00001 // -*- mode: c++; indent-tabs-mode: nil; -*- 00002 // 00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the 00004 //modeling, analysis, and design of biological macromolecules. 00005 //Copyright (C) 2006, Tim Robertson <kid50@users.sourceforge.net> 00006 // 00007 //This program is free software; you can redistribute it and/or modify 00008 //it under the terms of the GNU Lesser General Public License as published 00009 //by the Free Software Foundation; either version 2.1 of the License, or (at 00010 //your option) any later version. 00011 // 00012 //This program is distributed in the hope that it will be useful, but 00013 //WITHOUT ANY WARRANTY; without even the implied warranty of 00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 //Lesser General Public License for more details. 00016 // 00017 //You should have received a copy of the GNU Lesser General Public License 00018 //along with this program; if not, write to the Free Software Foundation, 00019 //Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00020 00023 00024 #ifndef BTK_UTILITY_TYPE_ID_HPP 00025 #define BTK_UTILITY_TYPE_ID_HPP 00026 00027 #include <ostream> 00028 00029 namespace BTK { 00030 namespace UTILITY { 00031 00039 template <typename T, typename V = int> 00040 class TypeID 00041 { 00042 public: 00043 typedef TypeID<T,V> self_type; 00044 00045 TypeID(self_type const & src) : _value(src._value) {} 00046 00049 ~TypeID() {} 00050 00052 operator V() const { return _value; } 00053 00054 bool operator==(self_type const & rhs) const 00055 { 00056 return _value == rhs._value; 00057 } 00058 00059 bool operator!=(self_type const & rhs) const 00060 { 00061 return _value != rhs._value; 00062 } 00063 00064 bool operator<(self_type const & rhs) const 00065 { 00066 return _value < rhs._value; 00067 } 00068 00069 bool operator<=(self_type const & rhs) const 00070 { 00071 return _value <= rhs._value; 00072 } 00073 00074 bool operator>(self_type const & rhs) const 00075 { 00076 return _value > rhs._value; 00077 } 00078 00079 bool operator>=(self_type const & rhs) const 00080 { 00081 return _value >= rhs._value; 00082 } 00083 00084 self_type & operator=(self_type const & rhs) 00085 { 00086 _value = rhs._value; 00087 return *this; 00088 } 00089 00090 friend std::ostream & operator<<(std::ostream & os, 00091 self_type const & t) 00092 { 00093 os << t._value; 00094 return os; 00095 } 00096 00097 protected: 00098 TypeID(V value) : _value(value) {} 00099 00100 void increment() { ++_value; } 00101 void decrement() { --_value; } 00102 00103 private: 00104 V _value; 00105 }; 00106 00107 } // namespace UTILITY 00108 } // namespace BTK 00109 00110 #endif