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

Generated by: LCOV version 1.13