LCOV - code coverage report
Current view: top level - advgetopt - option_info_ref.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 227 227 100.0 %
Date: 2022-07-15 17:40:56 Functions: 62 62 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2006-2022  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         507 : option_info_ref::operator std::string () const
     227             : {
     228         507 :     if(f_opt->is_defined())
     229             :     {
     230         342 :         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          10 :     std::string v;
     251           5 :     if(value != '\0')
     252             :     {
     253           3 :         v += value;
     254             :     }
     255           5 :     f_opt->set_value(0, v, option_source_t::SOURCE_DIRECT);
     256          10 :     return *this;
     257             : }
     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           8 :     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, option_source_t::SOURCE_DIRECT);
     279           8 :     return *this;
     280             : }
     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(), option_source_t::SOURCE_DIRECT);
     297             :     }
     298             :     else
     299             :     {
     300           4 :         f_opt->set_value(0, value, option_source_t::SOURCE_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, option_source_t::SOURCE_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, option_source_t::SOURCE_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          16 :     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, option_source_t::SOURCE_DIRECT);
     359          16 :     return *this;
     360             : }
     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          12 :     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, option_source_t::SOURCE_DIRECT);
     380          12 :     return *this;
     381             : }
     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          14 :     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, option_source_t::SOURCE_DIRECT);
     401          14 :     return *this;
     402             : }
     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, option_source_t::SOURCE_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          12 :     f_opt->set_value(
     433             :               0
     434          12 :             , static_cast<std::string>(*this) + static_cast<std::string>(value)
     435             :             , option_source_t::SOURCE_DIRECT);
     436           6 :     return *this;
     437             : }
     438             : 
     439             : 
     440             : /** \brief Append the character \p value to this option's value.
     441             :  *
     442             :  * This operator is used to append a character to the value of the option
     443             :  * and returns the result as a string.
     444             :  *
     445             :  * \note
     446             :  * This version appends an ISO-8859-1 character. Make sure to use a
     447             :  * char32_t character to add a Unicode character.
     448             :  *
     449             :  * \param[in] value  The character to append to the option_info's value.
     450             :  *
     451             :  * \return A string with the resulting concatenation.
     452             :  */
     453          10 : std::string option_info_ref::operator + (char value) const
     454             : {
     455          10 :     if(value == '\0')
     456             :     {
     457           5 :         return *this;
     458             :     }
     459           5 :     return static_cast<std::string>(*this) + value;
     460             : }
     461             : 
     462             : 
     463             : /** \brief Append the character \p value to this option's value.
     464             :  *
     465             :  * This operator is used to append a Unicode character to the value of the
     466             :  * option and returns the result as a string.
     467             :  *
     468             :  * \param[in] value  The character to append to the option_info's value.
     469             :  *
     470             :  * \return A string with the resulting concatenation.
     471             :  */
     472          12 : std::string option_info_ref::operator + (char32_t value) const
     473             : {
     474          12 :     if(value == U'\0')
     475             :     {
     476           6 :         return *this;
     477             :     }
     478           6 :     return static_cast<std::string>(*this) + libutf8::to_u8string(value);
     479             : }
     480             : 
     481             : 
     482             : /** \brief Append \p value to this option's value.
     483             :  *
     484             :  * This operator is used to append a string to the value of the option
     485             :  * and return the result as a string.
     486             :  *
     487             :  * \param[in] value  The string to append to the option_info's value.
     488             :  *
     489             :  * \return A string with the resulting concatenation.
     490             :  */
     491           8 : std::string option_info_ref::operator + (char const * value) const
     492             : {
     493           8 :     if(value == nullptr)
     494             :     {
     495           2 :         return *this;
     496             :     }
     497           6 :     return static_cast<std::string>(*this) + value;
     498             : }
     499             : 
     500             : 
     501             : /** \brief Append \p value to this option's value.
     502             :  *
     503             :  * This operator is used to append a string to the value of the option
     504             :  * and return the result as a string.
     505             :  *
     506             :  * \param[in] value  The value to append to the option_info's value.
     507             :  *
     508             :  * \return A string with the resulting concatenation.
     509             :  */
     510           5 : std::string option_info_ref::operator + (std::string const & value) const
     511             : {
     512           5 :     return static_cast<std::string>(*this) + value;
     513             : }
     514             : 
     515             : 
     516             : /** \brief Append the value of this \p value option to this option_info's value.
     517             :  *
     518             :  * This operator is used to append two option references to each others and
     519             :  * return the concatenated string as the result.
     520             :  *
     521             :  * \param[in] value  The other option to read the value from.
     522             :  *
     523             :  * \return A reference to this object_info_ref.
     524             :  */
     525          10 : std::string option_info_ref::operator + (option_info_ref const & value) const
     526             : {
     527          20 :     return static_cast<std::string>(*this)
     528          30 :          + static_cast<std::string>(value);
     529             : }
     530             : 
     531             : 
     532             : /** \brief Concatenate a character and an option reference value.
     533             :  *
     534             :  * This operator concatenates the \p value ISO-8859-1 character to the front
     535             :  * of the \p rhs reference.
     536             :  *
     537             :  * \param[in] value  A character to add to the left of the referred value.
     538             :  * \param[in] rhs  The referred value.
     539             :  *
     540             :  * \return The concatenated result.
     541             :  */
     542          13 : std::string operator + (char value, option_info_ref const & rhs)
     543             : {
     544          13 :     if(value == '\0')
     545             :     {
     546           6 :         return rhs;
     547             :     }
     548           7 :     return value + static_cast<std::string>(rhs);
     549             : }
     550             : 
     551             : 
     552             : /** \brief Concatenate a character and an option reference value.
     553             :  *
     554             :  * This operator concatenates the \p value Unicode character to the front
     555             :  * of the \p rhs reference.
     556             :  *
     557             :  * \param[in] value  A character to add to the left of the referred value.
     558             :  * \param[in] rhs  The referred value.
     559             :  *
     560             :  * \return The concatenated result.
     561             :  */
     562          12 : std::string operator + (char32_t value, option_info_ref const & rhs)
     563             : {
     564          12 :     if(value == U'\0')
     565             :     {
     566           7 :         return rhs;
     567             :     }
     568           5 :     return libutf8::to_u8string(value) + static_cast<std::string>(rhs);
     569             : }
     570             : 
     571             : 
     572             : /** \brief Concatenate a string and an option reference value.
     573             :  *
     574             :  * This operator concatenates the \p value string to the front
     575             :  * of the \p rhs reference.
     576             :  *
     577             :  * \param[in] value  A character to add to the left of the referred value.
     578             :  * \param[in] rhs  The referred value.
     579             :  *
     580             :  * \return The concatenated result.
     581             :  */
     582           5 : std::string operator + (char const * value, option_info_ref const & rhs)
     583             : {
     584           5 :     if(value == nullptr)
     585             :     {
     586           2 :         return rhs;
     587             :     }
     588           3 :     return value + static_cast<std::string>(rhs);
     589             : }
     590             : 
     591             : 
     592             : /** \brief Concatenate a string and an option reference value.
     593             :  *
     594             :  * This operator concatenates the \p value string to the front
     595             :  * of the \p rhs reference.
     596             :  *
     597             :  * \param[in] value  A character to add to the left of the referred value.
     598             :  * \param[in] rhs  The referred value.
     599             :  *
     600             :  * \return The concatenated result.
     601             :  */
     602           3 : std::string operator + (std::string const & value, option_info_ref const & rhs)
     603             : {
     604           3 :     return value + static_cast<std::string>(rhs);
     605             : }
     606             : 
     607             : 
     608             : /** \brief Check whether the value is an empty string or not.
     609             :  *
     610             :  * This function calls the empty function and returns the opposite result.
     611             :  *
     612             :  * \return true if the value is not an empty string.
     613             :  */
     614           2 : option_info_ref::operator bool () const
     615             : {
     616           2 :     return !empty();
     617             : }
     618             : 
     619             : 
     620             : /** \brief Check whether the value is an empty string or not.
     621             :  *
     622             :  * This function calls the empty function and returns the result.
     623             :  *
     624             :  * \return true if the value is an empty string.
     625             :  */
     626           2 : bool option_info_ref::operator ! () const
     627             : {
     628           2 :     return empty();
     629             : }
     630             : 
     631             : 
     632             : /** \brief Compare this option's value with the specified string.
     633             :  *
     634             :  * This operator compares this option's value with the specified string.
     635             :  *
     636             :  * \param[in] value  A string to compare this option's value with.
     637             :  *
     638             :  * \return true if both are equal.
     639             :  */
     640          67 : bool option_info_ref::operator == (char const * value) const
     641             : {
     642          67 :     if(value == nullptr)
     643             :     {
     644           2 :         return empty();
     645             :     }
     646          65 :     return static_cast<std::string>(*this) == value;
     647             : }
     648             : 
     649             : 
     650             : /** \brief Compare this option's value with the specified string.
     651             :  *
     652             :  * This operator compares this option's value with the specified string.
     653             :  *
     654             :  * \param[in] value  A string to compare this option's value with.
     655             :  *
     656             :  * \return true if both are equal.
     657             :  */
     658          45 : bool option_info_ref::operator == (std::string const & value) const
     659             : {
     660          45 :     return static_cast<std::string>(*this) == value;
     661             : }
     662             : 
     663             : 
     664             : /** \brief Compare this option's value with the value of option \p value.
     665             :  *
     666             :  * This operator compares this option's value with the value of the
     667             :  * option specified in \p value.
     668             :  *
     669             :  * \param[in] value  A string to compare this option's value with.
     670             :  *
     671             :  * \return true if both are equal.
     672             :  */
     673          15 : bool option_info_ref::operator == (option_info_ref const & value) const
     674             : {
     675          15 :     return static_cast<std::string>(*this) == static_cast<std::string>(value);
     676             : }
     677             : 
     678             : 
     679             : /** \brief Compare this option's value with the specified string.
     680             :  *
     681             :  * This operator compares this option's value with the specified string.
     682             :  *
     683             :  * \param[in] value  A string to compare this option's value with.
     684             :  *
     685             :  * \return true if both are not equal.
     686             :  */
     687           8 : bool option_info_ref::operator != (char const * value) const
     688             : {
     689           8 :     if(value == nullptr)
     690             :     {
     691           2 :         return !empty();
     692             :     }
     693           6 :     return static_cast<std::string>(*this) != value;
     694             : }
     695             : 
     696             : 
     697             : /** \brief Compare this option's value with the specified string.
     698             :  *
     699             :  * This operator compares this option's value with the specified string.
     700             :  *
     701             :  * \param[in] value  A string to compare this option's value with.
     702             :  *
     703             :  * \return true if both are not equal.
     704             :  */
     705           6 : bool option_info_ref::operator != (std::string const & value) const
     706             : {
     707           6 :     return static_cast<std::string>(*this) != value;
     708             : }
     709             : 
     710             : 
     711             : /** \brief Compare this option's value with the value of option \p value.
     712             :  *
     713             :  * This operator compares this option's value with the value of the
     714             :  * option specified in \p value.
     715             :  *
     716             :  * \param[in] value  A string to compare this option's value with.
     717             :  *
     718             :  * \return true if both are not equal.
     719             :  */
     720          10 : bool option_info_ref::operator != (option_info_ref const & value) const
     721             : {
     722          10 :     return static_cast<std::string>(*this) != static_cast<std::string>(value);
     723             : }
     724             : 
     725             : 
     726             : /** \brief Compare this option's value with the specified string.
     727             :  *
     728             :  * This operator compares this option's value with the specified string.
     729             :  *
     730             :  * \param[in] value  A string to compare this option's value with.
     731             :  *
     732             :  * \return true if lhs is less than rhs.
     733             :  */
     734           8 : bool option_info_ref::operator < (char const * value) const
     735             : {
     736           8 :     if(value == nullptr)
     737             :     {
     738           2 :         return false;
     739             :     }
     740           6 :     return static_cast<std::string>(*this) < value;
     741             : }
     742             : 
     743             : 
     744             : /** \brief Compare this option's value with the specified string.
     745             :  *
     746             :  * This operator compares this option's value with the specified string.
     747             :  *
     748             :  * \param[in] value  A string to compare this option's value with.
     749             :  *
     750             :  * \return true if lhs is less than rhs.
     751             :  */
     752           6 : bool option_info_ref::operator < (std::string const & value) const
     753             : {
     754           6 :     return static_cast<std::string>(*this) < value;
     755             : }
     756             : 
     757             : 
     758             : /** \brief Compare this option's value with the value of option \p value.
     759             :  *
     760             :  * This operator compares this option's value with the value of the
     761             :  * option specified in \p value.
     762             :  *
     763             :  * \param[in] value  A string to compare this option's value with.
     764             :  *
     765             :  * \return true if lhs is less than rhs.
     766             :  */
     767          10 : bool option_info_ref::operator < (option_info_ref const & value) const
     768             : {
     769          10 :     return static_cast<std::string>(*this) < static_cast<std::string>(value);
     770             : }
     771             : 
     772             : 
     773             : /** \brief Compare this option's value with the specified string.
     774             :  *
     775             :  * This operator compares this option's value with the specified string.
     776             :  *
     777             :  * \param[in] value  A string to compare this option's value with.
     778             :  *
     779             :  * \return true if lhs is less or equal than rhs.
     780             :  */
     781           8 : bool option_info_ref::operator <= (char const * value) const
     782             : {
     783           8 :     if(value == nullptr)
     784             :     {
     785           2 :         return empty();
     786             :     }
     787           6 :     return static_cast<std::string>(*this) <= value;
     788             : }
     789             : 
     790             : 
     791             : /** \brief Compare this option's value with the specified string.
     792             :  *
     793             :  * This operator compares this option's value with the specified string.
     794             :  *
     795             :  * \param[in] value  A string to compare this option's value with.
     796             :  *
     797             :  * \return true if lhs is less or equal than rhs.
     798             :  */
     799           6 : bool option_info_ref::operator <= (std::string const & value) const
     800             : {
     801           6 :     return static_cast<std::string>(*this) <= value;
     802             : }
     803             : 
     804             : 
     805             : /** \brief Compare this option's value with the value of option \p value.
     806             :  *
     807             :  * This operator compares this option's value with the value of the
     808             :  * option specified in \p value.
     809             :  *
     810             :  * \param[in] value  A string to compare this option's value with.
     811             :  *
     812             :  * \return true if lhs is less or equal than rhs.
     813             :  */
     814          10 : bool option_info_ref::operator <= (option_info_ref const & value) const
     815             : {
     816          10 :     return static_cast<std::string>(*this) <= static_cast<std::string>(value);
     817             : }
     818             : 
     819             : 
     820             : /** \brief Compare this option's value with the specified string.
     821             :  *
     822             :  * This operator compares this option's value with the specified string.
     823             :  *
     824             :  * \param[in] value  A string to compare this option's value with.
     825             :  *
     826             :  * \return true if lhs is greater than rhs.
     827             :  */
     828           8 : bool option_info_ref::operator > (char const * value) const
     829             : {
     830           8 :     if(value == nullptr)
     831             :     {
     832           2 :         return !empty();
     833             :     }
     834           6 :     return static_cast<std::string>(*this) > value;
     835             : }
     836             : 
     837             : 
     838             : /** \brief Compare this option's value with the specified string.
     839             :  *
     840             :  * This operator compares this option's value with the specified string.
     841             :  *
     842             :  * \param[in] value  A string to compare this option's value with.
     843             :  *
     844             :  * \return true if lhs is greater than rhs.
     845             :  */
     846           6 : bool option_info_ref::operator > (std::string const & value) const
     847             : {
     848           6 :     return static_cast<std::string>(*this) > value;
     849             : }
     850             : 
     851             : 
     852             : /** \brief Compare this option's value with the value of option \p value.
     853             :  *
     854             :  * This operator compares this option's value with the value of the
     855             :  * option specified in \p value.
     856             :  *
     857             :  * \param[in] value  A string to compare this option's value with.
     858             :  *
     859             :  * \return true if lhs is greater than rhs.
     860             :  */
     861          10 : bool option_info_ref::operator > (option_info_ref const & value) const
     862             : {
     863          10 :     return static_cast<std::string>(*this) > static_cast<std::string>(value);
     864             : }
     865             : 
     866             : 
     867             : /** \brief Compare this option's value with the specified string.
     868             :  *
     869             :  * This operator compares this option's value with the specified string.
     870             :  *
     871             :  * \param[in] value  A string to compare this option's value with.
     872             :  *
     873             :  * \return true if lhs is greater or equal than rhs.
     874             :  */
     875           8 : bool option_info_ref::operator >= (char const * value) const
     876             : {
     877           8 :     if(value == nullptr)
     878             :     {
     879           2 :         return true;
     880             :     }
     881           6 :     return static_cast<std::string>(*this) >= value;
     882             : }
     883             : 
     884             : 
     885             : /** \brief Compare this option's value with the specified string.
     886             :  *
     887             :  * This operator compares this option's value with the specified string.
     888             :  *
     889             :  * \param[in] value  A string to compare this option's value with.
     890             :  *
     891             :  * \return true if lhs is greater or equal than rhs.
     892             :  */
     893           6 : bool option_info_ref::operator >= (std::string const & value) const
     894             : {
     895           6 :     return static_cast<std::string>(*this) >= value;
     896             : }
     897             : 
     898             : 
     899             : /** \brief Compare this option's value with the value of option \p value.
     900             :  *
     901             :  * This operator compares this option's value with the value of the
     902             :  * option specified in \p value.
     903             :  *
     904             :  * \param[in] value  A string to compare this option's value with.
     905             :  *
     906             :  * \return true if lhs is greater or equal than rhs.
     907             :  */
     908          10 : bool option_info_ref::operator >= (option_info_ref const & value) const
     909             : {
     910          10 :     return static_cast<std::string>(*this) >= static_cast<std::string>(value);
     911             : }
     912             : 
     913             : 
     914             : 
     915             : /** \brief Compare \p value with the value of the right hand-side option.
     916             :  *
     917             :  * This operator compares the specified \p value with the value of the
     918             :  * option specified as the \p rhs (right hand-side.)
     919             :  *
     920             :  * \param[in] value  A string to compare an option's value with.
     921             :  * \param[in] rhs  The option to compare against \p value.
     922             :  *
     923             :  * \return true if value is equal to rhs.
     924             :  */
     925           8 : bool operator == (char const * value, option_info_ref const & rhs)
     926             : {
     927           8 :     if(value == nullptr)
     928             :     {
     929           2 :         return rhs.empty();
     930             :     }
     931           6 :     return value == static_cast<std::string>(rhs);
     932             : }
     933             : 
     934             : 
     935             : /** \brief Compare \p value with the value of the right hand-side option.
     936             :  *
     937             :  * This operator compares the specified \p value with the value of the
     938             :  * option specified as the \p rhs (right hand-side.)
     939             :  *
     940             :  * \param[in] value  A string to compare an option's value with.
     941             :  * \param[in] rhs  The option to compare against \p value.
     942             :  *
     943             :  * \return true if value is equal to rhs.
     944             :  */
     945          11 : bool operator == (std::string const & value, option_info_ref const & rhs)
     946             : {
     947          11 :     return value == static_cast<std::string>(rhs);
     948             : }
     949             : 
     950             : 
     951             : /** \brief Compare \p value with the value of the right hand-side option.
     952             :  *
     953             :  * This operator compares the specified \p value with the value of the
     954             :  * option specified as the \p rhs (right hand-side.)
     955             :  *
     956             :  * \param[in] value  A string to compare an option's value with.
     957             :  * \param[in] rhs  The option to compare against \p value.
     958             :  *
     959             :  * \return true if value is not equal to rhs.
     960             :  */
     961           8 : bool operator != (char const * value, option_info_ref const & rhs)
     962             : {
     963           8 :     if(value == nullptr)
     964             :     {
     965           2 :         return !rhs.empty();
     966             :     }
     967           6 :     return value != static_cast<std::string>(rhs);
     968             : }
     969             : 
     970             : 
     971             : /** \brief Compare \p value with the value of the right hand-side option.
     972             :  *
     973             :  * This operator compares the specified \p value with the value of the
     974             :  * option specified as the \p rhs (right hand-side.)
     975             :  *
     976             :  * \param[in] value  A string to compare an option's value with.
     977             :  * \param[in] rhs  The option to compare against \p value.
     978             :  *
     979             :  * \return true if value is not equal to rhs.
     980             :  */
     981           6 : bool operator != (std::string const & value, option_info_ref const & rhs)
     982             : {
     983           6 :     return value != static_cast<std::string>(rhs);
     984             : }
     985             : 
     986             : 
     987             : /** \brief Compare \p value with the value of the right hand-side option.
     988             :  *
     989             :  * This operator compares the specified \p value with the value of the
     990             :  * option specified as the \p rhs (right hand-side.)
     991             :  *
     992             :  * \param[in] value  A string to compare an option's value with.
     993             :  * \param[in] rhs  The option to compare against \p value.
     994             :  *
     995             :  * \return true if value is considered smaller than rhs.
     996             :  */
     997           8 : bool operator < (char const * value, option_info_ref const & rhs)
     998             : {
     999           8 :     if(value == nullptr)
    1000             :     {
    1001           2 :         return !rhs.empty();
    1002             :     }
    1003           6 :     return value < static_cast<std::string>(rhs);
    1004             : }
    1005             : 
    1006             : 
    1007             : /** \brief Compare \p value with the value of the right hand-side option.
    1008             :  *
    1009             :  * This operator compares the specified \p value with the value of the
    1010             :  * option specified as the \p rhs (right hand-side.)
    1011             :  *
    1012             :  * \param[in] value  A string to compare an option's value with.
    1013             :  * \param[in] rhs  The option to compare against \p value.
    1014             :  *
    1015             :  * \return true if value is considered smaller than rhs.
    1016             :  */
    1017           6 : bool operator < (std::string const & value, option_info_ref const & rhs)
    1018             : {
    1019           6 :     return value < static_cast<std::string>(rhs);
    1020             : }
    1021             : 
    1022             : 
    1023             : /** \brief Compare \p value with the value of the right hand-side option.
    1024             :  *
    1025             :  * This operator compares the specified \p value with the value of the
    1026             :  * option specified as the \p rhs (right hand-side.)
    1027             :  *
    1028             :  * \param[in] value  A string to compare an option's value with.
    1029             :  * \param[in] rhs  The option to compare against \p value.
    1030             :  *
    1031             :  * \return true if value is considered smaller or equal to rhs.
    1032             :  */
    1033           8 : bool operator <= (char const * value, option_info_ref const & rhs)
    1034             : {
    1035           8 :     if(value == nullptr)
    1036             :     {
    1037           2 :         return true;
    1038             :     }
    1039           6 :     return value <= static_cast<std::string>(rhs);
    1040             : }
    1041             : 
    1042             : 
    1043             : /** \brief Compare \p value with the value of the right hand-side option.
    1044             :  *
    1045             :  * This operator compares the specified \p value with the value of the
    1046             :  * option specified as the \p rhs (right hand-side.)
    1047             :  *
    1048             :  * \param[in] value  A string to compare an option's value with.
    1049             :  * \param[in] rhs  The option to compare against \p value.
    1050             :  *
    1051             :  * \return true if value is considered smaller or equal to rhs.
    1052             :  */
    1053           6 : bool operator <= (std::string const & value, option_info_ref const & rhs)
    1054             : {
    1055           6 :     return value <= static_cast<std::string>(rhs);
    1056             : }
    1057             : 
    1058             : 
    1059             : /** \brief Compare \p value with the value of the right hand-side option.
    1060             :  *
    1061             :  * This operator compares the specified \p value with the value of the
    1062             :  * option specified as the \p rhs (right hand-side.)
    1063             :  *
    1064             :  * \param[in] value  A string to compare an option's value with.
    1065             :  * \param[in] rhs  The option to compare against \p value.
    1066             :  *
    1067             :  * \return true if value is considered larger than rhs.
    1068             :  */
    1069           8 : bool operator > (char const * value, option_info_ref const & rhs)
    1070             : {
    1071           8 :     if(value == nullptr)
    1072             :     {
    1073           2 :         return false;
    1074             :     }
    1075           6 :     return value > static_cast<std::string>(rhs);
    1076             : }
    1077             : 
    1078             : 
    1079             : /** \brief Compare \p value with the value of the right hand-side option.
    1080             :  *
    1081             :  * This operator compares the specified \p value with the value of the
    1082             :  * option specified as the \p rhs (right hand-side.)
    1083             :  *
    1084             :  * \param[in] value  A string to compare an option's value with.
    1085             :  * \param[in] rhs  The option to compare against \p value.
    1086             :  *
    1087             :  * \return true if value is considered larger than rhs.
    1088             :  */
    1089           6 : bool operator > (std::string const & value, option_info_ref const & rhs)
    1090             : {
    1091           6 :     return value > static_cast<std::string>(rhs);
    1092             : }
    1093             : 
    1094             : 
    1095             : /** \brief Compare \p value with the value of the right hand-side option.
    1096             :  *
    1097             :  * This operator compares the specified \p value with the value of the
    1098             :  * option specified as the \p rhs (right hand-side.)
    1099             :  *
    1100             :  * \param[in] value  A string to compare an option's value with.
    1101             :  * \param[in] rhs  The option to compare against \p value.
    1102             :  *
    1103             :  * \return true if value is considered larger or equal to rhs.
    1104             :  */
    1105           7 : bool operator >= (char const * value, option_info_ref const & rhs)
    1106             : {
    1107           7 :     if(value == nullptr)
    1108             :     {
    1109           2 :         return rhs.empty();
    1110             :     }
    1111           5 :     return value >= static_cast<std::string>(rhs);
    1112             : }
    1113             : 
    1114             : 
    1115             : /** \brief Compare \p value with the value of the right hand-side option.
    1116             :  *
    1117             :  * This operator compares the specified \p value with the value of the
    1118             :  * option specified as the \p rhs (right hand-side.)
    1119             :  *
    1120             :  * \param[in] value  A string to compare an option's value with.
    1121             :  * \param[in] rhs  The option to compare against \p value.
    1122             :  *
    1123             :  * \return true if value is considered larger or equal to rhs.
    1124             :  */
    1125           5 : bool operator >= (std::string const & value, option_info_ref const & rhs)
    1126             : {
    1127           5 :     return value >= static_cast<std::string>(rhs);
    1128             : }
    1129             : 
    1130             : 
    1131             : 
    1132             : }   // namespace advgetopt
    1133             : 
    1134             : 
    1135             : 
    1136           2 : std::string operator + (char32_t value, std::string const & rhs)
    1137             : {
    1138           4 :     std::string v;
    1139           2 :     if(value != U'\0')
    1140             :     {
    1141           1 :         v = libutf8::to_u8string(value);
    1142             :     }
    1143           4 :     return v + rhs;
    1144             : }
    1145             : 
    1146           4 : std::string operator + (std::string const & lhs, char32_t value)
    1147             : {
    1148           8 :     std::string v;
    1149           4 :     if(value != U'\0')
    1150             :     {
    1151           1 :         v = libutf8::to_u8string(value);
    1152             :     }
    1153           8 :     return lhs + v;
    1154           6 : }
    1155             : 
    1156             : 
    1157             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13