|
Boost : |
Subject: Re: [boost] [rfc] rcpp
From: Ivan Sorokin (sorokin_at_[hidden])
Date: 2010-02-28 14:15:18
Daniel Trebbien wrote:
>> I have a small library that is intended for convenient and declarative
>> resource wrappers creation.
>>
>> Read Documentation:
>> http://rain.ifmo.ru/~sorokin/rcpp/doc/index.html
>>
>> Main Page:
>> http://rain.ifmo.ru/~sorokin/rcpp/
>>
> For example, it would be nice if the resource config had an
> `is_invalid` member.
I thought about that. And I decided to make library without it because
1 Even if user provides is_invalid() it still needs to provide
invalid_value() function. invalid_value() is required by
default-constructor, move-constructor/move-assignment-operator and
release() function. This is the main cause.
2 It is not really necessary. Let we have some underlying_resource_type
for example std::pair<HWND, HDC> (common_dc)
We can divide its values into three groups:
1 Valid values (first != NULL && second != NULL)
2 Invalid values ((first == NULL) ^ (second == NULL))
3 "True" invalid value (first == NULL && second == NULL)
When user wants to wrap underlying_resource_type into rcpp::resource, it
can check whether underlying_resource is invalid and it is, wraps "True"
invalid value.
Note that rcpp::resource is not intended to keep every possibly value of
underlying_resource_type. It can keep only two kind of values: values
that can be disposed or invalid_value. (we can wrap (char *)666 into
auto_ptr, but it is not correct, so it is with rcpp::resource)
> This would be useful in creating a resource
> manager for Windows `HANDLE`s that result from calls to
> `DuplicateHandle`. I need to keep track of the `DuplicateHandle`
> return value so that I would know whether the `HANDLE` member of the
> resource manager is set to something that needs to be closed with
> `CloseHandle`.
What kind of HANDLE that can be returned from DuplicateHandle should not
be disposed by CloseHandle?
> Essentially the underlying resource type in this case
> is a pair of a `HANDLE` and `BOOL`, where the "invalid value" is a
> pair with the `BOOL` set to `FALSE` and an indeterminate value of the
> `HANDLE`. In order to use the `rcpp::resource` template, I would need
> to override the `==` operator so that equality of the resource means
> equality of the `BOOL` member only, which is not ideal. I think that
> an `is_invalid` member would do the trick rather nicely, however.
Why do not use boost::optional<HANDLE> as underlying resource type?
> Also, I think that it would be nice to have a `shared_resource`
> template. I have an application in mind where I would like to create a
> shared `HANDLE` that is only closed if it is invalid and all
> references to it have been destroyed (a shared reference count reaches
> 0).
I thought about that. I don't think it has wide application. Moreover it
can be emulated with boost::shared_ptr<rcpp::resource>. Is it worth while?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk