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? 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... Thanks in advance, ~Matt Verona Houston, Texas USA

"Matt Verona" <mattverona@houston.rr.com> wrote in message
news:00f301c3f0bf$73098790$6601a8c0@sugarlansduzuv... 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?
There's an aspiring view implementation by Roland Richter in the sandbox which you might check out. He has also written a couple of nice papers on the subject. I would Definately like to see a view lib in boost! Although using the boost iterator-adaptors you can achieve some of the effects right now. Regards // Fredrik Blomqvist

Matt Verona wrote:
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.
Matt, is there any reason why you want to provide only insert(const key&) and erase(const key&)? Why not insert(InputIterator, InputIterator) or clear() or any other method? When I designed the view library (which you can find in Boost.Sandbox), I decided to make views read-only for two reasons: + Performance: as long as a view is read-only, it usually suffices that it owns the underlying container by reference, i.e. no copy is needed. Write access means that each view must contain its own copy of the container. Could be solved with a copy-on-write behaviour. + Simplicity of interface: read-only views have a minimal interface: they just define those functions *all* STL containers provide, such as begin()/end(), empty()/size(), plus various typedef's. But what about read-and-write views? Some have an insert() methods, others don't insert(), but push_back(), and so on. A general-purpose view (i.e. one suitable for all STL containers, not tailored to a specific one) either has to provide all these methods (uh oh, somebody just wanted to push_back() into a view<std::map>), or they have to know (how?) which they should provide, and which not. If you want to modify the view - why don't you modify the underlying container? The easiest solution might be that views provide a method to access the (copy of the) underlying container.
I was also wondering if Boost was planning to eventually provide a VTL-like framework?
I ported boost::view to use the new iterator_adaptors a few months ago, but got troubles because then the iterator adaptor lib was not stable. Ok, we have 1.31.0 since a few days, so I will look back. Sorry, can't promise more at the moment. - Roland
participants (3)
-
Fredrik Blomqvist
-
Matt Verona
-
Roland Richter