|
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 #include <stk_util/util/Identifier.hpp> 00010 #include <cstring> 00011 00012 namespace stk { 00013 00014 namespace { 00015 00016 int 00017 compare( 00018 const char * s1, 00019 const size_t s1_length, 00020 const char * s2, 00021 const size_t s2_length) 00022 { 00023 const size_t length = std::min(s1_length, s2_length); 00024 int result = ignorecase_traits::compare(s1, s2, length); 00025 if (!result) 00026 result = s1_length - s2_length; 00027 return result; 00028 } 00029 00030 } // namespace <empty> 00031 00032 00033 int 00034 IdentifierA::compare( 00035 const char * s1, 00036 const size_t s1_length, 00037 const char * s2, 00038 const size_t s2_length) 00039 { 00040 const size_t length = std::min(s1_length, s2_length); 00041 int result = ignorecase_traits::compare(s1, s2, length); 00042 if (!result) 00043 result = s1_length - s2_length; 00044 return result; 00045 } 00046 00047 00048 IdentifierA operator+(const IdentifierA &identifier1, const IdentifierA &identifier2) { 00049 IdentifierA identifier(identifier1); 00050 00051 return identifier += identifier2; 00052 } 00053 00054 IdentifierA operator+(const IdentifierA &identifier1, const std::string &string2) { 00055 IdentifierA identifier(identifier1); 00056 00057 return identifier += IdentifierA(string2); 00058 } 00059 00060 std::string operator+(const std::string &string1, const IdentifierA &identifier2) { 00061 std::string string(string1); 00062 00063 return string += identifier2; 00064 } 00065 00066 std::ostream &operator<<(std::ostream &os, const IdentifierA &identifier) { 00067 return os << identifier.c_str(); 00068 } 00069 00070 std::istream &operator>>(std::istream &is, IdentifierA &identifier) { 00071 std::string s; 00072 00073 is >> s; 00074 identifier = s; 00075 00076 return is; 00077 } 00078 00079 bool operator<(const std::string &s1, const IdentifierA &s2) { 00080 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0; 00081 } 00082 00083 bool operator<(const IdentifierA &s1, const std::string &s2) { 00084 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0; 00085 } 00086 00087 bool operator<(const IdentifierA &s1, const char *s2) { 00088 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) < 0; 00089 } 00090 00091 bool operator<(const IdentifierA &s1, const IdentifierA &s2) { 00092 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0; 00093 } 00094 00095 bool operator==(const std::string &s1, const IdentifierA &s2) { 00096 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0; 00097 } 00098 00099 bool operator==(const IdentifierA &s1, const std::string &s2) { 00100 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0; 00101 } 00102 00103 bool operator==(const IdentifierA &s1, const char *s2) { 00104 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) == 0; 00105 } 00106 00107 bool operator==(const IdentifierA &s1, const IdentifierA &s2) { 00108 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0; 00109 } 00110 00111 bool operator<=(const std::string &s1, const IdentifierA &s2) { 00112 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0; 00113 } 00114 00115 bool operator<=(const IdentifierA &s1, const std::string &s2) { 00116 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0; 00117 } 00118 00119 bool operator<=(const IdentifierA &s1, const char *s2) { 00120 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) <= 0; 00121 } 00122 00123 bool operator<=(const IdentifierA &s1, const IdentifierA &s2) { 00124 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0; 00125 } 00126 00127 bool operator>(const std::string &s1, const IdentifierA &s2) { 00128 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0; 00129 } 00130 00131 bool operator>(const IdentifierA &s1, const std::string &s2) { 00132 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0; 00133 } 00134 00135 bool operator>(const IdentifierA &s1, const char *s2) { 00136 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) > 0; 00137 } 00138 00139 bool operator>(const IdentifierA &s1, const IdentifierA &s2) { 00140 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0; 00141 } 00142 00143 bool operator>=(const std::string &s1, const IdentifierA &s2) { 00144 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0; 00145 } 00146 00147 bool operator>=(const IdentifierA &s1, const std::string &s2) { 00148 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0; 00149 } 00150 00151 bool operator>=(const IdentifierA &s1, const char *s2) { 00152 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) >= 0; 00153 } 00154 00155 bool operator>=(const IdentifierA &s1, const IdentifierA &s2) { 00156 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0; 00157 } 00158 00159 bool operator!=(const std::string &s1, const IdentifierA &s2) { 00160 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0; 00161 } 00162 00163 bool operator!=(const IdentifierA &s1, const std::string &s2) { 00164 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0; 00165 } 00166 00167 bool operator!=(const IdentifierA &s1, const char *s2) { 00168 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) != 0; 00169 } 00170 00171 bool operator!=(const IdentifierA &s1, const IdentifierA &s2) { 00172 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0; 00173 } 00174 00175 00176 00177 int 00178 IdentifierB::compare( 00179 const char * s1, 00180 const size_t s1_length, 00181 const char * s2, 00182 const size_t s2_length) 00183 { 00184 const size_t length = std::min(s1_length, s2_length); 00185 int result = ignorecase_traits::compare(s1, s2, length); 00186 if (!result) 00187 result = s1_length - s2_length; 00188 return result; 00189 } 00190 00191 00192 std::ostream &operator<<(std::ostream &os, const IdentifierB &identifier) { 00193 return os << identifier.c_str(); 00194 } 00195 00196 std::istream &operator>>(std::istream &is, IdentifierB &identifier) { 00197 std::string s; 00198 00199 is >> s; 00200 identifier = s; 00201 00202 return is; 00203 } 00204 00205 IdentifierB operator+(const IdentifierB &identifier1, const IdentifierB &identifier2) { 00206 std::string identifier(identifier1); 00207 00208 return IdentifierB(identifier += identifier2); 00209 } 00210 00211 IdentifierB operator+(const IdentifierB &identifier1, const std::string &string2) { 00212 std::string identifier(identifier1); 00213 00214 return IdentifierB(identifier += string2); 00215 } 00216 00217 IdentifierB operator+(const IdentifierB &identifier1, const char *string2) { 00218 IdentifierB identifier(identifier1); 00219 00220 return IdentifierB(identifier += string2); 00221 } 00222 00223 std::string operator+(const std::string &string1, const IdentifierB &identifier2) { 00224 std::string string(string1); 00225 00226 return string += identifier2; 00227 } 00228 00229 bool operator<(const IdentifierB &s1, const std::string &s2) { 00230 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0; 00231 } 00232 00233 bool operator<(const IdentifierB &s1, const char *s2) { 00234 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) < 0; 00235 } 00236 00237 bool operator<(const IdentifierB &s1, const IdentifierB &s2) { 00238 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0; 00239 } 00240 00241 bool operator==(const std::string &s1, const IdentifierB &s2) { 00242 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0; 00243 } 00244 00245 bool operator==(const IdentifierB &s1, const std::string &s2) { 00246 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0; 00247 } 00248 00249 bool operator==(const IdentifierB &s1, const char *s2) { 00250 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) == 0; 00251 } 00252 00253 bool operator==(const IdentifierB &s1, const IdentifierB &s2) { 00254 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0; 00255 } 00256 00257 bool operator<=(const std::string &s1, const IdentifierB &s2) { 00258 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0; 00259 } 00260 00261 bool operator<=(const IdentifierB &s1, const std::string &s2) { 00262 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0; 00263 } 00264 00265 bool operator<=(const IdentifierB &s1, const char *s2) { 00266 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) <= 0; 00267 } 00268 00269 bool operator<=(const IdentifierB &s1, const IdentifierB &s2) { 00270 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0; 00271 } 00272 00273 bool operator>(const std::string &s1, const IdentifierB &s2) { 00274 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0; 00275 } 00276 00277 bool operator>(const IdentifierB &s1, const std::string &s2) { 00278 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0; 00279 } 00280 00281 bool operator>(const IdentifierB &s1, const char *s2) { 00282 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) > 0; 00283 } 00284 00285 bool operator>(const IdentifierB &s1, const IdentifierB &s2) { 00286 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0; 00287 } 00288 00289 bool operator>=(const std::string &s1, const IdentifierB &s2) { 00290 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0; 00291 } 00292 00293 bool operator>=(const IdentifierB &s1, const std::string &s2) { 00294 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0; 00295 } 00296 00297 bool operator>=(const IdentifierB &s1, const char *s2) { 00298 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) >= 0; 00299 } 00300 00301 bool operator>=(const IdentifierB &s1, const IdentifierB &s2) { 00302 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0; 00303 } 00304 00305 bool operator!=(const std::string &s1, const IdentifierB &s2) { 00306 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0; 00307 } 00308 00309 bool operator!=(const IdentifierB &s1, const std::string &s2) { 00310 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0; 00311 } 00312 00313 bool operator!=(const IdentifierB &s1, const char *s2) { 00314 return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) != 0; 00315 } 00316 00317 bool operator!=(const IdentifierB &s1, const IdentifierB &s2) { 00318 return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0; 00319 } 00320 00321 } // namespace stk