00001 // ======================================================================== // 00002 // // 00003 // File : boost_util.h // 00004 // Purpose : Code from boost library (see http://www.boost.org/) // 00005 // Time-stamp: <Wed Nov/13/2002 08:30 MET Coder@ReallySoft.de> // 00006 // // 00007 // (C) May 2002 by Ralf Westram // 00008 // // 00009 // Permission to use, copy, modify, distribute and sell this software // 00010 // and its documentation for any purpose is hereby granted without fee, // 00011 // provided that the above copyright notice appear in all copies and // 00012 // that both that copyright notice and this permission notice appear // 00013 // in supporting documentation. // 00014 // // 00015 // Ralf Westram makes no representations about the suitability of this // 00016 // software for any purpose. It is provided "as is" without express or // 00017 // implied warranty. // 00018 // // 00019 // ======================================================================== // 00020 00021 #ifndef BOOST_UTIL_H 00022 #define BOOST_UTIL_H 00023 00024 #ifndef CSTDLIB 00025 #include <cstdlib> 00026 #endif 00027 00028 00029 namespace rs { 00030 00035 namespace rs_boost { 00036 00052 template <class T> 00053 T next(T x) { return ++x; } 00054 00056 template <class T> 00057 T prior(T x) { return --x; } 00058 00059 00068 class noncopyable 00069 { 00070 protected: 00071 noncopyable(){} 00072 ~noncopyable(){} 00073 private: // emphasize the following members are private 00074 noncopyable( const noncopyable& ); 00075 const noncopyable& operator=( const noncopyable& ); 00076 }; 00077 00083 template <class X> 00084 class counted { 00085 static size_t instances; 00086 static size_t max_instances; 00087 public: 00088 counted() { 00089 ++instances; 00090 if (instances>max_instances) max_instances = instances; 00091 } 00092 ~counted() { --instances; } 00093 00094 size_t get_instances() const { return instances; } 00095 size_t get_max_instances() const { return max_instances; } 00096 }; 00097 00098 template <class X> size_t counted<X>::instances = 0; 00099 template <class X> size_t counted<X>::max_instances = 0; 00100 00101 void second_instance_error(); 00102 00111 template <class X> 00112 class singleton : counted<X> { 00113 public: 00115 singleton() : counted<X>() { 00116 if (get_instances()>1) second_instance_error(); 00117 } 00118 ~singleton() {} 00119 }; 00120 }; 00121 00122 }; // end of namespace rs 00123 00124 #else 00125 #error boost_util.h included twice 00126 #endif // BOOST_UTIL_H 00127
Contact me in case of errors or questions. This documentation is powered by . |
(C) 2000-2002 |