Home Libraries Author Links

dbmap.hpp

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the SysToMath DB C++ Libraries package (LibStmDb).
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Tom Michaelis, SysToMath.
00018  * Portions created by the Initial Developer are Copyright (C) 2003-2008
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /******************************************************************************
00038  *                       First Release 2003-03-15
00039  ******************************************************************************/
00040 
00041 
00103 #ifndef STM_DBMAP_HPP
00104 #define STM_DBMAP_HPP
00105 
00106 
00252 // Include header files and macros for implementation.
00253 #include <stm/impl/dbxmap.hpp>
00254 
00255 
00257 namespace stm
00258 {
00259 
00260 
00278 namespace db
00279 {
00280 
00281 
00286 
00287 
00288 typedef dword size_type;
00289 
00290 
00293 typedef int32 difference_type;
00294 
00295 
00298 typedef char char_type;
00299 
00300 
00303 const size_type locking = 1;
00304 
00305 
00309 template <class FlagsT, FlagsT Flags>
00310 struct policy
00311 {
00312     typedef FlagsT flags_type;
00313     typedef boost::mpl::bool_<(Flags & flags_type (locking)) == flags_type (locking)> lock;
00314 };
00315 
00316 
00320 template <size_type Flags>
00321 struct default_policy : public policy<size_type, Flags>
00322 {};
00323 
00324 
00328 template <class SizeT, class DiffT, class CharT, class Allocator>
00329 struct traits
00330 {
00331     typedef SizeT size_type;
00332     typedef DiffT difference_type;
00333     typedef CharT char_type;
00334     typedef Allocator allocator_type;
00335     typedef std::basic_string
00336     <
00337         char_type,
00338         std::char_traits<char_type>,
00339         typename allocator_type::template rebind<char_type>::other
00340     >
00341     string_type;
00342 };
00343 
00344 
00348 template <class Allocator>
00349 struct default_traits :
00350     public traits<size_type, difference_type, char_type, Allocator>
00351 {};
00352 
00353 
00356 struct null_type
00357 {
00358     null_type ();
00359 };
00360 
00361 
00365 template <typename T> struct is_variant;
00366 
00367 
00371 template <typename T> struct is_optional;
00372 
00373 
00378 template <typename T> struct optional :
00379     public boost::variant<db::null_type, T>
00380 {
00382     bool exists () const;
00383 };
00384 
00385 
00389 template <typename T> struct is_bytelike;
00390 
00391 
00395 template <typename T, class Enable = void> struct may_endiancvt;
00396 
00397 
00401 template <typename T, class Enable = void> struct is_conslist;
00402 
00403 
00408 template <class Sequence, class Enable = void> struct conslist;
00409 
00410 
00417 class buffer
00418 {
00419 public:
00423     virtual void append (const byte *src, size_type size) = 0;
00424 
00428     virtual const byte *extract (size_type size) = 0;
00429 
00434     virtual bool endiancvt () const = 0;
00435 
00438     template <typename T>
00439     buffer &operator<< (const T &value);
00440 
00443     template <typename T>
00444     buffer &operator>> (T &value);
00445 };
00446 
00447 
00462 template <typename T, class Enable = void>
00463 struct stream
00464 {
00466     static void put (buffer &buf, const T &value);
00467 
00469     static void get (buffer &buf, T &value);
00470 };
00471 
00472 
00475 template <typename T>
00476 struct stream<T, typename boost::enable_if<boost::is_empty<T> >::type>;
00477 
00478 
00481 template <typename T>
00482 struct stream<T, typename boost::enable_if<boost::is_pod<T> >::type>;
00483 
00484 
00487 template <typename T, class Allocator>
00488 struct stream<std::vector<T, Allocator> >;
00489  
00490 
00493 template <class charT, class traits, class Allocator>
00494 struct stream<std::basic_string<charT, traits, Allocator> >;
00495 
00496 
00499 template <class T>
00500 struct stream<T, typename boost::enable_if<is_variant<T> >::type>;
00501 
00502 
00505 template <class T>
00506 struct stream<T, typename boost::enable_if<is_optional<T> >::type>;
00507 
00508 
00511 template <class T>
00512 struct stream<T, typename boost::enable_if<is_conslist<T> >::type>;
00513 
00514 
00517 template <typename T1, typename T2>
00518 struct stream<std::pair<T1, T2> >;
00519  
00520 
00524 }}  // namespace stm::db
00525 
00526 
00527 // Include base class implementation.
00528 #include <stm/impl/dbxmap.hpp>
00529 
00530 
00531 namespace stm
00532 {
00533 
00534 
00535 namespace db
00536 {
00537 
00538 
00543 
00544 
00545 
00546 
00547 
00548 
00549 //\{
00571 template
00572 <
00573     class Key,
00574     class T,
00575     class Compare = std::less<Key>,
00576     class Allocator = std::allocator<std::pair<const Key, T> >,
00577     class Policy = default_policy<0>,
00578     class Traits = default_traits<Allocator>
00579 >
00580 class map :
00581     private local::pxmap<Key, T, Compare, Allocator, Policy, Traits, false>  // Implementation.
00582 {
00583     typedef local::pxmap<Key, T, Compare, Allocator, Policy, Traits, false> proxy;  // Implementation
00584 
00585 public:
00589 
00591     typedef map<Key, T, Compare, Allocator, Policy, Traits> db_type;
00592 
00594     typedef Key key_type;
00595 
00597     typedef T mapped_type;
00598 
00599     typedef std::pair<const Key, T> value_type;
00600     typedef Compare key_compare;
00601     typedef typename proxy::value_compare value_compare;
00602     typedef Allocator allocator_type;
00603     typedef Policy policy_type;
00604     typedef Traits traits_type;
00605 
00606     typedef typename Allocator::reference reference;
00607     typedef typename Allocator::const_reference const_reference;
00608 
00609     typedef typename Allocator::pointer pointer;
00610     typedef typename Allocator::const_pointer const_pointer;
00611 
00612     typedef typename proxy::iterator iterator;
00613     typedef typename proxy::const_iterator const_iterator;
00614 
00615     typedef typename proxy::reverse_iterator reverse_iterator;
00616     typedef typename proxy::const_reverse_iterator const_reverse_iterator;
00617 
00618     typedef typename traits_type::size_type size_type;
00619     typedef typename traits_type::difference_type difference_type;
00620     typedef typename traits_type::char_type char_type;
00621     typedef typename traits_type::string_type string_type;
00622 
00628     class locker;
00629 
00631     template
00632     <
00633         class SKey,
00634         class SCompare = std::less<SKey>
00635     > class index;
00636 
00638     typedef typename policy_type::flags_type flags_type;
00639 
00640 
00641     //\}////////////////////////////////////////////////////////////////////////
00644 
00646     static const flags_type noflags = proxy::noflags;
00647 
00649     static const flags_type truncate = proxy::truncate;
00650 
00652     static const flags_type forceendiancvt = proxy::forceendiancvt;
00653 
00655     static const flags_type multiprocessing = proxy::multiprocessing;
00656 
00657 
00658     //\}////////////////////////////////////////////////////////////////////////
00661 
00663     map ();
00664 
00666     explicit map
00667     (
00668         const string_type &name,
00669         flags_type flags = noflags,
00670         const key_compare &comp = key_compare (),
00671         const allocator_type &alloc = allocator_type ()
00672     );
00673 
00675     template <class InputIterator>
00676     map
00677     (
00678         InputIterator first,
00679         InputIterator last,
00680         const string_type &name = string_type (),
00681         flags_type flags = noflags,
00682         const key_compare &comp = key_compare (),
00683         const allocator_type &alloc = allocator_type ()
00684     );
00685 
00689     map
00690     (
00691         const map<Key, T, Compare, Allocator, Policy, Traits> &rhs,
00692         const string_type &name = string_type ()
00693     );
00694 
00696     map<Key, T, Compare, Allocator, Policy, Traits> &operator=
00697     (
00698         const map<Key, T, Compare, Allocator, Policy, Traits> &rhs
00699     );
00700 
00704     void swap (map<Key, T, Compare, Allocator, Policy, Traits> &other) throw ();
00705 
00707     ~map ();
00708 
00709 
00710     //\}////////////////////////////////////////////////////////////////////////
00713 
00714     iterator begin ();
00715     const_iterator begin () const;
00716 
00717     iterator end ();
00718     const_iterator end () const;
00719 
00720     reverse_iterator rbegin ();
00721     const_reverse_iterator rbegin () const;
00722 
00723     reverse_iterator rend ();
00724     const_reverse_iterator rend () const;
00725 
00726 
00727     //\}////////////////////////////////////////////////////////////////////////
00730 
00731     bool empty () const;
00732     size_type size () const;
00733     size_type max_size () const;
00734 
00735 
00736     //\}////////////////////////////////////////////////////////////////////////
00739 
00740     mapped_type &operator[] (const key_type &key);
00741 
00742 
00743     //\}////////////////////////////////////////////////////////////////////////
00746 
00747     iterator insert (iterator hint, const value_type &value);
00748     std::pair<typename db_type::iterator, bool> insert (const value_type &value);
00749 
00750     template <typename InputIterator>
00751     void insert (InputIterator first, InputIterator last);
00752 
00753     void erase (iterator position);
00754     size_type erase (const key_type &key);
00755     void erase (iterator first, iterator last);
00756     void clear ();
00757 
00758 
00759     //\}////////////////////////////////////////////////////////////////////////
00762 
00763     key_compare key_comp () const;
00764     value_compare value_comp () const;
00765     allocator_type get_allocator () const;
00766 
00768     bool endiancvt () const;
00769 
00771     flags_type get_flags () const;
00772 
00774     const string_type &get_name () const;
00775 
00776 
00777     //\}////////////////////////////////////////////////////////////////////////
00780 
00781     iterator find (const key_type &key);
00782     const_iterator find (const key_type &key) const;
00783     reverse_iterator rfind (const key_type &key);
00784     const_reverse_iterator rfind (const key_type &key) const;
00785     size_type count (const key_type &key) const;
00786     iterator lower_bound (const key_type &key);
00787     const_iterator lower_bound (const key_type &key) const;
00788     iterator upper_bound (const key_type &key);
00789     const_iterator upper_bound (const key_type &key) const;
00790     std::pair<iterator, iterator> equal_range (const key_type &key);
00791     std::pair<const_iterator, const_iterator> equal_range (const key_type &key) const;
00792 };
00793 
00794 
00798 
00799 //\{
00800 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00801 bool operator== (const map<Key, T, Compare, Allocator, Policy, Traits> &x,
00802                  const map<Key, T, Compare, Allocator, Policy, Traits> &y);
00803 
00804 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00805 bool operator< (const map<Key, T, Compare, Allocator, Policy, Traits> &x,
00806                 const map<Key, T, Compare, Allocator, Policy, Traits> &y);
00807 
00808 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00809 bool operator!= (const map<Key, T, Compare, Allocator, Policy, Traits> &x,
00810                  const map<Key, T, Compare, Allocator, Policy, Traits> &y);
00811 
00812 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00813 bool operator> (const map<Key, T, Compare, Allocator, Policy, Traits> &x,
00814                 const map<Key, T, Compare, Allocator, Policy, Traits> &y);
00815 
00816 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00817 bool operator>= (const map<Key, T, Compare, Allocator, Policy, Traits> &x,
00818                  const map<Key, T, Compare, Allocator, Policy, Traits> &y);
00819 
00820 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00821 bool operator<= (const map<Key, T, Compare, Allocator, Policy, Traits> &x,
00822                  const map<Key, T, Compare, Allocator, Policy, Traits> &y);
00823 //\}
00824 
00825 
00829 //\{
00830 
00831 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00832 void swap (map<Key, T, Compare, Allocator, Policy, Traits> &x,
00833            map<Key, T, Compare, Allocator, Policy, Traits> &y);
00834 //\}
00835 //\}
00836 
00837 
00843 
00846 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00847 class map<Key, T, Compare, Allocator, Policy, Traits>::locker :
00848     private local::plocker<Key, T, Compare, Allocator, Policy, Traits, false, typename policy_type::lock>
00849 {
00850 public:
00851     // Type definitions.
00852     typedef map<Key, T, Compare, Allocator, Policy, Traits> db_type;
00853     typedef boost::function<void ()> cb_type;
00854 
00855     // Constructor.
00856     locker (const db_type &db, cb_type unlockfct = 0);
00857 
00858     // Constructor.
00859     template <class IndexT>
00860     locker (const IndexT &idx, cb_type unlockfct = 0);
00861 
00862     // Destructor.
00863     ~locker ();
00864 };
00865 
00866 
00869 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
00870 template <class SKey, class SCompare>
00871 class map<Key, T, Compare, Allocator, Policy, Traits>::index :
00872     private local::pindex<Key, T, Compare, Allocator, Policy, Traits, SKey, SCompare>  // Implementation.
00873 {
00874     typedef local::pindex<Key, T, Compare, Allocator, Policy, Traits, SKey, SCompare> proxy;  // Implementation.
00875 
00876 public:
00877     // Type definitions.
00878     typedef map<Key, T, Compare, Allocator, Policy, Traits> db_type;
00879     typedef typename db_type::key_type key_type;
00880     typedef typename db_type::mapped_type mapped_type;
00881     typedef typename db_type::value_type value_type;
00882     typedef typename db_type::policy_type policy_type;
00883     typedef typename db_type::traits_type traits_type;
00884     typedef typename db_type::size_type size_type;
00885     typedef typename db_type::difference_type difference_type;
00886     typedef typename db_type::char_type char_type;
00887     typedef typename db_type::string_type string_type;
00888     typedef SKey skey_type;
00889     typedef SCompare skey_compare;
00890     typedef typename proxy::skeyfct_type skeyfct_type;
00891 
00892     typedef typename proxy::iterator iterator;
00893     typedef typename proxy::const_iterator const_iterator;
00894 
00895     typedef typename proxy::reverse_iterator reverse_iterator;
00896     typedef typename proxy::const_reverse_iterator const_reverse_iterator;
00897 
00898     typedef typename db_type::flags_type flags_type;
00899 
00900     // Flag value definitions (bitwise orable).
00901     static const flags_type noflags = proxy::noflags;
00902     static const flags_type reindex = proxy::reindex;
00903 
00904     // Construction and destruction.
00905     index ();
00906 
00907     explicit index
00908     (
00909         const db_type &db,
00910         const string_type &name
00911     );
00912 
00913     explicit index
00914     (
00915         const db_type &db,
00916         skeyfct_type skeyfct,
00917         const string_type &name = string_type (),
00918         flags_type flags = noflags,
00919         const skey_compare &comp = skey_compare ()
00920     );
00921 
00922     index
00923     (
00924         const index<SKey, SCompare> &rhs,
00925         const string_type &name = string_type ()
00926     );
00927 
00928     index<SKey, SCompare> &operator=
00929     (
00930         const index<SKey, SCompare> &rhs
00931     );
00932 
00933     void swap (index<SKey, SCompare> &other) throw ();
00934 
00935     ~index ();
00936 
00937     // Iterators.
00938     iterator begin ();
00939     const_iterator begin () const;
00940 
00941     iterator end ();
00942     const_iterator end () const;
00943 
00944     reverse_iterator rbegin ();
00945     const_reverse_iterator rbegin () const;
00946 
00947     reverse_iterator rend ();
00948     const_reverse_iterator rend () const;
00949 
00950     // Capacity.
00951     bool empty () const;
00952     size_type size () const;
00953     size_type max_size () const;
00954 
00955     // Modifiers.
00956     void erase (iterator position);
00957     size_type erase (const skey_type &skey);
00958     void erase (iterator first, iterator last);
00959     void clear ();
00960 
00961     // Observers.
00962     const db_type &dbmap () const;
00963     skey_compare skey_comp () const;
00964     skeyfct_type get_skeyfct () const;
00965     bool endiancvt () const;
00966     flags_type get_flags () const;
00967     const string_type &get_name () const;
00968 
00969     // db::map::index key operations.
00970     iterator find (const skey_type &skey);
00971     const_iterator find (const skey_type &skey) const;
00972     reverse_iterator rfind (const skey_type &skey);
00973     const_reverse_iterator rfind (const skey_type &skey) const;
00974     size_type count (const skey_type &skey) const;
00975     iterator lower_bound (const skey_type &skey);
00976     const_iterator lower_bound (const skey_type &skey) const;
00977     iterator upper_bound (const skey_type &skey);
00978     const_iterator upper_bound (const skey_type &skey) const;
00979     std::pair<iterator, iterator> equal_range (const skey_type &skey);
00980     std::pair<const_iterator, const_iterator> equal_range (const skey_type &skey) const;
00981 };
00982 
00983     
00984 // db::map::index comparison operators.
00985 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
00986           class SKey, class SCompare>
00987 bool operator== (const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
00988                  const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
00989 
00990 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
00991           class SKey, class SCompare>
00992 bool operator< (const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
00993                 const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
00994 
00995 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
00996           class SKey, class SCompare>
00997 bool operator!= (const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
00998                  const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
00999 
01000 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
01001           class SKey, class SCompare>
01002 bool operator> (const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
01003                 const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
01004 
01005 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
01006           class SKey, class SCompare>
01007 bool operator>= (const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
01008                  const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
01009 
01010 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
01011           class SKey, class SCompare>
01012 bool operator<= (const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
01013                  const typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
01014 
01015 
01016 // db::map::index specialized algorithms.
01017 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits,
01018           class SKey, class SCompare>
01019 void swap (typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &x,
01020            typename map<Key, T, Compare, Allocator, Policy, Traits>::template index<SKey, SCompare> &y);
01021 
01022 
01028 
01029 //\{
01047 template
01048 <
01049     class Key,
01050     class Compare = std::less<Key>,
01051     class Allocator = std::allocator<Key>,
01052     class Policy = default_policy<0>,
01053     class Traits = default_traits<Allocator>
01054 >
01055 class set :
01056     private local::pxmap<Key, null_type, Compare, Allocator, Policy, Traits, false>  // Implementation.
01057 {
01058     typedef local::pxmap<Key, null_type, Compare, Allocator, Policy, Traits, false> proxy;  // Implementation
01059 
01060 public:
01064 
01066     typedef set<Key, Compare, Allocator, Policy, Traits> db_type;
01067 
01069     typedef Key key_type;
01070 
01072     typedef key_type value_type;
01073     typedef Compare key_compare;
01074     typedef Compare value_compare;
01075     typedef Allocator allocator_type;
01076     typedef Policy policy_type;
01077     typedef Traits traits_type;
01078 
01079     typedef typename Allocator::reference reference;
01080     typedef typename Allocator::const_reference const_reference;
01081 
01082     typedef typename Allocator::pointer pointer;
01083     typedef typename Allocator::const_pointer const_pointer;
01084 
01085     typedef typename proxy::iterator iterator;
01086     typedef typename proxy::const_iterator const_iterator;
01087 
01088     typedef typename proxy::reverse_iterator reverse_iterator;
01089     typedef typename proxy::const_reverse_iterator const_reverse_iterator;
01090 
01091     typedef typename traits_type::size_type size_type;
01092     typedef typename traits_type::difference_type difference_type;
01093     typedef typename traits_type::char_type char_type;
01094     typedef typename traits_type::string_type string_type;
01095 
01101     class locker;
01102 
01104     typedef typename policy_type::flags_type flags_type;
01105 
01106 
01107     //\}////////////////////////////////////////////////////////////////////////
01110 
01112     static const flags_type noflags = proxy::noflags;
01113 
01115     static const flags_type truncate = proxy::truncate;
01116 
01118     static const flags_type forceendiancvt = proxy::forceendiancvt;
01119 
01121     static const flags_type multiprocessing = proxy::multiprocessing;
01122 
01123 
01124     //\}////////////////////////////////////////////////////////////////////////
01127 
01129     set ();
01130 
01132     explicit set
01133     (
01134         const string_type &name,
01135         flags_type flags = noflags,
01136         const key_compare &comp = key_compare (),
01137         const allocator_type &alloc = allocator_type ()
01138     );
01139 
01141     template <class InputIterator>
01142     set
01143     (
01144         InputIterator first,
01145         InputIterator last,
01146         const string_type &name = string_type (),
01147         flags_type flags = noflags,
01148         const key_compare &comp = key_compare (),
01149         const allocator_type &alloc = allocator_type ()
01150     );
01151 
01155     set
01156     (
01157         const set<Key, Compare, Allocator, Policy, Traits> &rhs,
01158         const string_type &name = string_type ()
01159     );
01160 
01162     set<Key, Compare, Allocator, Policy, Traits> &operator=
01163     (
01164         const set<Key, Compare, Allocator, Policy, Traits> &rhs
01165     );
01166 
01170     void swap (set<Key, Compare, Allocator, Policy, Traits> &other) throw ();
01171 
01173     ~set ();
01174 
01175 
01176     //\}////////////////////////////////////////////////////////////////////////
01179 
01180     iterator begin ();
01181     const_iterator begin () const;
01182 
01183     iterator end ();
01184     const_iterator end () const;
01185 
01186     reverse_iterator rbegin ();
01187     const_reverse_iterator rbegin () const;
01188 
01189     reverse_iterator rend ();
01190     const_reverse_iterator rend () const;
01191 
01192 
01193     //\}////////////////////////////////////////////////////////////////////////
01196 
01197     bool empty () const;
01198     size_type size () const;
01199     size_type max_size () const;
01200 
01201 
01202     //\}////////////////////////////////////////////////////////////////////////
01205 
01206     iterator insert (iterator hint, const value_type &value);
01207     std::pair<typename db_type::iterator, bool> insert (const value_type &value);
01208 
01209     template <typename InputIterator>
01210     void insert (InputIterator first, InputIterator last);
01211 
01212     void erase (iterator position);
01213     size_type erase (const key_type &key);
01214     void erase (iterator first, iterator last);
01215     void clear ();
01216 
01217 
01218     //\}////////////////////////////////////////////////////////////////////////
01221 
01222     key_compare key_comp () const;
01223     value_compare value_comp () const;
01224     allocator_type get_allocator () const;
01225 
01227     bool endiancvt () const;
01228 
01230     flags_type get_flags () const;
01231 
01233     const string_type &get_name () const;
01234 
01235 
01236     //\}////////////////////////////////////////////////////////////////////////
01239 
01240     iterator find (const key_type &key);
01241     const_iterator find (const key_type &key) const;
01242     reverse_iterator rfind (const key_type &key);
01243     const_reverse_iterator rfind (const key_type &key) const;
01244     size_type count (const key_type &key) const;
01245     iterator lower_bound (const key_type &key);
01246     const_iterator lower_bound (const key_type &key) const;
01247     iterator upper_bound (const key_type &key);
01248     const_iterator upper_bound (const key_type &key) const;
01249     std::pair<iterator, iterator> equal_range (const key_type &key);
01250     std::pair<const_iterator, const_iterator> equal_range (const key_type &key) const;
01251 };
01252 
01253 
01257 
01258 //\{
01259 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01260 bool operator== (const set<Key, Compare, Allocator, Policy, Traits> &x,
01261                  const set<Key, Compare, Allocator, Policy, Traits> &y);
01262 
01263 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01264 bool operator< (const set<Key, Compare, Allocator, Policy, Traits> &x,
01265                 const set<Key, Compare, Allocator, Policy, Traits> &y);
01266 
01267 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01268 bool operator!= (const set<Key, Compare, Allocator, Policy, Traits> &x,
01269                  const set<Key, Compare, Allocator, Policy, Traits> &y);
01270 
01271 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01272 bool operator> (const set<Key, Compare, Allocator, Policy, Traits> &x,
01273                 const set<Key, Compare, Allocator, Policy, Traits> &y);
01274 
01275 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01276 bool operator>= (const set<Key, Compare, Allocator, Policy, Traits> &x,
01277                  const set<Key, Compare, Allocator, Policy, Traits> &y);
01278 
01279 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01280 bool operator<= (const set<Key, Compare, Allocator, Policy, Traits> &x,
01281                  const set<Key, Compare, Allocator, Policy, Traits> &y);
01282 //\}
01283 
01284 
01288 //\{
01289 
01290 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01291 void swap (set<Key, Compare, Allocator, Policy, Traits> &x,
01292            set<Key, Compare, Allocator, Policy, Traits> &y);
01293 //\}
01294 //\}
01295 
01296 
01302 
01305 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01306 class set<Key, Compare, Allocator, Policy, Traits>::locker :
01307     private local::plocker<Key, null_type, Compare, Allocator, Policy, Traits, false, typename policy_type::lock>
01308 {
01309 public:
01310     // Type definitions.
01311     typedef set<Key, Compare, Allocator, Policy, Traits> db_type;
01312     typedef boost::function<void ()> cb_type;
01313 
01314     // Constructor.
01315     locker (const db_type &db, cb_type unlockfct = 0);
01316 
01317     // Constructor.
01318     template <class IndexT>
01319     locker (const IndexT &idx, cb_type unlockfct = 0);
01320 
01321     // Destructor.
01322     ~locker ();
01323 };
01324 
01325 
01328 template
01329 <
01330     class Key,
01331     class T,
01332     class Compare = std::less<Key>,
01333     class Allocator = std::allocator<std::pair<const Key, T> >,
01334     class Policy = default_policy<0>,
01335     class Traits = default_traits<Allocator>
01336 >
01337 class multimap :
01338     private local::pxmap<Key, T, Compare, Allocator, Policy, Traits, true>  // Implementation.
01339 {
01340     typedef local::pxmap<Key, T, Compare, Allocator, Policy, Traits, true> proxy;  // Implementation
01341 
01342 public:
01343     // Type definitions.
01344     typedef multimap<Key, T, Compare, Allocator, Policy, Traits> db_type;
01345     typedef Key key_type;
01346     typedef T mapped_type;
01347     typedef std::pair<const Key, T> value_type;
01348     typedef Compare key_compare;
01349     typedef typename proxy::value_compare value_compare;
01350     typedef Allocator allocator_type;
01351     typedef Policy policy_type;
01352     typedef Traits traits_type;
01353 
01354     typedef typename Allocator::reference reference;
01355     typedef typename Allocator::const_reference const_reference;
01356 
01357     typedef typename Allocator::pointer pointer;
01358     typedef typename Allocator::const_pointer const_pointer;
01359 
01360     typedef typename proxy::iterator iterator;
01361     typedef typename proxy::const_iterator const_iterator;
01362 
01363     typedef typename proxy::reverse_iterator reverse_iterator;
01364     typedef typename proxy::const_reverse_iterator const_reverse_iterator;
01365 
01366     typedef typename traits_type::size_type size_type;
01367     typedef typename traits_type::difference_type difference_type;
01368     typedef typename traits_type::char_type char_type;
01369     typedef typename traits_type::string_type string_type;
01370 
01375     class locker;
01376 
01377     typedef typename policy_type::flags_type flags_type;
01378 
01379     // Flag value definitions (bitwise orable).
01380     static const flags_type noflags = proxy::noflags;
01381     static const flags_type truncate = proxy::truncate;
01382     static const flags_type forceendiancvt = proxy::forceendiancvt;
01383     static const flags_type multiprocessing = proxy::multiprocessing;
01384 
01385     // Construction and destruction.
01386     multimap ();
01387 
01388     explicit multimap
01389     (
01390         const string_type &name = string_type (),
01391         flags_type flags = noflags,
01392         const key_compare &comp = key_compare (),
01393         const allocator_type &alloc = allocator_type ()
01394     );
01395 
01396     template <class InputIterator>
01397     multimap
01398     (
01399         InputIterator first,
01400         InputIterator last,
01401         const string_type &name = string_type (),
01402         flags_type flags = noflags,
01403         const key_compare &comp = key_compare (),
01404         const allocator_type &alloc = allocator_type ()
01405     );
01406 
01407     multimap
01408     (
01409         const multimap<Key, T, Compare, Allocator, Policy, Traits> &rhs,
01410         const string_type &name = string_type ()
01411     );
01412 
01413     multimap<Key, T, Compare, Allocator, Policy, Traits> &operator=
01414     (
01415         const multimap<Key, T, Compare, Allocator, Policy, Traits> &rhs
01416     );
01417 
01418     void swap (multimap<Key, T, Compare, Allocator, Policy, Traits> &other) throw ();
01419 
01420     ~multimap ();
01421 
01422     // Iterators.
01423     iterator begin ();
01424     const_iterator begin () const;
01425 
01426     iterator end ();
01427     const_iterator end () const;
01428 
01429     reverse_iterator rbegin ();
01430     const_reverse_iterator rbegin () const;
01431 
01432     reverse_iterator rend ();
01433     const_reverse_iterator rend () const;
01434 
01435     // Capacity.
01436     bool empty () const;
01437     size_type size () const;
01438     size_type max_size () const;
01439 
01440     // Modifiers.
01441     iterator insert (iterator hint, const value_type &value);
01442     iterator insert (const value_type &value);
01443 
01444     template <typename InputIterator>
01445     void insert (InputIterator first, InputIterator last);
01446 
01447     void erase (iterator position);
01448     size_type erase (const key_type &key);
01449     void erase (iterator first, iterator last);
01450     void clear ();
01451 
01452     // Observers.
01453     key_compare key_comp () const;
01454     value_compare value_comp () const;
01455     allocator_type get_allocator () const;
01456     bool endiancvt () const;
01457     flags_type get_flags () const;
01458     const string_type &get_name () const;
01459 
01460     // db::multimap key operations.
01461     iterator find (const key_type &key);
01462     const_iterator find (const key_type &key) const;
01463     reverse_iterator rfind (const key_type &key);
01464     const_reverse_iterator rfind (const key_type &key) const;
01465     size_type count (const key_type &key) const;
01466     iterator lower_bound (const key_type &key);
01467     const_iterator lower_bound (const key_type &key) const;
01468     iterator upper_bound (const key_type &key);
01469     const_iterator upper_bound (const key_type &key) const;
01470     std::pair<iterator, iterator> equal_range (const key_type &key);
01471     std::pair<const_iterator, const_iterator> equal_range (const key_type &key) const;
01472 };
01473 
01474 
01475 // db::multimap comparison operators.
01476 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01477 bool operator== (const multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01478                  const multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01479 
01480 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01481 bool operator< (const multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01482                 const multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01483 
01484 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01485 bool operator!= (const multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01486                  const multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01487 
01488 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01489 bool operator> (const multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01490                 const multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01491 
01492 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01493 bool operator>= (const multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01494                  const multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01495 
01496 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01497 bool operator<= (const multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01498                  const multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01499 
01500 
01501 // db::multimap specialized algorithms.
01502 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01503 void swap (multimap<Key, T, Compare, Allocator, Policy, Traits> &x,
01504            multimap<Key, T, Compare, Allocator, Policy, Traits> &y);
01505 
01506 
01509 template <class Key, class T, class Compare, class Allocator, class Policy, class Traits>
01510 class multimap<Key, T, Compare, Allocator, Policy, Traits>::locker :
01511     private local::plocker<Key, T, Compare, Allocator, Policy, Traits, true, typename policy_type::lock>
01512 {
01513 public:
01514     // Type definitions.
01515     typedef multimap<Key, T, Compare, Allocator, Policy, Traits> db_type;
01516     typedef boost::function<void ()> cb_type;
01517 
01518     // Constructor.
01519     locker (const db_type &db, cb_type unlockfct = 0);
01520 
01521     // Destructor.
01522     ~locker ();
01523 };
01524 
01525 
01528 template
01529 <
01530     class Key,
01531     class Compare = std::less<Key>,
01532     class Allocator = std::allocator<Key>,
01533     class Policy = default_policy<0>,
01534     class Traits = default_traits<Allocator>
01535 >
01536 class multiset :
01537     private local::pxmap<Key, null_type, Compare, Allocator, Policy, Traits, true>  // Implementation.
01538 {
01539     typedef local::pxmap<Key, null_type, Compare, Allocator, Policy, Traits, true> proxy;  // Implementation
01540 
01541 public:
01542     // Type definitions.
01543     typedef multiset<Key, Compare, Allocator, Policy, Traits> db_type;
01544     typedef Key key_type;
01545     typedef key_type value_type;
01546     typedef Compare key_compare;
01547     typedef Compare value_compare;
01548     typedef Allocator allocator_type;
01549     typedef Policy policy_type;
01550     typedef Traits traits_type;
01551 
01552     typedef typename Allocator::reference reference;
01553     typedef typename Allocator::const_reference const_reference;
01554 
01555     typedef typename Allocator::pointer pointer;
01556     typedef typename Allocator::const_pointer const_pointer;
01557 
01558     typedef typename proxy::iterator iterator;
01559     typedef typename proxy::const_iterator const_iterator;
01560 
01561     typedef typename proxy::reverse_iterator reverse_iterator;
01562     typedef typename proxy::const_reverse_iterator const_reverse_iterator;
01563 
01564     typedef typename traits_type::size_type size_type;
01565     typedef typename traits_type::difference_type difference_type;
01566     typedef typename traits_type::char_type char_type;
01567     typedef typename traits_type::string_type string_type;
01568 
01573     class locker;
01574 
01575     typedef typename policy_type::flags_type flags_type;
01576 
01577     // Flag value definitions (bitwise orable).
01578     static const flags_type noflags = proxy::noflags;
01579     static const flags_type truncate = proxy::truncate;
01580     static const flags_type forceendiancvt = proxy::forceendiancvt;
01581     static const flags_type multiprocessing = proxy::multiprocessing;
01582 
01583     // Construction and destruction.
01584     multiset ();
01585 
01586     explicit multiset
01587     (
01588         const string_type &name = string_type (),
01589         flags_type flags = noflags,
01590         const key_compare &comp = key_compare (),
01591         const allocator_type &alloc = allocator_type ()
01592     );
01593 
01594     template <class InputIterator>
01595     multiset
01596     (
01597         InputIterator first,
01598         InputIterator last,
01599         const string_type &name = string_type (),
01600         flags_type flags = noflags,
01601         const key_compare &comp = key_compare (),
01602         const allocator_type &alloc = allocator_type ()
01603     );
01604 
01605     multiset
01606     (
01607         const multiset<Key, Compare, Allocator, Policy, Traits> &rhs,
01608         const string_type &name = string_type ()
01609     );
01610 
01611     multiset<Key, Compare, Allocator, Policy, Traits> &operator=
01612     (
01613         const multiset<Key, Compare, Allocator, Policy, Traits> &rhs
01614     );
01615 
01616     void swap (multiset<Key, Compare, Allocator, Policy, Traits> &other) throw ();
01617 
01618     ~multiset ();
01619 
01620     // Iterators.
01621     iterator begin ();
01622     const_iterator begin () const;
01623 
01624     iterator end ();
01625     const_iterator end () const;
01626 
01627     reverse_iterator rbegin ();
01628     const_reverse_iterator rbegin () const;
01629 
01630     reverse_iterator rend ();
01631     const_reverse_iterator rend () const;
01632 
01633     // Capacity.
01634     bool empty () const;
01635     size_type size () const;
01636     size_type max_size () const;
01637 
01638     // Modifiers.
01639     iterator insert (iterator hint, const value_type &value);
01640     iterator insert (const value_type &value);
01641 
01642     template <typename InputIterator>
01643     void insert (InputIterator first, InputIterator last);
01644 
01645     void erase (iterator position);
01646     size_type erase (const key_type &key);
01647     void erase (iterator first, iterator last);
01648     void clear ();
01649 
01650     // Observers.
01651     key_compare key_comp () const;
01652     value_compare value_comp () const;
01653     allocator_type get_allocator () const;
01654     bool endiancvt () const;
01655     flags_type get_flags () const;
01656     const string_type &get_name () const;
01657 
01658     // db::multiset key operations.
01659     iterator find (const key_type &key);
01660     const_iterator find (const key_type &key) const;
01661     reverse_iterator rfind (const key_type &key);
01662     const_reverse_iterator rfind (const key_type &key) const;
01663     size_type count (const key_type &key) const;
01664     iterator lower_bound (const key_type &key);
01665     const_iterator lower_bound (const key_type &key) const;
01666     iterator upper_bound (const key_type &key);
01667     const_iterator upper_bound (const key_type &key) const;
01668     std::pair<iterator, iterator> equal_range (const key_type &key);
01669     std::pair<const_iterator, const_iterator> equal_range (const key_type &key) const;
01670 };
01671 
01672 
01673 // db::multiset comparison operators.
01674 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01675 bool operator== (const multiset<Key, Compare, Allocator, Policy, Traits> &x,
01676                  const multiset<Key, Compare, Allocator, Policy, Traits> &y);
01677 
01678 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01679 bool operator< (const multiset<Key, Compare, Allocator, Policy, Traits> &x,
01680                 const multiset<Key, Compare, Allocator, Policy, Traits> &y);
01681 
01682 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01683 bool operator!= (const multiset<Key, Compare, Allocator, Policy, Traits> &x,
01684                  const multiset<Key, Compare, Allocator, Policy, Traits> &y);
01685 
01686 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01687 bool operator> (const multiset<Key, Compare, Allocator, Policy, Traits> &x,
01688                 const multiset<Key, Compare, Allocator, Policy, Traits> &y);
01689 
01690 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01691 bool operator>= (const multiset<Key, Compare, Allocator, Policy, Traits> &x,
01692                  const multiset<Key, Compare, Allocator, Policy, Traits> &y);
01693 
01694 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01695 bool operator<= (const multiset<Key, Compare, Allocator, Policy, Traits> &x,
01696                  const multiset<Key, Compare, Allocator, Policy, Traits> &y);
01697 
01698 
01699 // db::multiset specialized algorithms.
01700 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01701 void swap (multiset<Key, Compare, Allocator, Policy, Traits> &x,
01702            multiset<Key, Compare, Allocator, Policy, Traits> &y);
01703 
01704 
01707 template <class Key, class Compare, class Allocator, class Policy, class Traits>
01708 class multiset<Key, Compare, Allocator, Policy, Traits>::locker :
01709     private local::plocker<Key, null_type, Compare, Allocator, Policy, Traits, true, typename policy_type::lock>
01710 {
01711 public:
01712     // Type definitions.
01713     typedef multiset<Key, Compare, Allocator, Policy, Traits> db_type;
01714     typedef boost::function<void ()> cb_type;
01715 
01716     // Constructor.
01717     locker (const db_type &db, cb_type unlockfct = 0);
01718 
01719     // Destructor.
01720     ~locker ();
01721 };
01722 
01723 
01727 }  // namespace db
01728 
01729 
01730 }  // namespace stm
01731 
01732 
01733 // Include inline implementation.
01734 #include <stm/impl/dbxmap.hpp>
01735 
01736 
01737 #endif  // STM_DBMAP_HPP

© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).