RE: [boost] VTL question (sorry if this is slightly off-topic)

Hello, I was reviewing the View Template Library (VTL) - see http://www.zib.de/weiser/vtl/ ... and have a few questions regarding Views as applied to STL Maps. I was also wondering if Boost was planning to eventually provide a VTL-like framework? ---------------------------------- Gary > Yes, I'm planning on using the new Iterator Adaptors and converting the VTL library to use boost. --------------------------- I'm looking for a type of View that provides read-only access to an STL map, with only const iterators, but also provides limited insertion and removal access as well (as shown below): This new limited View-like map will only allow clients to iterate using const iterators, and also provides only one public insert(const key&) and one erase(const key&) method. These insert and erase member functions need to be implemented as "Template Method Functions", as follows: (see Design Patterns) * Note: these are shown using the latest SGI STL implementation (i.e., the _M_t.insert_unique and _M_t.erase calls) virtual bool preInsert(const value_type&) { return true; } pair<iterator, bool> insert(const value_type& x) { if(preInsert(x) { return _M_t.insert_unique(x); } return make_pair(end(), false); // make compiler happy } virtual bool preErase(const key_type&) { return true; } size_type erase(const key_type& x) { if(preErase(x) { return _M_t.erase(x); } return 0; // make compiler happy } The preInsert and preErase methods are virtual Hook Methods, and derived classes override these to add behavior to the (non-virtual) insert and erase functions.. Another nice addition to this map view would be a const _Tp& operator[](const key_type& k) const function, implemented something like this: const _Tp& operator[](const key_type& k) const { const_iterator i = lower_bound(k); if(i == end() || key_comp(k, (*i).first)) // if i->first is >= k throw SearchError(k); return (*i).second; } * Note: this simple implementation assumes that the key can be converted to a string in the constructor of the SearchError exception object. I have at least three Manager-like (Mediator) classes that can use this pattern (i.e., derived from this Map View class) as well as others that need a vector view with a similar filtered design... ---------------------------------------------- Gary > If you are asking me to write this code, well I'm not likely to get around to it. However I'd be glad to review it as an addition to the library. We generally stayed with the STL model of no virtual functions. In the meantime you might like to look at the Iterator Adaptor library and generate your own special view container. -Gary-

Hello, I was reviewing the View Template Library (VTL) - see http://www.zib.de/weiser/vtl/ ... and have a few questions regarding Views as applied to STL Maps.
I was also wondering if Boost was planning to eventually provide a VTL-like framework? ---------------------------------- Gary > Yes, I'm planning on using the new Iterator Adaptors and converting
If I am not wrong, VTL is using Boost. I can see more than one file from Boost libraries.Some of these files are: config.hpp smart_ptr.hpp type_traits.hpp utility.hpp Then how you will convert VTL to use Boost if it is already is based on Boost? Sorry for not understanding. Mohammed ----- Original Message ----- From: "Powell, Gary" <powellg@amazon.com> To: "Boost mailing list" <boost@lists.boost.org> Sent: Wednesday, February 11, 2004 7:34 PM Subject: RE: [boost] VTL question (sorry if this is slightly off-topic) the VTL library to use boost.
--------------------------- I'm looking for a type of View that provides read-only access to an STL
access as well (as shown below):
This new limited View-like map will only allow clients to iterate using const iterators, and also provides only one public insert(const key&) and one erase(const key&) method.
These insert and erase member functions need to be implemented as "Template Method Functions", as follows: (see Design Patterns)
* Note: these are shown using the latest SGI STL implementation (i.e., the _M_t.insert_unique and _M_t.erase calls)
virtual bool preInsert(const value_type&) { return true; }
pair<iterator, bool> insert(const value_type& x) { if(preInsert(x) { return _M_t.insert_unique(x); } return make_pair(end(), false); // make compiler happy }
virtual bool preErase(const key_type&) { return true; }
size_type erase(const key_type& x) { if(preErase(x) { return _M_t.erase(x); } return 0; // make compiler happy }
The preInsert and preErase methods are virtual Hook Methods, and derived classes override these to add behavior to the (non-virtual) insert and erase functions..
Another nice addition to this map view would be a const _Tp& operator[](const key_type& k) const function, implemented something like
map, with only const iterators, but also provides limited insertion and removal this:
const _Tp& operator[](const key_type& k) const { const_iterator i = lower_bound(k); if(i == end() || key_comp(k, (*i).first)) // if i->first is >= k throw SearchError(k); return (*i).second; }
* Note: this simple implementation assumes that the key can be converted
to a string in the constructor of the SearchError exception object.
I have at least three Manager-like (Mediator) classes that can use this
a vector view with a similar filtered design... ----------------------------------------------
Gary > If you are asking me to write this code, well I'm not likely to get around to it. However I'd be glad to review it as an addition to the
pattern (i.e., derived from this Map View class) as well as others that need library. We generally stayed with the STL model of no virtual functions. In the meantime you might like to look at the Iterator Adaptor library and generate your own special view container.
-Gary- _______________________________________________ Unsubscribe & other changes:
participants (2)
-
Mohammed
-
Powell, Gary