reversible_ptr_container.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. ++++++++++++++++++++++++++++++++++
  2. |Boost| Pointer Container Library
  3. ++++++++++++++++++++++++++++++++++
  4. .. |Boost| image:: boost.png
  5. Class ``reversible_ptr_container``
  6. ------------------------------------
  7. This class is not a real class that can be found in the library.
  8. Its purpose is to present the general interface of all the pointer containers.
  9. **Hierarchy:**
  10. - ``reversible_ptr_container``
  11. - `ptr_sequence_adapter <ptr_sequence_adapter.html>`_
  12. - `ptr_vector <ptr_vector.html>`_
  13. - `ptr_list <ptr_list.html>`_
  14. - `ptr_deque <ptr_deque.html>`_
  15. - `ptr_array <ptr_array.html>`_
  16. - `associative_ptr_container <associative_ptr_container.html>`_
  17. - `ptr_set_adapter <ptr_set_adapter.html>`_
  18. - `ptr_multiset_adapter <ptr_multiset_adapter.html>`_
  19. - `ptr_map_adapter <ptr_map_adapter.html>`_
  20. - `ptr_multi_map_adapter <ptr_multimap_adapter.html>`_
  21. - `ptr_set <ptr_set.html>`_
  22. - `ptr_multi_set <ptr_multiset.html>`_
  23. - `ptr_map <ptr_map.html>`_
  24. - `ptr_multimap <ptr_multimap.html>`_
  25. **Navigate:**
  26. - `home <ptr_container.html>`_
  27. - `reference <reference.html>`_
  28. **synopsis:**
  29. .. parsed-literal::
  30. namespace boost
  31. {
  32. template
  33. <
  34. class T,
  35. class CloneAllocator,
  36. class VoidPtrContainer
  37. >
  38. class reversible_ptr_container
  39. {
  40. public: // `typedefs`_
  41. typedef T* value_type;
  42. typedef T& reference;
  43. typedef const T& const_reference;
  44. typedef *implementation defined* iterator;
  45. typedef *implementation defined* const_iterator;
  46. typedef typename VoidPtrContainer::differnce_type difference_type;
  47. typedef typename VoidPtrContainer::size_type size_type;
  48. typedef typename VoidPtrContainer::allocator_type allocator_type;
  49. typedef *implementation defined* reverse_iterator;
  50. typedef *implementation defined* const_reverse_iterator;
  51. typedef *implementation defined* auto_type;
  52. public: // `construct/copy/destroy`_
  53. reversible_ptr_container();
  54. explicit reversible_ptr_container( const reversible_ptr_container& r );
  55. template< class Derived >
  56. explicit reversible_ptr_container( const reversible_ptr_container<Derived>& r );
  57. explicit reversible_ptr_container( compatible-smart-ptr<reversible_ptr_container> r );
  58. template< class InputIterator >
  59. reversible_ptr_container( InputIterator first, InputIterator last );
  60. ~reversible_ptr_container();
  61. reversible_ptr_container& operator=( const reversible_ptr_container& r );
  62. template<class Derived>
  63. reversible_ptr_container& operator=( const reversible_ptr_container<Derived>& r );
  64. reversible_ptr_container& operator=( compatible-smart-ptr<reversible_ptr_container> r );
  65. allocator_type get_allocator() const;
  66. public: // `iterators`_
  67. iterator begin();
  68. const_iterator begin() const;
  69. iterator end();
  70. const_iterator end() const;
  71. reverse_iterator rbegin();
  72. const_reverse_iterator rbegin() const;
  73. reverse_iterator rend();
  74. const_reverse_iterator rend() const;
  75. public: // `capacity`_
  76. size_type size() const;
  77. size_type max_size() const;
  78. bool empty() const;
  79. public: // `modifiers`_
  80. void swap( reversible_ptr_container& r );
  81. void clear():
  82. VoidPtrContainer& base();
  83. const VoidPtrContainer& base() const;
  84. public: // `pointer container requirements`_
  85. auto_type replace( iterator position, T* x );
  86. template< class U >
  87. auto_type replace( iterator position, compatible-smart-ptr<U> x );
  88. compatible-smart-ptr<reversible_ptr_container> clone() const;
  89. compatible-smart-ptr<reversible_ptr_container> release();
  90. auto_type release( iterator position );
  91. }; // class 'reversible_ptr_container'
  92. // `comparison`_
  93. template < class T, class CA, class VPC >
  94. bool operator==( const reversible_ptr_container<T,CA,VPC>& x,
  95. const reversible_ptr_container<T,CA,VPC>& y);
  96. template < class T, class CA, class VPC >
  97. bool operator<( const reversible_ptr_container<T,CA,VPC>& x,
  98. const reversible_ptr_container<T,CA,VPC>& y);
  99. template < class T, class CA, class VPC >
  100. bool operator!=( const reversible_ptr_container<T,CA,VPC>& x,
  101. const reversible_ptr_container<T,CA,VPC>& y);
  102. template < class T, class CA, class VPC >
  103. bool operator>( const reversible_ptr_container<T,CA,VPC>& x,
  104. const reversible_ptr_container<T,CA,VPC>& y);
  105. template < class T, class CA, class VPC >
  106. bool operator>=( const reversible_ptr_container<T,CA,VPC>& x,
  107. const reversible_ptr_container<T,CA,VPC>& y);
  108. template < class T, class CA, class VPC >
  109. bool operator<=( const reversible_ptr_container<T,CA,VPC>& x,
  110. const reversible_ptr_container<T,CA,VPC>& y);
  111. template< class T, class CA, class VPC >
  112. void swap( reversible_ptr_container<T,CA,VPC>& x,
  113. reversible_ptr_container<T,CA,VPC>& y );
  114. // cloneability_
  115. template< class T, class CA, class VPC >
  116. reversible_ptr_container<T,CA,VPC>*
  117. new_clone( const reversible_ptr_container<T,CA,VPC>& r );
  118. // `null predicate`_
  119. template< class Iterator >
  120. bool is_null( Iterator i );
  121. // `serialization`_
  122. template<class Archive, class T, class CA, class VPC>
  123. void serialize( Archive& ar, reversible_ptr_container<T,CÁ,VPC>& c, const unsigned int version );
  124. } // namespace 'boost'
  125. Semantics
  126. ---------
  127. .. _`typedefs`:
  128. Semantics: typedefs
  129. ^^^^^^^^^^^^^^^^^^^
  130. Notice how these two types differ:
  131. - ``typedef T* value_type;``
  132. - notice this has pointer type
  133. - ``typedef T& reference;``
  134. - notice this is not a pointer type
  135. This is done to be able to add pointers directly
  136. to the container, but to hide the pointers externally.
  137. ..
  138. - ``typedef *implementation defined* object_type;``
  139. - this is ``T`` for sequences and sets
  140. - this is ``std::pair<const Key, void*>`` for maps
  141. Also notice that
  142. - ``typedef ... iterator``
  143. allows one to iterate over ``T&`` objects, not ``T*``.
  144. Note that::
  145. iterator i = ...;
  146. i.base();
  147. returns an iterator that allows one to iterate over ``void*``
  148. elements (*this is very rarely needed and you should not use the
  149. functionality unless you know what you are doing*).
  150. - ``typedef ... auto_type``
  151. This declaration hides a pointer pointer type. You can rely on the following
  152. operations
  153. .. parsed-literal::
  154. T* operator->() const;
  155. T& operator*() const;
  156. T* release();
  157. ~auto_type();
  158. operator *implementation-defined bool*\ ();
  159. The destructor will delete the stored object *using the clone allocator of the container*
  160. (this explains why we cannot use ``std::auto_ptr<T>`` nor ``std::unique_ptr<T>``). It might help to
  161. think it is just a ``compatible-smart-ptr<T>``. You can also return
  162. the pointer from a function or assign it to another pointer via the ``move()``
  163. function
  164. .. parsed-literal::
  165. auto_type ptr = ...;
  166. auto_type other = boost::ptr_container::move( ptr );
  167. return boost::ptr_container::move( other );
  168. .. _construct/copy/destroy:
  169. Semantics: construct/copy/destroy
  170. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  171. - ``reversible_ptr_container();``
  172. - Effects: Constructs an empty container
  173. - Postconditions: ``size() == 0``
  174. ..
  175. - ``reversible_ptr_container( size_type n, const T& x );``
  176. - Effects: Constructs a container with ``n`` clones of ``x``
  177. - Postconditions: ``size() == n``
  178. - ``explicit reversible_ptr_container( const reversible_ptr_container& r );``
  179. - Effects: Constructs a container by cloning all elements of ``r``
  180. - ``template< class Derived > explicit reversible_ptr_container( const reversible_ptr_container<Derived>& r );``
  181. - Effects: Constructs a container by cloning all elements of ``r``
  182. - Requirements: ``Derived`` is derived from ``T``
  183. - ``explicit reversible_ptr_container( compatible-smart-ptr< reversible_ptr_container > r );``
  184. - Effects: Constructs a container by taking ownership of the supplied pointers
  185. - ``template< class InputIterator >``
  186. ``reversible_ptr_container( InputIterator first, InputIterator last );``
  187. - Requirements: ``(first,last]`` is a valid range
  188. - Effects: Constructs a container with a cloned range of ``(first,last]``
  189. - Postconditions: ``size() == std::distance( first, last )``
  190. - ``~reversible_ptr_container();``
  191. - Effects: Deletes the stored objects via the clone allocator
  192. - Throws: Nothing
  193. - ``reversible_ptr_container& operator=( const reversible_ptr_container& r );``
  194. - Effects: Assigns a clone of ``r``
  195. - Exception safety: strong guarantee
  196. - ``template<class Derived> reversible_ptr_container& operator=( const reversible_ptr_container<Derived>& r );``
  197. - Effects: Assigns a clone of ``r``
  198. - Requirements: ``Derived`` is derived from ``T``
  199. - Exception safety: Strong guarantee
  200. - ``reversible_ptr_container& operator=( compatible-smart-ptr<reversible_ptr_container> r );``
  201. - Effects: Deletes the stored objects and then takes ownership of the supplied pointers
  202. - Throws: Nothing
  203. - ``allocator_type get_allocator() const;``
  204. - Effects: Returns a copy of the allocator of the container object
  205. .. _iterators:
  206. Semantics: iterators
  207. ^^^^^^^^^^^^^^^^^^^^
  208. **See also:** `iterator invalidation <conventions.html#iterators-are-invalidated-as-in-the-corresponding-standard-container>`_
  209. - ``iterator begin();``
  210. - ``const_iterator begin() const;``
  211. - Effects: Returns a mutable/non-mutable iterator with ``value_type T``
  212. - Throws: Nothing
  213. - ``iterator end();``
  214. - ``const_iterator end() const;``
  215. - Effects: Returns a mutable/non-mutable iterator with ``value_type T``
  216. - Throws: Nothing
  217. - ``reverse_iterator rbegin();``
  218. - ``const_reverse_iterator rbegin() const;``
  219. - Effects: Returns a mutable/non-mutable reverse iterator with ``value_type T``
  220. - Throws: Nothing
  221. - ``reverse_iterator rend();``
  222. - ``const_reverse_iterator rend() const;``
  223. - Effects: Returns a mutable/non-mutable reverse iterator with ``value_type T``
  224. - Throws: Nothing
  225. .. _capacity:
  226. Semantics: capacity
  227. ^^^^^^^^^^^^^^^^^^^
  228. - ``size_type size() const;``
  229. - Effects: Returns the number of stored elements
  230. - Throws: Nothing
  231. - ``size_type max_size() const;``
  232. - Effects: Returns the maximum number of stored elements
  233. - Throws: Nothing
  234. - ``bool empty() const;``
  235. - Effects: Returns whether the container is empty or not
  236. - Throws: Nothing
  237. .. _modifiers:
  238. Semantics: modifiers
  239. ^^^^^^^^^^^^^^^^^^^^
  240. - ``void swap( reversible_ptr_container& r );``
  241. - Effects: Swaps the content of the two containers
  242. - Throws: Nothing
  243. - ``void clear();``
  244. - Effects: Destroys all object of the container
  245. - Postconditions: ``empty() == true``
  246. - Throws: Nothing
  247. - ``VoidPtrContainer& base();``
  248. - ``const VoidPtrContainer& base() const;``
  249. - Returns: a reference to the wrapped container
  250. .. _`pointer container requirements`:
  251. Semantics: pointer container requirements
  252. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  253. - ``auto_type replace( iterator position, T* x );``
  254. - Requirements: ``not empty() and x != 0``
  255. - Effects: returns the object pointed to by ``position`` and replaces it with ``x``.
  256. - Throws: ``bad_ptr_container_operation`` if the container is empty and ``bad_pointer`` if ``x == 0``.
  257. - Exception safety: Strong guarantee
  258. - ``template< class U > auto_type replace( iterator position, compatible-smart-ptr<U> x );``
  259. - Effects: ``return replace( position, x.release() );``
  260. - ``compatible-smart-ptr< reversible_ptr_container > clone() const;``
  261. - Effects: Returns a deep copy of the container
  262. - Throws: ``std::bad_alloc`` if there is not enough memory to make a clone of the container
  263. - Complexity: Linear
  264. - ``compatible-smart-ptr< reversible_ptr_container > release();``
  265. - Effects: Releases ownership of the container. This is a useful way of returning a container from a function.
  266. - Postconditions: ``empty() == true``
  267. - Throws: ``std::bad_alloc`` if the return value cannot be allocated
  268. - Exception safety: Strong guarantee
  269. - ``auto_type release( iterator position );``
  270. - Requirements: ``not empty();``
  271. - Effects: Releases ownership of the pointer referred to by position
  272. - Postconditions: ``size()`` is one less
  273. - Throws: ``bad_ptr_container_operation`` if the container is empty
  274. - Exception safety: Strong guarantee
  275. .. _comparison:
  276. Semantics: comparison
  277. ^^^^^^^^^^^^^^^^^^^^^
  278. These functions compare the underlying range of objects.
  279. So ::
  280. operation( const ptr_container& l, const ptr_container& r );
  281. has the effect one would expect of normal standard containers. Hence
  282. objects are compared and not the pointers to objects.
  283. .. _`cloneability`:
  284. Semantics: cloneability
  285. ^^^^^^^^^^^^^^^^^^^^^^^
  286. - ``template< class T, class CloneAllocator >
  287. reversible_ptr_container<T,CA,VPC>*
  288. new_clone( const reversible_ptr_container<T,CA,VPC>& r );``
  289. - Effects: ``return r.clone().release();``
  290. - Remarks: This function is only defined for concrete `pointer containers`_, but not for
  291. `pointer container adapters`_.
  292. .. _`pointer containers`: ptr_container.html#smart-containers
  293. .. _`pointer container adapters`: ptr_container.html#smart-container-adapters
  294. .. _`null predicate`:
  295. Semantics: null predicate
  296. ^^^^^^^^^^^^^^^^^^^^^^^^^
  297. - ``template< class Iterator > bool is_null( Iterator i );``
  298. - Requirements: ``i`` is a valid dereferencable iterator
  299. - Returns: ``*i.base() == 0;``
  300. .. _`serialization`:
  301. Semantics: serialization
  302. ^^^^^^^^^^^^^^^^^^^^^^^^
  303. All containers can be serialized by means of
  304. `Boost.Serialization`__. For an overview, see
  305. `Serialization of Pointer Containers`_.
  306. .. __: ../../serialization/index.html
  307. .. _`Serialization of Pointer Containers`: reference.html#serialization
  308. ::
  309. template<class Archive, class T, class CA, class VPC>
  310. void serialize( Archive& ar, reversible_ptr_container<T,CA,VPC>& c, const unsigned int version );
  311. - Effects: Saves or loads the container to/from the archive.
  312. - Remarks: This function is called automatically be stream operators in
  313. Boost.Serialization
  314. - Exception safety: Loading gives the basic guarantee
  315. .. raw:: html
  316. <hr>
  317. :Copyright: Thorsten Ottosen 2004-2007. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
  318. __ http://www.boost.org/LICENSE_1_0.txt