ptr_map_adapter.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ++++++++++++++++++++++++++++++++++
  2. |Boost| Pointer Container Library
  3. ++++++++++++++++++++++++++++++++++
  4. .. |Boost| image:: boost.png
  5. Class ``ptr_map_adapter``
  6. -------------------------
  7. This class is used to build custom pointer containers with
  8. an underlying map-like container. The interface of the class is an extension
  9. of the interface from ``associative_ptr_container``.
  10. **Hierarchy:**
  11. - `reversible_ptr_container <reversible_ptr_container.html>`_
  12. - `associative_ptr_container <associative_ptr_container.html>`_
  13. - `ptr_set_adapter <ptr_set_adapter.html>`_
  14. - `ptr_multiset_adapter <ptr_multiset_adapter.html>`_
  15. - ``ptr_map_adapter``
  16. - `ptr_multi_map_adapter <ptr_multimap_adapter.html>`_
  17. - `ptr_set <ptr_set.html>`_
  18. - `ptr_multi_set <ptr_multiset.html>`_
  19. - `ptr_map <ptr_map.html>`_
  20. - `ptr_multimap <ptr_multimap.html>`_
  21. **Navigate:**
  22. - `home <ptr_container.html>`_
  23. - `reference <reference.html>`_
  24. **Synopsis:**
  25. .. parsed-literal::
  26. namespace boost
  27. {
  28. template
  29. <
  30. class T,
  31. class VoidPtrMap,
  32. class CloneAllocator = heap_clone_allocator
  33. >
  34. class ptr_map_adapter
  35. {
  36. public: // `typedefs`_
  37. typedef VoidPtrMap::key_type key_type;
  38. typedef T* mapped_type;
  39. typedef T& mapped_reference;
  40. typedef const T& const_mapped_reference;
  41. typedef ... value_type;
  42. typedef ... reference;
  43. typedef ... const_reference;
  44. typedef ... pointer;
  45. typedef ... const_pointer;
  46. public: // `modifiers`_
  47. std::pair<iterator,bool> insert( key_type& k, T* x );
  48. template< class U >
  49. std::pair<iterator,bool> insert( const key_type& k, compatible-smart-ptr<U> x );
  50. public; // `lookup`_
  51. T& operator[]( const key_type& key );
  52. T& at( const key_type& key );
  53. const T& at( const key_type& key ) const;
  54. public: // `pointer container requirements`_
  55. bool transfer( iterator object, ptr_map_adapter& from );
  56. size_type transfer( iterator first, iterator last, ptr_map_adapter& from );
  57. template< class Range >
  58. size_type transfer( const Range& r, ptr_map_adapter& from );
  59. size_type transfer( ptr_map_adapter& from );
  60. }; // class 'ptr_map_adapter'
  61. } // namespace 'boost'
  62. Semantics
  63. ---------
  64. .. _`typedefs`:
  65. Semantics: typedefs
  66. ^^^^^^^^^^^^^^^^^^^
  67. The following types are implementation defined::
  68. typedef ... value_type;
  69. typedef ... reference;
  70. typedef ... const_reference;
  71. typedef ... pointer;
  72. typedef ... const_pointer;
  73. However, the structure of the type mimics ``std::pair`` s.t. one
  74. can use ``first`` and ``second`` members. The reference-types
  75. are not real references and the pointer-types are not real pointers.
  76. However, one may still write ::
  77. map_type::value_type a_value = *m.begin();
  78. a_value.second->foo();
  79. map_type::reference a_reference = *m.begin();
  80. a_reference.second->foo();
  81. map_type::const_reference a_creference = *const_begin(m);
  82. map_type::pointer a_pointer = &*m.begin();
  83. a_pointer->second->foo();
  84. map_type::const_pointer a_cpointer = &*const_begin(m);
  85. The difference compared to ``std::map<Key,T*>`` is that constness
  86. is propagated to the pointer (that is, to ``second``) in ``const_itertor``.
  87. .. _`modifiers`:
  88. Semantics: modifiers
  89. ^^^^^^^^^^^^^^^^^^^^
  90. - ``std::pair<iterator,bool> insert( key_type& k, value_type x );``
  91. - Requirements: ``x != 0``
  92. - Effects: Takes ownership of ``x`` and insert it iff there is no equivalent of it already. The bool part of the return value indicates insertion and the iterator points to the element with key ``x``.
  93. - Throws: bad_pointer if ``x == 0``
  94. - Exception safety: Strong guarantee
  95. - ``template< class U > std::pair<iterator,bool> insert( const key_type& k, compatible-smart-ptr<U> x );``
  96. - Equivalent to (but without the ``const_cast``): ``return insert( const_cast<key_type&>(k), x.release() );``
  97. ..
  98. - ``std::pair<iterator,bool> insert( key_type& k, const_reference x );``
  99. - Effects: ``return insert( allocate_clone( x ) );``
  100. - Exception safety: Strong guarantee
  101. .. _`lookup`:
  102. Semantics: lookup
  103. ^^^^^^^^^^^^^^^^^
  104. - ``T& operator[]( const key_type& key );``
  105. - Effects: returns the object with key ``key`` if it exists; otherwise a new object is allocated and inserted and its reference returned.
  106. - Exception-safety: Strong guarantee
  107. - ``T& at( const key_type& key );``
  108. - ``const T& at( const key_type& jey ) const;``
  109. - Requirement: the key exists
  110. - Throws: ``bad_ptr_container_operation`` if the key does not exist
  111. .. _`pointer container requirements`:
  112. Semantics: pointer container requirements
  113. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  114. - ``bool transfer( iterator object, ptr_map_adapter& from );``
  115. - Requirements: ``not from.empty()``
  116. - Effects: Inserts the object defined by ``object`` into the container and remove it from ``from``
  117. iff no equivalent object exists.
  118. - Returns: whether the object was transfered
  119. - Exception safety: Strong guarantee
  120. - ``size_type transfer( iterator first, iterator last, ptr__set_adapter& from );``
  121. - Requirements: ``not from.empty()``
  122. - Effects: Inserts the objects defined by the range ``[first,last)`` into the container and remove it from ``from``.
  123. An object is only transferred if no equivalent object exists.
  124. - Returns: the number of transfered objects
  125. - Exception safety: Basic guarantee
  126. - ``template< class Range > void transfer( const Range& r, ptr_map_adapter& from );``
  127. - Effects: ``return transfer( boost::begin(r), boost::end(r), from );``
  128. - ``size_type transfer( ptr_set_adapter& from );``
  129. - Effects: ``return transfer( from.begin(), from.end(), from );``.
  130. .. raw:: html
  131. <hr>
  132. :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
  133. __ http://www.boost.org/LICENSE_1_0.txt