00001 #ifndef OPENTISSUE_UTILITY_UTILITY_IDENTIFIER_H 00002 #define OPENTISSUE_UTILITY_UTILITY_IDENTIFIER_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <string> 00013 00014 namespace OpenTissue 00015 { 00016 namespace utility 00017 { 00018 00030 class Identifier 00031 { 00032 protected: 00033 00034 std::string m_ID; 00035 size_t m_index; 00036 00037 public: 00038 00039 Identifier() 00040 { 00041 generate_new_index(); 00042 m_ID = "ID" + m_index; 00043 } 00044 00045 virtual ~Identifier(){} 00046 00047 public: 00048 00049 Identifier(Identifier const & id) 00050 { 00051 m_ID = id.m_ID; 00052 m_index = id.m_index; 00053 } 00054 00055 Identifier & operator=(Identifier const & id) 00056 { 00057 m_ID = id.m_ID; 00058 m_index = id.m_index; 00059 return *this; 00060 } 00061 00062 bool operator==(Identifier const & id) const { return (m_index == id.m_index); } 00063 00064 bool operator!=(Identifier const & id) const { return !(*this == id); } 00065 00066 public: 00067 00068 void set_id(std::string const & id) { m_ID = id; } 00069 00070 std::string const & get_id() const { return m_ID; } 00071 00072 size_t get_index() const {return m_index; } 00073 00074 protected: 00075 00086 void generate_new_index() 00087 { 00088 static size_t next_index = 0; 00089 m_index = next_index; 00090 ++next_index; 00091 } 00092 00093 }; 00094 00095 } // namespace utility 00096 00097 } // namespace OpenTissue 00098 00099 // OPENTISSUE_UTILITY_UTILITY_IDENTIFIER_H 00100 #endif