/* This is our implementation of complete container adaptor, which takes * a Sorted Associative Container (SAC) and produces a SAC such that * complete traversals can be done transparently, as described * in: * * E. Gamess, D. R. Musser, A. J. Sanchez-Ruiz. "Complete Traversals * and their Implementation Using the Standard Template Library". Available * from http://anubis.ciens.ucv.ve/~asanchez/autoolab.html. * * The container provides: * * o Types size_type and value_type taken from the corresponding SAC. * o A constructor that takes a SAC as a parameter and stores a reference * to its argument. It also creates an iteration_list which is an STL * list used to implement complete traversals. * o Types iterator and const_iterator, which implement complete traversal * iterators on on-constant or constant SACs. * o Member function size, which returns the size of the SAC component * of a complete_container. * o Member function insert, which takes a value_type value and inserts * it into the underlying SAC. * o Member function base, which returns the SAC component of a * complete_container. * * * By: Eric Gamess (*, %), * David Musser(+), * and Arturo J. Sanchez-Ruiz (*) * * (*)Automatic Tools Construction Lab (AuTooLab) * Software Engineering and Systems Center (ISYS) * Faculty of Science -- Central University of Venezuela (UCV) * http://anubis.ciens.ucv.ve/~asanchez/autoolab.html * * (%)Computer Science Department * Universidad del Valle * Cali, Colombia * * (+)Computer Science Department * Rensselaer Polytechnic Institute * http://www.cs.rpi.edu/~musser * * (May, 1999) */ #ifndef COMPLETE_CONTAINER_H #define COMPLETE_CONTAINER_H #include using namespace std; template class complete_container { public: typedef typename SortedAssociativeContainer::size_type size_type; typedef typename SortedAssociativeContainer::value_type value_type; //iterators are simply list-based iterators typedef list::iterator iterator; typedef list::const_iterator const_iterator; protected: //representation list iteration_list; //iteration list SortedAssociativeContainer& container; //reference to container public: complete_container(SortedAssociativeContainer& c) : container(c) { //constructor copy(c.begin(), c.end(), back_inserter(iteration_list)); } //to manipulate the associated container: SortedAssociativeContainer& base() { return container; } //iterator-related member functions: iterator begin() { return iteration_list.begin(); } const_iterator begin() const { return iteration_list.begin(); } iterator end() { return iteration_list.end(); } const_iterator end() const { return iteration_list.end(); } size_type size() const { return container.size(); } //size void insert(const value_type& v) { //direct insertion typename SortedAssociativeContainer::size_type n = container.size(); container.insert(v); if (container.size() != n) //this allows uniform handling of both //unique and multiple containers iteration_list.push_back(v); } }; #endif