LCOV - code coverage report
Current view: top level - advgetopt - option_info_ref.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 211 211 100.0 %
Date: 2021-08-20 21:57:12 Functions: 61 61 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13