Line data Source code
1 : // Copyright (c) 2006-2024 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/advgetopt
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 :
20 :
21 : /** \file
22 : * \brief Implementation of the option_info class.
23 : *
24 : * This is the implementation of the class used to define one command
25 : * line option.
26 : */
27 :
28 : // self
29 : //
30 : #include "advgetopt/option_info.h"
31 :
32 : #include "advgetopt/exception.h"
33 : #include "advgetopt/validator_double.h"
34 : #include "advgetopt/validator_integer.h"
35 :
36 :
37 : // cppthread
38 : //
39 : #include <cppthread/log.h>
40 :
41 :
42 : // libutf8
43 : //
44 : #include <libutf8/libutf8.h>
45 :
46 :
47 : // last include
48 : //
49 : #include <snapdev/poison.h>
50 :
51 :
52 :
53 : namespace advgetopt
54 : {
55 :
56 :
57 :
58 : /** \brief Initialize a reference to an option_info object.
59 : *
60 : * This constructor creates a reference to the specified \p opt
61 : * option_info object.
62 : *
63 : * This gives you read and write access to the very first value held by
64 : * the \p opt object.
65 : *
66 : * \note
67 : * The option may not yet be defined in which case the default value is
68 : * used as the current value.
69 : *
70 : * \param[in] opt The option to create the reference of.
71 : */
72 172 : option_info_ref::option_info_ref(option_info::pointer_t opt)
73 172 : : f_opt(opt)
74 : {
75 172 : }
76 :
77 :
78 : /** \brief Retrieve the length of the option's value.
79 : *
80 : * This function checks the option's value and returns true if it is empty.
81 : *
82 : * \note
83 : * If the value is not currently defined, this function returns the
84 : * length of the default value.
85 : *
86 : * \return The length of the option's value.
87 : */
88 33 : bool option_info_ref::empty() const
89 : {
90 33 : if(f_opt->is_defined())
91 : {
92 17 : return f_opt->get_value().empty();
93 : }
94 :
95 16 : return true;
96 : }
97 :
98 :
99 : /** \brief Return the length of the option's value.
100 : *
101 : * This function returns the length of the option's value. This is the
102 : * number of bytes in the string.
103 : *
104 : * \note
105 : * If the value is not currently defined, this function returns the
106 : * length of the default value.
107 : *
108 : * \return The length of the option's value.
109 : */
110 26 : size_t option_info_ref::length() const
111 : {
112 26 : if(f_opt->is_defined())
113 : {
114 14 : return f_opt->get_value().length();
115 : }
116 :
117 12 : return f_opt->get_default().length();
118 : }
119 :
120 :
121 : /** \brief Return the length of the option's value.
122 : *
123 : * This function returns the length of the option's value. This is the
124 : * number of bytes in the string.
125 : *
126 : * \return The length of the option's value.
127 : */
128 13 : size_t option_info_ref::size() const
129 : {
130 13 : return length();
131 : }
132 :
133 :
134 : /** \brief Retrieve the referenced option as a long.
135 : *
136 : * This function attempts to retrieve the option value as a long integer.
137 : *
138 : * If the value is not yet defined, the function attempts to return the
139 : * default value converted to an integer. If that fails, the function
140 : * returns -1 after it emitted an error in the log.
141 : *
142 : * When the value is not defined and there is no default, the function
143 : * returns 0 (as if an empty string represented 0.)
144 : *
145 : * \return The value as a long or -1 or 0.
146 : */
147 29 : long option_info_ref::get_long() const
148 : {
149 29 : if(f_opt->is_defined())
150 : {
151 26 : return f_opt->get_long();
152 : }
153 :
154 3 : if(!f_opt->has_default())
155 : {
156 1 : return 0;
157 : }
158 :
159 2 : std::int64_t v;
160 2 : if(!validator_integer::convert_string(f_opt->get_default(), v))
161 : {
162 2 : cppthread::log << cppthread::log_level_t::error
163 1 : << "invalid default value for a number ("
164 1 : << f_opt->get_default()
165 1 : << ") in parameter --"
166 1 : << f_opt->get_name()
167 1 : << " at offset 0."
168 2 : << cppthread::end;
169 1 : return -1;
170 : }
171 :
172 1 : return v;
173 : }
174 :
175 :
176 : /** \brief Retrieve the referenced option as a double.
177 : *
178 : * This function attempts to retrieve the option value as a double floating
179 : * point.
180 : *
181 : * If the value is not yet defined, the function attempts to return the
182 : * default value converted to a double. If that fails, the function
183 : * returns -1 after it emitted an error in the log.
184 : *
185 : * When the value is not defined and there is no default, the function
186 : * returns 0 (as if an empty string represented 0.)
187 : *
188 : * \return The value as a double or -1.0 or 0.0.
189 : */
190 29 : double option_info_ref::get_double() const
191 : {
192 29 : if(f_opt->is_defined())
193 : {
194 26 : return f_opt->get_double();
195 : }
196 :
197 3 : if(!f_opt->has_default())
198 : {
199 1 : return 0.0;
200 : }
201 :
202 2 : double v;
203 2 : if(!validator_double::convert_string(f_opt->get_default(), v))
204 : {
205 2 : cppthread::log << cppthread::log_level_t::error
206 1 : << "invalid default value as a double number ("
207 1 : << f_opt->get_default()
208 1 : << ") in parameter --"
209 1 : << f_opt->get_name()
210 1 : << " at offset 0."
211 2 : << cppthread::end;
212 1 : return -1.0;
213 : }
214 :
215 1 : return v;
216 : }
217 :
218 :
219 : /** \brief Convert the reference to a string (a.k.a. read the value)
220 : *
221 : * This cast operator transforms the reference in a string which has
222 : * the contents of the option value.
223 : *
224 : * \return The option contents as a string.
225 : */
226 503 : option_info_ref::operator std::string () const
227 : {
228 503 : if(f_opt->is_defined())
229 : {
230 338 : return f_opt->get_value();
231 : }
232 :
233 165 : return f_opt->get_default();
234 : }
235 :
236 :
237 : /** \brief Set the option value to \p value.
238 : *
239 : * This assignment operator is used to change the value of the option.
240 : *
241 : * The input character is transform in a string and saved as such in the
242 : * option. If the character is '\0', then the value is cleared instead.
243 : *
244 : * \param[in] value The ISO-8859-1 character to save in the option_info object.
245 : *
246 : * \return A reference to this object_info_ref.
247 : */
248 5 : option_info_ref & option_info_ref::operator = (char value)
249 : {
250 5 : std::string v;
251 5 : if(value != '\0')
252 : {
253 3 : v += value;
254 : }
255 5 : f_opt->set_value(0, v); // source considered DIRECT
256 5 : return *this;
257 5 : }
258 :
259 :
260 : /** \brief Set the option value to \p value.
261 : *
262 : * This assignment operator is used to change the value of the option.
263 : *
264 : * The input character is transform in a string and saved as such in the
265 : * option. If the character is '\0', then the value is cleared instead.
266 : *
267 : * \param[in] value The unicode character to save in the option_info object.
268 : *
269 : * \return A reference to this object_info_ref.
270 : */
271 4 : option_info_ref & option_info_ref::operator = (char32_t value)
272 : {
273 4 : std::string v;
274 4 : if(value != U'\0')
275 : {
276 2 : v = libutf8::to_u8string(value);
277 : }
278 4 : f_opt->set_value(0, v); // source considered DIRECT
279 4 : return *this;
280 4 : }
281 :
282 :
283 : /** \brief Set the option value to \p value.
284 : *
285 : * This assignment operator can be used to change the value of the
286 : * option.
287 : *
288 : * \param[in] value The new value to save in the option_info object.
289 : *
290 : * \return A reference to this object_info_ref.
291 : */
292 5 : option_info_ref & option_info_ref::operator = (char const * value)
293 : {
294 5 : if(value == nullptr)
295 : {
296 1 : f_opt->set_value(0, std::string()); // source considered DIRECT
297 : }
298 : else
299 : {
300 4 : f_opt->set_value(0, value); // source considered DIRECT
301 : }
302 5 : return *this;
303 : }
304 :
305 :
306 : /** \brief Set the option value to \p value.
307 : *
308 : * This assignment operator can be used to change the value of the
309 : * option.
310 : *
311 : * \param[in] value The new value to save in the option_info object.
312 : *
313 : * \return A reference to this object_info_ref.
314 : */
315 3 : option_info_ref & option_info_ref::operator = (std::string const & value)
316 : {
317 3 : f_opt->set_value(0, value); // source considered DIRECT
318 3 : return *this;
319 : }
320 :
321 :
322 : /** \brief Set the value of this option to the value of another option.
323 : *
324 : * This assignment operator allows you to copy the value from reference
325 : * value to another.
326 : *
327 : * \param[in] value The other option to read the value from.
328 : *
329 : * \return A reference to this object_info_ref.
330 : */
331 4 : option_info_ref & option_info_ref::operator = (option_info_ref const & value)
332 : {
333 4 : f_opt->set_value(0, value); // source considered DIRECT
334 4 : return *this;
335 : }
336 :
337 :
338 : /** \brief Append the character \p value to this option's value.
339 : *
340 : * This assignment operator can be used to append a character to the
341 : * existing value of the option.
342 : *
343 : * \note
344 : * The character is taken as an ISO-8859-1. If you want to use a Unicode
345 : * character, make sure to use a char32_t character.
346 : *
347 : * \param[in] value The character to append to the option_info's value.
348 : *
349 : * \return A reference to this object_info_ref.
350 : */
351 8 : option_info_ref & option_info_ref::operator += (char value)
352 : {
353 8 : std::string v;
354 8 : if(value != '\0')
355 : {
356 4 : v += value;
357 : }
358 8 : f_opt->set_value(0, static_cast<std::string>(*this) + v); // source considered DIRECT
359 8 : return *this;
360 8 : }
361 :
362 :
363 : /** \brief Append the character \p value to this option's value.
364 : *
365 : * This assignment operator can be used to append a character to the
366 : * existing value of the option.
367 : *
368 : * \param[in] value The character to append to the option_info's value.
369 : *
370 : * \return A reference to this object_info_ref.
371 : */
372 6 : option_info_ref & option_info_ref::operator += (char32_t value)
373 : {
374 6 : std::string v;
375 6 : if(value != '\0')
376 : {
377 2 : v += libutf8::to_u8string(value);
378 : }
379 6 : f_opt->set_value(0, static_cast<std::string>(*this) + v); // source considered DIRECT
380 6 : return *this;
381 6 : }
382 :
383 :
384 : /** \brief Append \p value to this option's value.
385 : *
386 : * This assignment operator can be used to append a string to the existing
387 : * value of the option.
388 : *
389 : * \param[in] value The value to append to the option_info's value.
390 : *
391 : * \return A reference to this object_info_ref.
392 : */
393 7 : option_info_ref & option_info_ref::operator += (char const * value)
394 : {
395 7 : std::string v;
396 7 : if(value != nullptr)
397 : {
398 5 : v = value;
399 : }
400 7 : f_opt->set_value(0, static_cast<std::string>(*this) + v); // source considered DIRECT
401 7 : return *this;
402 7 : }
403 :
404 :
405 : /** \brief Append \p value to this option's value.
406 : *
407 : * This assignment operator is used to append a string to the existing
408 : * value of the option.
409 : *
410 : * \param[in] value The value to append to the option_info's value.
411 : *
412 : * \return A reference to this object_info_ref.
413 : */
414 5 : option_info_ref & option_info_ref::operator += (std::string const & value)
415 : {
416 5 : f_opt->set_value(0, static_cast<std::string>(*this) + value); // source considered DIRECT
417 5 : return *this;
418 : }
419 :
420 :
421 : /** \brief Append the value of this \p value option to this option_info's value.
422 : *
423 : * This assignment operator is used to append a string to the existing
424 : * value of this option.
425 : *
426 : * \param[in] value The other option to read the value from.
427 : *
428 : * \return A reference to this object_info_ref.
429 : */
430 6 : option_info_ref & option_info_ref::operator += (option_info_ref const & value)
431 : {
432 18 : f_opt->set_value( // source considered DIRECT
433 : 0
434 12 : , static_cast<std::string>(*this) + static_cast<std::string>(value));
435 6 : return *this;
436 : }
437 :
438 :
439 : /** \brief Append the character \p value to this option's value.
440 : *
441 : * This operator is used to append a character to the value of the option
442 : * and returns the result as a string.
443 : *
444 : * \note
445 : * This version appends an ISO-8859-1 character. Make sure to use a
446 : * char32_t character to add a Unicode character.
447 : *
448 : * \param[in] value The character to append to the option_info's value.
449 : *
450 : * \return A string with the resulting concatenation.
451 : */
452 9 : std::string option_info_ref::operator + (char value) const
453 : {
454 18 : return static_cast<std::string>(*this) + value;
455 : }
456 :
457 :
458 : /** \brief Append the character \p value to this option's value.
459 : *
460 : * This operator is used to append a Unicode character to the value of the
461 : * option and returns the result as a string.
462 : *
463 : * \param[in] value The character to append to the option_info's value.
464 : *
465 : * \return A string with the resulting concatenation.
466 : */
467 11 : std::string option_info_ref::operator + (char32_t value) const
468 : {
469 22 : return static_cast<std::string>(*this) + libutf8::to_u8string(value);
470 : }
471 :
472 :
473 : /** \brief Append \p value to this option's value.
474 : *
475 : * This operator is used to append a string to the value of the option
476 : * and return the result as a string.
477 : *
478 : * \param[in] value The string to append to the option_info's value.
479 : *
480 : * \return A string with the resulting concatenation.
481 : */
482 8 : std::string option_info_ref::operator + (char const * value) const
483 : {
484 8 : if(value == nullptr)
485 : {
486 2 : return *this;
487 : }
488 12 : return static_cast<std::string>(*this) + value;
489 : }
490 :
491 :
492 : /** \brief Append \p value to this option's value.
493 : *
494 : * This operator is used to append a string to the value of the option
495 : * and return the result as a string.
496 : *
497 : * \param[in] value The value to append to the option_info's value.
498 : *
499 : * \return A string with the resulting concatenation.
500 : */
501 5 : std::string option_info_ref::operator + (std::string const & value) const
502 : {
503 10 : return static_cast<std::string>(*this) + value;
504 : }
505 :
506 :
507 : /** \brief Append the value of this \p value option to this option_info's value.
508 : *
509 : * This operator is used to append two option references to each others and
510 : * return the concatenated string as the result.
511 : *
512 : * \param[in] value The other option to read the value from.
513 : *
514 : * \return A reference to this object_info_ref.
515 : */
516 10 : std::string option_info_ref::operator + (option_info_ref const & value) const
517 : {
518 20 : return static_cast<std::string>(*this)
519 30 : + static_cast<std::string>(value);
520 : }
521 :
522 :
523 : /** \brief Concatenate a character and an option reference value.
524 : *
525 : * This operator concatenates the \p value ISO-8859-1 character to the front
526 : * of the \p rhs reference.
527 : *
528 : * \param[in] value A character to add to the left of the referred value.
529 : * \param[in] rhs The referred value.
530 : *
531 : * \return The concatenated result.
532 : */
533 13 : std::string operator + (char value, option_info_ref const & rhs)
534 : {
535 26 : return value + static_cast<std::string>(rhs);
536 : }
537 :
538 :
539 : /** \brief Concatenate a character and an option reference value.
540 : *
541 : * This operator concatenates the \p value Unicode character to the front
542 : * of the \p rhs reference.
543 : *
544 : * \param[in] value A character to add to the left of the referred value.
545 : * \param[in] rhs The referred value.
546 : *
547 : * \return The concatenated result.
548 : */
549 12 : std::string operator + (char32_t value, option_info_ref const & rhs)
550 : {
551 24 : return libutf8::to_u8string(value) + static_cast<std::string>(rhs);
552 : }
553 :
554 :
555 : /** \brief Concatenate a string and an option reference value.
556 : *
557 : * This operator concatenates the \p value string to the front
558 : * of the \p rhs reference.
559 : *
560 : * \param[in] value A character to add to the left of the referred value.
561 : * \param[in] rhs The referred value.
562 : *
563 : * \return The concatenated result.
564 : */
565 5 : std::string operator + (char const * value, option_info_ref const & rhs)
566 : {
567 5 : if(value == nullptr)
568 : {
569 2 : return rhs;
570 : }
571 6 : return value + static_cast<std::string>(rhs);
572 : }
573 :
574 :
575 : /** \brief Concatenate a string and an option reference value.
576 : *
577 : * This operator concatenates the \p value string to the front
578 : * of the \p rhs reference.
579 : *
580 : * \param[in] value A character to add to the left of the referred value.
581 : * \param[in] rhs The referred value.
582 : *
583 : * \return The concatenated result.
584 : */
585 3 : std::string operator + (std::string const & value, option_info_ref const & rhs)
586 : {
587 6 : return value + static_cast<std::string>(rhs);
588 : }
589 :
590 :
591 : /** \brief Check whether the value is an empty string or not.
592 : *
593 : * This function calls the empty function and returns the opposite result.
594 : *
595 : * \return true if the value is not an empty string.
596 : */
597 2 : option_info_ref::operator bool () const
598 : {
599 2 : return !empty();
600 : }
601 :
602 :
603 : /** \brief Check whether the value is an empty string or not.
604 : *
605 : * This function calls the empty function and returns the result.
606 : *
607 : * \return true if the value is an empty string.
608 : */
609 2 : bool option_info_ref::operator ! () const
610 : {
611 2 : return empty();
612 : }
613 :
614 :
615 : /** \brief Compare this option's value with the specified string.
616 : *
617 : * This operator compares this option's value with the specified string.
618 : *
619 : * \param[in] value A string to compare this option's value with.
620 : *
621 : * \return true if both are equal.
622 : */
623 67 : bool option_info_ref::operator == (char const * value) const
624 : {
625 67 : if(value == nullptr)
626 : {
627 2 : return empty();
628 : }
629 65 : return static_cast<std::string>(*this) == value;
630 : }
631 :
632 :
633 : /** \brief Compare this option's value with the specified string.
634 : *
635 : * This operator compares this option's value with the specified string.
636 : *
637 : * \param[in] value A string to compare this option's value with.
638 : *
639 : * \return true if both are equal.
640 : */
641 45 : bool option_info_ref::operator == (std::string const & value) const
642 : {
643 45 : return static_cast<std::string>(*this) == value;
644 : }
645 :
646 :
647 : /** \brief Compare this option's value with the value of option \p value.
648 : *
649 : * This operator compares this option's value with the value of the
650 : * option specified in \p value.
651 : *
652 : * \param[in] value A string to compare this option's value with.
653 : *
654 : * \return true if both are equal.
655 : */
656 15 : bool option_info_ref::operator == (option_info_ref const & value) const
657 : {
658 15 : return static_cast<std::string>(*this) == static_cast<std::string>(value);
659 : }
660 :
661 :
662 : /** \brief Compare this option's value with the specified string.
663 : *
664 : * This operator compares this option's value with the specified string.
665 : *
666 : * \param[in] value A string to compare this option's value with.
667 : *
668 : * \return true if both are not equal.
669 : */
670 8 : bool option_info_ref::operator != (char const * value) const
671 : {
672 8 : if(value == nullptr)
673 : {
674 2 : return !empty();
675 : }
676 6 : return static_cast<std::string>(*this) != value;
677 : }
678 :
679 :
680 : /** \brief Compare this option's value with the specified string.
681 : *
682 : * This operator compares this option's value with the specified string.
683 : *
684 : * \param[in] value A string to compare this option's value with.
685 : *
686 : * \return true if both are not equal.
687 : */
688 6 : bool option_info_ref::operator != (std::string const & value) const
689 : {
690 6 : return static_cast<std::string>(*this) != value;
691 : }
692 :
693 :
694 : /** \brief Compare this option's value with the value of option \p value.
695 : *
696 : * This operator compares this option's value with the value of the
697 : * option specified in \p value.
698 : *
699 : * \param[in] value A string to compare this option's value with.
700 : *
701 : * \return true if both are not equal.
702 : */
703 10 : bool option_info_ref::operator != (option_info_ref const & value) const
704 : {
705 10 : return static_cast<std::string>(*this) != static_cast<std::string>(value);
706 : }
707 :
708 :
709 : /** \brief Compare this option's value with the specified string.
710 : *
711 : * This operator compares this option's value with the specified string.
712 : *
713 : * \param[in] value A string to compare this option's value with.
714 : *
715 : * \return true if lhs is less than rhs.
716 : */
717 8 : bool option_info_ref::operator < (char const * value) const
718 : {
719 8 : if(value == nullptr)
720 : {
721 2 : return false;
722 : }
723 6 : return static_cast<std::string>(*this) < value;
724 : }
725 :
726 :
727 : /** \brief Compare this option's value with the specified string.
728 : *
729 : * This operator compares this option's value with the specified string.
730 : *
731 : * \param[in] value A string to compare this option's value with.
732 : *
733 : * \return true if lhs is less than rhs.
734 : */
735 6 : bool option_info_ref::operator < (std::string const & value) const
736 : {
737 6 : return static_cast<std::string>(*this) < value;
738 : }
739 :
740 :
741 : /** \brief Compare this option's value with the value of option \p value.
742 : *
743 : * This operator compares this option's value with the value of the
744 : * option specified in \p value.
745 : *
746 : * \param[in] value A string to compare this option's value with.
747 : *
748 : * \return true if lhs is less than rhs.
749 : */
750 10 : bool option_info_ref::operator < (option_info_ref const & value) const
751 : {
752 10 : return static_cast<std::string>(*this) < static_cast<std::string>(value);
753 : }
754 :
755 :
756 : /** \brief Compare this option's value with the specified string.
757 : *
758 : * This operator compares this option's value with the specified string.
759 : *
760 : * \param[in] value A string to compare this option's value with.
761 : *
762 : * \return true if lhs is less or equal than rhs.
763 : */
764 8 : bool option_info_ref::operator <= (char const * value) const
765 : {
766 8 : if(value == nullptr)
767 : {
768 2 : return empty();
769 : }
770 6 : return static_cast<std::string>(*this) <= value;
771 : }
772 :
773 :
774 : /** \brief Compare this option's value with the specified string.
775 : *
776 : * This operator compares this option's value with the specified string.
777 : *
778 : * \param[in] value A string to compare this option's value with.
779 : *
780 : * \return true if lhs is less or equal than rhs.
781 : */
782 6 : bool option_info_ref::operator <= (std::string const & value) const
783 : {
784 6 : return static_cast<std::string>(*this) <= value;
785 : }
786 :
787 :
788 : /** \brief Compare this option's value with the value of option \p value.
789 : *
790 : * This operator compares this option's value with the value of the
791 : * option specified in \p value.
792 : *
793 : * \param[in] value A string to compare this option's value with.
794 : *
795 : * \return true if lhs is less or equal than rhs.
796 : */
797 10 : bool option_info_ref::operator <= (option_info_ref const & value) const
798 : {
799 10 : return static_cast<std::string>(*this) <= static_cast<std::string>(value);
800 : }
801 :
802 :
803 : /** \brief Compare this option's value with the specified string.
804 : *
805 : * This operator compares this option's value with the specified string.
806 : *
807 : * \param[in] value A string to compare this option's value with.
808 : *
809 : * \return true if lhs is greater than rhs.
810 : */
811 8 : bool option_info_ref::operator > (char const * value) const
812 : {
813 8 : if(value == nullptr)
814 : {
815 2 : return !empty();
816 : }
817 6 : return static_cast<std::string>(*this) > value;
818 : }
819 :
820 :
821 : /** \brief Compare this option's value with the specified string.
822 : *
823 : * This operator compares this option's value with the specified string.
824 : *
825 : * \param[in] value A string to compare this option's value with.
826 : *
827 : * \return true if lhs is greater than rhs.
828 : */
829 6 : bool option_info_ref::operator > (std::string const & value) const
830 : {
831 6 : return static_cast<std::string>(*this) > value;
832 : }
833 :
834 :
835 : /** \brief Compare this option's value with the value of option \p value.
836 : *
837 : * This operator compares this option's value with the value of the
838 : * option specified in \p value.
839 : *
840 : * \param[in] value A string to compare this option's value with.
841 : *
842 : * \return true if lhs is greater than rhs.
843 : */
844 10 : bool option_info_ref::operator > (option_info_ref const & value) const
845 : {
846 10 : return static_cast<std::string>(*this) > static_cast<std::string>(value);
847 : }
848 :
849 :
850 : /** \brief Compare this option's value with the specified string.
851 : *
852 : * This operator compares this option's value with the specified string.
853 : *
854 : * \param[in] value A string to compare this option's value with.
855 : *
856 : * \return true if lhs is greater or equal than rhs.
857 : */
858 8 : bool option_info_ref::operator >= (char const * value) const
859 : {
860 8 : if(value == nullptr)
861 : {
862 2 : return true;
863 : }
864 6 : return static_cast<std::string>(*this) >= value;
865 : }
866 :
867 :
868 : /** \brief Compare this option's value with the specified string.
869 : *
870 : * This operator compares this option's value with the specified string.
871 : *
872 : * \param[in] value A string to compare this option's value with.
873 : *
874 : * \return true if lhs is greater or equal than rhs.
875 : */
876 6 : bool option_info_ref::operator >= (std::string const & value) const
877 : {
878 6 : return static_cast<std::string>(*this) >= value;
879 : }
880 :
881 :
882 : /** \brief Compare this option's value with the value of option \p value.
883 : *
884 : * This operator compares this option's value with the value of the
885 : * option specified in \p value.
886 : *
887 : * \param[in] value A string to compare this option's value with.
888 : *
889 : * \return true if lhs is greater or equal than rhs.
890 : */
891 10 : bool option_info_ref::operator >= (option_info_ref const & value) const
892 : {
893 10 : return static_cast<std::string>(*this) >= static_cast<std::string>(value);
894 : }
895 :
896 :
897 :
898 : /** \brief Compare \p value with the value of the right hand-side option.
899 : *
900 : * This operator compares the specified \p value with the value of the
901 : * option specified as the \p rhs (right hand-side.)
902 : *
903 : * \param[in] value A string to compare an option's value with.
904 : * \param[in] rhs The option to compare against \p value.
905 : *
906 : * \return true if value is equal to rhs.
907 : */
908 8 : bool operator == (char const * value, option_info_ref const & rhs)
909 : {
910 8 : if(value == nullptr)
911 : {
912 2 : return rhs.empty();
913 : }
914 6 : return value == static_cast<std::string>(rhs);
915 : }
916 :
917 :
918 : /** \brief Compare \p value with the value of the right hand-side option.
919 : *
920 : * This operator compares the specified \p value with the value of the
921 : * option specified as the \p rhs (right hand-side.)
922 : *
923 : * \param[in] value A string to compare an option's value with.
924 : * \param[in] rhs The option to compare against \p value.
925 : *
926 : * \return true if value is equal to rhs.
927 : */
928 9 : bool operator == (std::string const & value, option_info_ref const & rhs)
929 : {
930 9 : return value == static_cast<std::string>(rhs);
931 : }
932 :
933 :
934 : /** \brief Compare \p value with the value of the right hand-side option.
935 : *
936 : * This operator compares the specified \p value with the value of the
937 : * option specified as the \p rhs (right hand-side.)
938 : *
939 : * \param[in] value A string to compare an option's value with.
940 : * \param[in] rhs The option to compare against \p value.
941 : *
942 : * \return true if value is not equal to rhs.
943 : */
944 8 : bool operator != (char const * value, option_info_ref const & rhs)
945 : {
946 8 : if(value == nullptr)
947 : {
948 2 : return !rhs.empty();
949 : }
950 6 : return value != static_cast<std::string>(rhs);
951 : }
952 :
953 :
954 : /** \brief Compare \p value with the value of the right hand-side option.
955 : *
956 : * This operator compares the specified \p value with the value of the
957 : * option specified as the \p rhs (right hand-side.)
958 : *
959 : * \param[in] value A string to compare an option's value with.
960 : * \param[in] rhs The option to compare against \p value.
961 : *
962 : * \return true if value is not equal to rhs.
963 : */
964 6 : bool operator != (std::string const & value, option_info_ref const & rhs)
965 : {
966 6 : return value != static_cast<std::string>(rhs);
967 : }
968 :
969 :
970 : /** \brief Compare \p value with the value of the right hand-side option.
971 : *
972 : * This operator compares the specified \p value with the value of the
973 : * option specified as the \p rhs (right hand-side.)
974 : *
975 : * \param[in] value A string to compare an option's value with.
976 : * \param[in] rhs The option to compare against \p value.
977 : *
978 : * \return true if value is considered smaller than rhs.
979 : */
980 8 : bool operator < (char const * value, option_info_ref const & rhs)
981 : {
982 8 : if(value == nullptr)
983 : {
984 2 : return !rhs.empty();
985 : }
986 6 : return value < static_cast<std::string>(rhs);
987 : }
988 :
989 :
990 : /** \brief Compare \p value with the value of the right hand-side option.
991 : *
992 : * This operator compares the specified \p value with the value of the
993 : * option specified as the \p rhs (right hand-side.)
994 : *
995 : * \param[in] value A string to compare an option's value with.
996 : * \param[in] rhs The option to compare against \p value.
997 : *
998 : * \return true if value is considered smaller than rhs.
999 : */
1000 6 : bool operator < (std::string const & value, option_info_ref const & rhs)
1001 : {
1002 6 : return value < static_cast<std::string>(rhs);
1003 : }
1004 :
1005 :
1006 : /** \brief Compare \p value with the value of the right hand-side option.
1007 : *
1008 : * This operator compares the specified \p value with the value of the
1009 : * option specified as the \p rhs (right hand-side.)
1010 : *
1011 : * \param[in] value A string to compare an option's value with.
1012 : * \param[in] rhs The option to compare against \p value.
1013 : *
1014 : * \return true if value is considered smaller or equal to rhs.
1015 : */
1016 8 : bool operator <= (char const * value, option_info_ref const & rhs)
1017 : {
1018 8 : if(value == nullptr)
1019 : {
1020 2 : return true;
1021 : }
1022 6 : return value <= static_cast<std::string>(rhs);
1023 : }
1024 :
1025 :
1026 : /** \brief Compare \p value with the value of the right hand-side option.
1027 : *
1028 : * This operator compares the specified \p value with the value of the
1029 : * option specified as the \p rhs (right hand-side.)
1030 : *
1031 : * \param[in] value A string to compare an option's value with.
1032 : * \param[in] rhs The option to compare against \p value.
1033 : *
1034 : * \return true if value is considered smaller or equal to rhs.
1035 : */
1036 6 : bool operator <= (std::string const & value, option_info_ref const & rhs)
1037 : {
1038 6 : return value <= static_cast<std::string>(rhs);
1039 : }
1040 :
1041 :
1042 : /** \brief Compare \p value with the value of the right hand-side option.
1043 : *
1044 : * This operator compares the specified \p value with the value of the
1045 : * option specified as the \p rhs (right hand-side.)
1046 : *
1047 : * \param[in] value A string to compare an option's value with.
1048 : * \param[in] rhs The option to compare against \p value.
1049 : *
1050 : * \return true if value is considered larger than rhs.
1051 : */
1052 8 : bool operator > (char const * value, option_info_ref const & rhs)
1053 : {
1054 8 : if(value == nullptr)
1055 : {
1056 2 : return false;
1057 : }
1058 6 : return value > static_cast<std::string>(rhs);
1059 : }
1060 :
1061 :
1062 : /** \brief Compare \p value with the value of the right hand-side option.
1063 : *
1064 : * This operator compares the specified \p value with the value of the
1065 : * option specified as the \p rhs (right hand-side.)
1066 : *
1067 : * \param[in] value A string to compare an option's value with.
1068 : * \param[in] rhs The option to compare against \p value.
1069 : *
1070 : * \return true if value is considered larger than rhs.
1071 : */
1072 6 : bool operator > (std::string const & value, option_info_ref const & rhs)
1073 : {
1074 6 : return value > static_cast<std::string>(rhs);
1075 : }
1076 :
1077 :
1078 : /** \brief Compare \p value with the value of the right hand-side option.
1079 : *
1080 : * This operator compares the specified \p value with the value of the
1081 : * option specified as the \p rhs (right hand-side.)
1082 : *
1083 : * \param[in] value A string to compare an option's value with.
1084 : * \param[in] rhs The option to compare against \p value.
1085 : *
1086 : * \return true if value is considered larger or equal to rhs.
1087 : */
1088 7 : bool operator >= (char const * value, option_info_ref const & rhs)
1089 : {
1090 7 : if(value == nullptr)
1091 : {
1092 2 : return rhs.empty();
1093 : }
1094 5 : return value >= static_cast<std::string>(rhs);
1095 : }
1096 :
1097 :
1098 : /** \brief Compare \p value with the value of the right hand-side option.
1099 : *
1100 : * This operator compares the specified \p value with the value of the
1101 : * option specified as the \p rhs (right hand-side.)
1102 : *
1103 : * \param[in] value A string to compare an option's value with.
1104 : * \param[in] rhs The option to compare against \p value.
1105 : *
1106 : * \return true if value is considered larger or equal to rhs.
1107 : */
1108 5 : bool operator >= (std::string const & value, option_info_ref const & rhs)
1109 : {
1110 5 : return value >= static_cast<std::string>(rhs);
1111 : }
1112 :
1113 :
1114 :
1115 : } // namespace advgetopt
1116 :
1117 :
1118 :
1119 : // vim: ts=4 sw=4 et
|