![]() |
Home | Libraries | Author | Links |
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 C++ Libraries package (LibStmCpp). 00015 * 00016 * The Initial Developer of the Original Code is 00017 * Tom Michaelis, SysToMath. 00018 * Portions created by the Initial Developer are Copyright (C) 2005-2006 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 2005-10-19 00039 ******************************************************************************/ 00040 00041 00103 #ifndef STM_SMARTPTRAIDS_HPP 00104 #define STM_SMARTPTRAIDS_HPP 00105 00106 00107 // Include header files for implementation. 00108 #include <stm/impl/smartptrxaids.hpp> 00109 00110 00111 // Include injective_ptr base class template implementation. 00112 #include <stm/impl/smartptrxaids.hpp> 00113 00114 00115 namespace stm 00116 { 00117 00118 00122 namespace smartptr 00123 { 00124 00125 00130 00131 00132 00133 00134 const stm::dword Surjective = 0x00000001; 00135 const stm::dword Multirange = 0x00000002; 00136 00137 00138 00142 template <stm::dword Flags = 0> 00143 struct policy 00144 { 00147 typedef boost::mpl::bool_<(Flags & Surjective) == Surjective> surjective; 00148 00151 typedef boost::mpl::bool_<(Flags & Multirange) == Multirange> multirange; 00152 }; 00153 00154 00158 template <class Policy> 00159 struct MakeSurjective 00160 { 00162 typedef boost::mpl::true_ surjective; 00163 00166 typedef typename Policy::multirange multirange; 00167 }; 00168 00169 00173 template <class Policy> 00174 struct MakeMultirange 00175 { 00178 typedef typename Policy::surjective surjective; 00179 00181 typedef boost::mpl::true_ multirange; 00182 }; 00183 00184 00247 template 00248 < 00249 class T, 00250 class Compare = std::less<T>, 00251 class Allocator = std::allocator<T>, 00252 class Policy = stm::smartptr::policy<> 00253 > 00254 class injective_ptr : 00255 private local::mapped_ptr 00256 < 00257 T, 00258 Compare, 00259 Allocator, 00260 Policy::surjective::value, 00261 Policy::multirange::value 00262 > 00263 { 00265 typedef local::mapped_ptr 00266 < 00267 T, 00268 Compare, 00269 Allocator, 00270 Policy::surjective::value, 00271 Policy::multirange::value 00272 > 00273 mapped_ptr_impl; 00274 00276 typedef typename mapped_ptr_impl::repository repository; 00277 00279 friend class boost::serialization::access; 00280 00281 public: 00283 typedef T element_type; 00284 00287 typedef typename mapped_ptr_impl::rangeid_type rangeid_type; 00288 00290 typedef Compare compare_type; 00291 00293 typedef Allocator allocator_type; 00294 00296 typedef Policy policy_type; 00297 00300 typedef long refcount_type; 00301 00308 typedef typename repository::range_type range_type; 00309 00312 injective_ptr (); 00313 00318 injective_ptr (rangeid_type rangeid); 00319 00323 injective_ptr (const typename range_type::iterator &it); 00324 00330 injective_ptr (const element_type &value, bool store = true); 00331 00340 injective_ptr (const element_type &value, 00341 rangeid_type rangeid, bool store = true); 00342 00344 injective_ptr (const injective_ptr &other); 00345 00347 injective_ptr &operator= (const injective_ptr &other); 00348 00352 injective_ptr &assign (const element_type &value); 00353 00357 void reset (); 00358 00362 void reset (const element_type &value); 00363 00366 void swap (injective_ptr &other); 00367 00370 operator bool () const; 00371 00374 const element_type &operator* () const; 00375 00378 const element_type *operator-> () const; 00379 00383 const element_type *get () const; 00384 00387 static bool is_surjective (); 00388 00391 static bool is_multirange (); 00392 00397 bool unique () const; 00398 00402 refcount_type use_count () const; 00403 00406 const range_type &range () const; 00407 00410 rangeid_type rangeid () const; 00411 00415 static rangeid_type define_range (); 00416 00423 static void undefine_range (rangeid_type rangeid); 00424 00427 static bool range_empty (rangeid_type rangeid); 00428 00430 static bool range_defined (rangeid_type rangeid); 00431 00433 static bool range_available (rangeid_type rangeid); 00434 }; 00435 00436 00441 template <class T, class Compare, class Allocator, class Policy> 00442 bool operator== 00443 ( 00444 const injective_ptr<T, Compare, Allocator, Policy> &ptr1, 00445 const injective_ptr<T, Compare, Allocator, Policy> &ptr2 00446 ); 00447 00448 00453 template <class T, class Compare, class Allocator, class Policy> 00454 bool operator!= 00455 ( 00456 const injective_ptr<T, Compare, Allocator, Policy> &ptr1, 00457 const injective_ptr<T, Compare, Allocator, Policy> &ptr2 00458 ); 00459 00460 00473 template <class T, class Compare, class Allocator, class Policy> 00474 bool operator< 00475 ( 00476 const injective_ptr<T, Compare, Allocator, Policy> &ptr1, 00477 const injective_ptr<T, Compare, Allocator, Policy> &ptr2 00478 ); 00479 00480 00483 template <class T, class Compare, class Allocator, class Policy> 00484 void swap 00485 ( 00486 injective_ptr<T, Compare, Allocator, Policy> &ptr1, 00487 injective_ptr<T, Compare, Allocator, Policy> &ptr2 00488 ); 00489 00490 00494 template <class T, class Compare, class Allocator, class Policy> 00495 const T *get_pointer 00496 ( 00497 const injective_ptr<T, Compare, Allocator, Policy> &ptr 00498 ); 00499 00500 00503 template 00504 < 00505 class OStreamT, 00506 class T, 00507 class Compare, 00508 class Allocator, 00509 class Policy 00510 > 00511 OStreamT &operator<< 00512 ( 00513 OStreamT &os, 00514 const injective_ptr<T, Compare, Allocator, Policy> &ptr 00515 ); 00516 00517 00559 template 00560 < 00561 class T, 00562 class Compare = std::less<T>, 00563 class Allocator = std::allocator<T>, 00564 class Policy = stm::smartptr::policy<stm::smartptr::Multirange> 00565 > 00566 class injective_set : 00567 private boost::noncopyable 00568 { 00569 public: 00571 typedef T value_type; 00572 00574 typedef Compare compare_type; 00575 00577 typedef Allocator allocator_type; 00578 00580 typedef MakeMultirange<Policy> policy_type; 00581 00583 typedef injective_ptr 00584 < 00585 T, 00586 Compare, 00587 Allocator, 00588 MakeMultirange<Policy> 00589 > injective_ptr_type; 00590 00594 typedef typename injective_ptr_type::range_type range_type; 00595 00603 class accessor : 00604 public injective_ptr_type 00605 { 00606 public: 00608 typedef injective_ptr_type base; 00609 00612 accessor (); 00613 00615 accessor (const accessor &other); 00616 00618 accessor (const base &ptr); 00619 00622 accessor (const typename range_type::iterator &it); 00623 00627 accessor &operator= (const accessor &other); 00628 }; 00629 00631 injective_set (); 00632 00636 ~injective_set (); 00637 00639 accessor nil () const; 00640 00646 accessor insert (const value_type &value); 00647 00653 accessor insert (const value_type &value, bool &inserted); 00654 00658 accessor find (const value_type &value) const; 00659 00662 const range_type &range () const; 00663 00666 typename range_type::iterator begin () const; 00667 00670 typename range_type::iterator end () const; 00671 00674 typename range_type::size_type size () const; 00675 00677 bool empty () const; 00678 00679 private: 00681 typename injective_ptr_type::rangeid_type rangeid_; 00682 }; 00683 00684 00689 template 00690 < 00691 class T, 00692 class Compare = std::less<T>, 00693 class Allocator = std::allocator<T>, 00694 class Policy = stm::smartptr::policy<> 00695 > 00696 class injective 00697 { 00698 public: 00700 typedef injective_ptr<T, Compare, Allocator, Policy> ptr; 00701 00703 typedef injective_set<T, Compare, Allocator, MakeMultirange<Policy> > set; 00704 00706 typedef typename Policy::surjective surjective; 00707 }; 00708 00709 00714 template 00715 < 00716 class T, 00717 class Compare = std::less<T>, 00718 class Allocator = std::allocator<T>, 00719 class Policy = stm::smartptr::policy<stm::smartptr::Surjective> 00720 > 00721 class bijective 00722 { 00723 public: 00726 typedef injective_ptr<T, Compare, Allocator, MakeSurjective<Policy> > ptr; 00727 00730 typedef injective_set<T, Compare, Allocator, MakeMultirange<MakeSurjective<Policy> > > set; 00731 00733 typedef boost::mpl::true_ surjective; 00734 }; 00735 00736 00740 } // namespace smartptr 00741 00742 00743 // Lift names to namespace stm. 00744 using smartptr::injective_ptr; 00745 using smartptr::injective_set; 00746 using smartptr::injective; 00747 using smartptr::bijective; 00748 00749 00750 } // namespace stm 00751 00752 00753 // Include inline and template implementation. 00754 #include <stm/impl/smartptrxaids.hpp> 00755 00756 00757 #endif // STM_SMARTPTRAIDS_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).