|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #ifndef STK_UTIL_UTIL_IDENTIFIER_H 00010 #define STK_UTIL_UTIL_IDENTIFIER_H 00011 00012 #include <string> 00013 #include <stk_util/util/ci_string.hpp> 00014 00015 #include <boost/unordered_set.hpp> // boost 1.36.0 unordered_set not in the tr1 00016 00017 namespace std { 00018 namespace tr1 { 00019 using ::boost::unordered_set; 00020 } 00021 } 00022 00023 namespace stk_classic { 00024 00025 class IdentifierA 00026 { 00027 public: 00028 static int compare(const char *s1, const size_t s1_length, const char *s2, const size_t s2_length); 00029 00030 IdentifierA() 00031 {} 00032 00033 IdentifierA(const IdentifierA &identifier) 00034 : m_string(identifier.m_string) 00035 {} 00036 00037 explicit IdentifierA(const std::string &string) 00038 : m_string(string) 00039 {} 00040 00041 explicit IdentifierA(const char *string) 00042 : m_string(string) 00043 {} 00044 00045 IdentifierA &operator=(const IdentifierA &identifier) { 00046 if (&identifier != this) 00047 m_string = identifier.m_string; 00048 return *this; 00049 } 00050 00051 IdentifierA &operator=(const std::string &string) { 00052 m_string = string; 00053 return *this; 00054 } 00055 00056 IdentifierA &operator+=(const IdentifierA &identifier) { 00057 m_string.append(identifier.m_string); 00058 return *this; 00059 } 00060 00061 IdentifierA &operator+=(const std::string &string) { 00062 m_string.append(string); 00063 return *this; 00064 } 00065 00066 const char *c_str() const { 00067 return m_string.c_str(); 00068 } 00069 00070 const size_t length() const { 00071 return m_string.length(); 00072 } 00073 00074 operator const std::string &() const { 00075 return m_string; 00076 } 00077 00078 private: 00079 std::string m_string; 00080 }; 00081 00082 00083 IdentifierA operator+(const IdentifierA &identifier1, const IdentifierA &identifier2); 00084 00085 IdentifierA operator+(const IdentifierA &identifier1, const std::string &string2); 00086 00087 std::string operator+(const std::string &string1, const IdentifierA &identifier2); 00088 00089 std::ostream &operator<<(std::ostream &os, const IdentifierA &identifier); 00090 00091 std::istream &operator>>(std::istream &is, IdentifierA &identifier); 00092 00093 bool operator<(const std::string &s1, const IdentifierA &s2); 00094 00095 bool operator<(const IdentifierA &s1, const std::string &s2); 00096 00097 bool operator<(const IdentifierA &s1, const IdentifierA &s2); 00098 00099 bool operator<(const IdentifierA &s1, const char *s2); 00100 00101 bool operator==(const std::string &s1, const IdentifierA &s2); 00102 00103 bool operator==(const IdentifierA &s1, const std::string &s2); 00104 00105 bool operator==(const IdentifierA &s1, const IdentifierA &s2); 00106 00107 bool operator==(const IdentifierA &s1, const char *s2); 00108 00109 bool operator<=(const std::string &s1, const IdentifierA &s2); 00110 00111 bool operator<=(const IdentifierA &s1, const std::string &s2); 00112 00113 bool operator<=(const IdentifierA &s1, const IdentifierA &s2); 00114 00115 bool operator<=(const IdentifierA &s1, const char *s2); 00116 00117 bool operator>(const std::string &s1, const IdentifierA &s2); 00118 00119 bool operator>(const IdentifierA &s1, const std::string &s2); 00120 00121 bool operator>(const IdentifierA &s1, const IdentifierA &s2); 00122 00123 bool operator>(const IdentifierA &s1, const char *s2); 00124 00125 bool operator>=(const std::string &s1, const IdentifierA &s2); 00126 00127 bool operator>=(const IdentifierA &s1, const std::string &s2); 00128 00129 bool operator>=(const IdentifierA &s1, const IdentifierA &s2); 00130 00131 bool operator>=(const IdentifierA &s1, const char *s2); 00132 00133 bool operator!=(const std::string &s1, const IdentifierA &s2); 00134 00135 bool operator!=(const IdentifierA &s1, const std::string &s2); 00136 00137 bool operator!=(const IdentifierA &s1, const IdentifierA &s2); 00138 00139 bool operator!=(const IdentifierA &s1, const char *s2); 00140 00141 00142 00143 00144 class IdentifierB : public std::string 00145 { 00146 public: 00147 static int compare(const char *s1, const size_t s1_length, const char *s2, const size_t s2_length); 00148 00149 IdentifierB() 00150 {} 00151 00152 IdentifierB(const IdentifierB &identifier) 00153 : std::string(static_cast<std::string>(identifier)) 00154 {} 00155 00156 explicit IdentifierB(const std::string &string) 00157 : std::string(string) 00158 {} 00159 00160 explicit IdentifierB(const char *string) 00161 : std::string(string) 00162 {} 00163 00164 IdentifierB &operator=(const IdentifierB &identifier) { 00165 std::string::operator=(identifier); 00166 return *this; 00167 } 00168 00169 IdentifierB &operator=(const std::string &string) { 00170 std::string::operator=(string); 00171 return *this; 00172 } 00173 00174 IdentifierB &operator=(const char *string) { 00175 std::string::operator=(string); 00176 return *this; 00177 } 00178 }; 00179 00180 IdentifierB operator+(const IdentifierB &identifier1, const IdentifierB &identifier2); 00181 00182 IdentifierB operator+(const IdentifierB &identifier1, const std::string &string2); 00183 00184 IdentifierB operator+(const IdentifierB &identifier1, const char *string2); 00185 00186 std::string operator+(const std::string &string1, const IdentifierB &identifier2); 00187 00188 std::ostream &operator<<(std::ostream &os, const IdentifierB &identifier); 00189 00190 std::istream &operator>>(std::istream &is, IdentifierB &identifier); 00191 00192 bool operator<(const std::string &s1, const IdentifierB &s2); 00193 00194 bool operator<(const IdentifierB &s1, const std::string &s2); 00195 00196 bool operator<(const IdentifierB &s1, const IdentifierB &s2); 00197 00198 bool operator<(const IdentifierB &s1, const char *s2); 00199 00200 bool operator==(const std::string &s1, const IdentifierB &s2); 00201 00202 bool operator==(const IdentifierB &s1, const std::string &s2); 00203 00204 bool operator==(const IdentifierB &s1, const IdentifierB &s2); 00205 00206 bool operator==(const IdentifierB &s1, const char *s2); 00207 00208 bool operator<=(const std::string &s1, const IdentifierB &s2); 00209 00210 bool operator<=(const IdentifierB &s1, const std::string &s2); 00211 00212 bool operator<=(const IdentifierB &s1, const IdentifierB &s2); 00213 00214 bool operator<=(const IdentifierB &s1, const char *s2); 00215 00216 bool operator>(const std::string &s1, const IdentifierB &s2); 00217 00218 bool operator>(const IdentifierB &s1, const std::string &s2); 00219 00220 bool operator>(const IdentifierB &s1, const IdentifierB &s2); 00221 00222 bool operator>(const IdentifierB &s1, const char *s2); 00223 00224 bool operator>=(const std::string &s1, const IdentifierB &s2); 00225 00226 bool operator>=(const IdentifierB &s1, const std::string &s2); 00227 00228 bool operator>=(const IdentifierB &s1, const IdentifierB &s2); 00229 00230 bool operator>=(const IdentifierB &s1, const char *s2); 00231 00232 bool operator!=(const std::string &s1, const IdentifierB &s2); 00233 00234 bool operator!=(const IdentifierB &s1, const std::string &s2); 00235 00236 bool operator!=(const IdentifierB &s1, const IdentifierB &s2); 00237 00238 bool operator!=(const IdentifierB &s1, const char *s2); 00239 00240 } // namespace stk_classic 00241 00242 namespace boost { 00243 00244 template <> 00245 struct hash<stk_classic::IdentifierA> 00246 { 00247 std::size_t operator()(const stk_classic::IdentifierA &s) const; 00248 }; 00249 00250 template <> 00251 struct hash<stk_classic::IdentifierB> 00252 { 00253 std::size_t operator()(const stk_classic::IdentifierB &s) const; 00254 }; 00255 00256 } // namespace boost 00257 00258 #endif // STK_UTIL_UTIL_IDENTIFIER_H