LCOV - code coverage report
Current view: top level - advgetopt - option_info_ref.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 209 209 100.0 %
Date: 2019-07-15 03:11:49 Functions: 61 61 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.12