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