Sierra Toolkit  Version of the Day
Identifier.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <stk_util/util/Identifier.hpp>
10 #include <cstring>
11 #include <iostream>
12 
13 namespace stk_classic {
14 
15 namespace {
16 
17 int
18 compare(
19  const char * s1,
20  const size_t s1_length,
21  const char * s2,
22  const size_t s2_length)
23 {
24  const size_t length = std::min(s1_length, s2_length);
25  int result = ignorecase_traits::compare(s1, s2, length);
26  if (!result)
27  result = s1_length - s2_length;
28  return result;
29 }
30 
31 } // namespace <empty>
32 
33 
34 int
35 IdentifierA::compare(
36  const char * s1,
37  const size_t s1_length,
38  const char * s2,
39  const size_t s2_length)
40 {
41  const size_t length = std::min(s1_length, s2_length);
42  int result = ignorecase_traits::compare(s1, s2, length);
43  if (!result)
44  result = s1_length - s2_length;
45  return result;
46 }
47 
48 
49 IdentifierA operator+(const IdentifierA &identifier1, const IdentifierA &identifier2) {
50  IdentifierA identifier(identifier1);
51 
52  return identifier += identifier2;
53 }
54 
55 IdentifierA operator+(const IdentifierA &identifier1, const std::string &string2) {
56  IdentifierA identifier(identifier1);
57 
58  return identifier += IdentifierA(string2);
59 }
60 
61 std::string operator+(const std::string &string1, const IdentifierA &identifier2) {
62  std::string string(string1);
63 
64  return string += identifier2;
65 }
66 
67 std::ostream &operator<<(std::ostream &os, const IdentifierA &identifier) {
68  return os << identifier.c_str();
69 }
70 
71 std::istream &operator>>(std::istream &is, IdentifierA &identifier) {
72  std::string s;
73 
74  is >> s;
75  identifier = s;
76 
77  return is;
78 }
79 
80 bool operator<(const std::string &s1, const IdentifierA &s2) {
81  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0;
82 }
83 
84 bool operator<(const IdentifierA &s1, const std::string &s2) {
85  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0;
86 }
87 
88 bool operator<(const IdentifierA &s1, const char *s2) {
89  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) < 0;
90 }
91 
92 bool operator<(const IdentifierA &s1, const IdentifierA &s2) {
93  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0;
94 }
95 
96 bool operator==(const std::string &s1, const IdentifierA &s2) {
97  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0;
98 }
99 
100 bool operator==(const IdentifierA &s1, const std::string &s2) {
101  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0;
102 }
103 
104 bool operator==(const IdentifierA &s1, const char *s2) {
105  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) == 0;
106 }
107 
108 bool operator==(const IdentifierA &s1, const IdentifierA &s2) {
109  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0;
110 }
111 
112 bool operator<=(const std::string &s1, const IdentifierA &s2) {
113  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0;
114 }
115 
116 bool operator<=(const IdentifierA &s1, const std::string &s2) {
117  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0;
118 }
119 
120 bool operator<=(const IdentifierA &s1, const char *s2) {
121  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) <= 0;
122 }
123 
124 bool operator<=(const IdentifierA &s1, const IdentifierA &s2) {
125  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0;
126 }
127 
128 bool operator>(const std::string &s1, const IdentifierA &s2) {
129  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0;
130 }
131 
132 bool operator>(const IdentifierA &s1, const std::string &s2) {
133  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0;
134 }
135 
136 bool operator>(const IdentifierA &s1, const char *s2) {
137  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) > 0;
138 }
139 
140 bool operator>(const IdentifierA &s1, const IdentifierA &s2) {
141  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0;
142 }
143 
144 bool operator>=(const std::string &s1, const IdentifierA &s2) {
145  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0;
146 }
147 
148 bool operator>=(const IdentifierA &s1, const std::string &s2) {
149  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0;
150 }
151 
152 bool operator>=(const IdentifierA &s1, const char *s2) {
153  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) >= 0;
154 }
155 
156 bool operator>=(const IdentifierA &s1, const IdentifierA &s2) {
157  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0;
158 }
159 
160 bool operator!=(const std::string &s1, const IdentifierA &s2) {
161  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0;
162 }
163 
164 bool operator!=(const IdentifierA &s1, const std::string &s2) {
165  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0;
166 }
167 
168 bool operator!=(const IdentifierA &s1, const char *s2) {
169  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) != 0;
170 }
171 
172 bool operator!=(const IdentifierA &s1, const IdentifierA &s2) {
173  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0;
174 }
175 
176 
177 
178 int
179 IdentifierB::compare(
180  const char * s1,
181  const size_t s1_length,
182  const char * s2,
183  const size_t s2_length)
184 {
185  const size_t length = std::min(s1_length, s2_length);
186  int result = ignorecase_traits::compare(s1, s2, length);
187  if (!result)
188  result = s1_length - s2_length;
189  return result;
190 }
191 
192 
193 std::ostream &operator<<(std::ostream &os, const IdentifierB &identifier) {
194  return os << identifier.c_str();
195 }
196 
197 std::istream &operator>>(std::istream &is, IdentifierB &identifier) {
198  std::string s;
199 
200  is >> s;
201  identifier = s;
202 
203  return is;
204 }
205 
206 IdentifierB operator+(const IdentifierB &identifier1, const IdentifierB &identifier2) {
207  std::string identifier(identifier1);
208 
209  return IdentifierB(identifier += identifier2);
210 }
211 
212 IdentifierB operator+(const IdentifierB &identifier1, const std::string &string2) {
213  std::string identifier(identifier1);
214 
215  return IdentifierB(identifier += string2);
216 }
217 
218 IdentifierB operator+(const IdentifierB &identifier1, const char *string2) {
219  IdentifierB identifier(identifier1);
220 
221  return IdentifierB(identifier += string2);
222 }
223 
224 std::string operator+(const std::string &string1, const IdentifierB &identifier2) {
225  std::string string(string1);
226 
227  return string += identifier2;
228 }
229 
230 bool operator<(const IdentifierB &s1, const std::string &s2) {
231  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0;
232 }
233 
234 bool operator<(const IdentifierB &s1, const char *s2) {
235  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) < 0;
236 }
237 
238 bool operator<(const IdentifierB &s1, const IdentifierB &s2) {
239  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) < 0;
240 }
241 
242 bool operator==(const std::string &s1, const IdentifierB &s2) {
243  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0;
244 }
245 
246 bool operator==(const IdentifierB &s1, const std::string &s2) {
247  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0;
248 }
249 
250 bool operator==(const IdentifierB &s1, const char *s2) {
251  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) == 0;
252 }
253 
254 bool operator==(const IdentifierB &s1, const IdentifierB &s2) {
255  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) == 0;
256 }
257 
258 bool operator<=(const std::string &s1, const IdentifierB &s2) {
259  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0;
260 }
261 
262 bool operator<=(const IdentifierB &s1, const std::string &s2) {
263  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0;
264 }
265 
266 bool operator<=(const IdentifierB &s1, const char *s2) {
267  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) <= 0;
268 }
269 
270 bool operator<=(const IdentifierB &s1, const IdentifierB &s2) {
271  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) <= 0;
272 }
273 
274 bool operator>(const std::string &s1, const IdentifierB &s2) {
275  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0;
276 }
277 
278 bool operator>(const IdentifierB &s1, const std::string &s2) {
279  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0;
280 }
281 
282 bool operator>(const IdentifierB &s1, const char *s2) {
283  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) > 0;
284 }
285 
286 bool operator>(const IdentifierB &s1, const IdentifierB &s2) {
287  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) > 0;
288 }
289 
290 bool operator>=(const std::string &s1, const IdentifierB &s2) {
291  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0;
292 }
293 
294 bool operator>=(const IdentifierB &s1, const std::string &s2) {
295  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0;
296 }
297 
298 bool operator>=(const IdentifierB &s1, const char *s2) {
299  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) >= 0;
300 }
301 
302 bool operator>=(const IdentifierB &s1, const IdentifierB &s2) {
303  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) >= 0;
304 }
305 
306 bool operator!=(const std::string &s1, const IdentifierB &s2) {
307  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0;
308 }
309 
310 bool operator!=(const IdentifierB &s1, const std::string &s2) {
311  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0;
312 }
313 
314 bool operator!=(const IdentifierB &s1, const char *s2) {
315  return compare(s1.c_str(), s1.length(), s2, std::strlen(s2)) != 0;
316 }
317 
318 bool operator!=(const IdentifierB &s1, const IdentifierB &s2) {
319  return compare(s1.c_str(), s1.length(), s2.c_str(), s2.length()) != 0;
320 }
321 
322 } // namespace stk_classic
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
Definition: Bucket.cpp:239
basic_string< char > string
string / wstring
static int compare(const char *s1, const char *s2, std::size_t n)
Member function compare compares up to n characters of s1 and s2 and returns -1 if s1 is less then s2...
Definition: ci_traits.cpp:12
Sierra Toolkit.