advgetopt 2.0.49
Parse complex command line arguments and configuration files in C++.
option_info.cpp
Go to the documentation of this file.
1// Copyright (c) 2006-2025 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
28// self
29//
31
32#include "advgetopt/exception.h"
35
36
37// cppthread
38//
39#include <cppthread/guard.h>
40#include <cppthread/log.h>
41#include <cppthread/mutex.h>
42
43
44// snapdev
45//
46#include <snapdev/not_used.h>
47#include <snapdev/tokenize_string.h>
48
49
50// libutf8
51//
52#include <libutf8/libutf8.h>
53#include <libutf8/iterator.h>
54
55
56// last include
57//
58#include <snapdev/poison.h>
59
60
61
62namespace advgetopt
63{
64
65
66namespace
67{
68
69
84bool g_trace_sources = false;
85
86
97std::string g_configuration_filename = std::string();
98
99
100
101} // no name namespace
102
103
104
105// from utils.cpp
106//
107// (it's here because we do not want to make cppthread public in
108// out header files--we could have an advgetopt_private.h, though)
109//
110cppthread::mutex & get_global_mutex();
111
112
113
114
128short_name_t string_to_short_name(std::string const & name)
129{
130 if(!name.empty())
131 {
132 libutf8::utf8_iterator u8(name);
133 short_name_t const short_name(*u8++);
134 if(u8 == name.end())
135 {
136 return short_name;
137 }
138 }
139
140 return NO_SHORT_NAME;
141}
142
143
163{
165 {
166 return std::string();
167 }
168 return libutf8::to_u8string(short_name);
169}
170
171
225 : f_name(option_with_dashes(name))
226 , f_short_name(short_name)
227{
228 if(f_name.empty())
229 {
231 {
232 throw getopt_logic_error(
233 "option_info::option_info(): all options must at least have a long name (short name: '"
234 + libutf8::to_u8string(short_name)
235 + "'.)");
236 }
237 throw getopt_logic_error(
238 "option_info::option_info(): all options must at least have a long name.");
239 }
240
241 if(f_name == "--")
242 {
244 {
245 throw getopt_logic_error(
246 "option_info::option_info(): the default parameter \"--\" cannot include a short name ('"
247 + libutf8::to_u8string(short_name)
248 + "'.)");
249 }
250
252 }
253 else
254 {
255 if(f_name[0] == '-')
256 {
257 throw getopt_logic_error(
258 "option_info::option_info(): an option cannot start with a dash (-), \""
259 + f_name
260 + "\" is not valid.");
261 }
262
263 if(short_name == '-')
264 {
265 throw getopt_logic_error(
266 "option_info::option_info(): the short name of an option cannot be the dash (-).");
267 }
268 }
269}
270
271
287std::string const & option_info::get_name() const
288{
289 return f_name;
290}
291
292
316
317
330
331
344std::string option_info::get_basename() const
345{
346 std::string::size_type const pos(f_name.rfind("::"));
347 if(pos == std::string::npos)
348 {
349 return f_name;
350 }
351
352 return f_name.substr(pos + 2);
353}
354
355
372{
373 std::string::size_type const pos(f_name.rfind("::"));
374 if(pos == std::string::npos)
375 {
376 return std::string();
377 }
378
379 return f_name.substr(0, pos);
380}
381
382
399{
400 std::string::size_type const pos(f_name.rfind("::"));
401 if(pos == std::string::npos)
402 {
403 return string_list_t();
404 }
405
407 snapdev::tokenize_string(section_list
408 , f_name.substr(0, pos)
409 , "::"
410 , true
411 , std::string()
412 , &snapdev::string_predicate<string_list_t>);
413 return section_list;
414}
415
416
431{
433 || (f_name.size() == 2 && f_name[0] == '-' && f_name[1] == '-');
434}
435
436
451void option_info::set_environment_variable_name(std::string const & name)
452{
454}
455
456
469{
470 if(name != nullptr)
471 {
472 set_environment_variable_name(std::string(name));
473 }
474}
475
476
497
498
514 std::string & value
515 , char const * intro) const
516{
517 // make it empty by default
518 //
519 value.clear();
520
522 {
523 return false;
524 }
525
526 std::string name(f_environment_variable_name);
527 if(intro != nullptr)
528 {
529 name = intro + name;
530 }
531
532 char const * env(getenv(name.c_str()));
533 if(env == nullptr)
534 {
535 return false;
536 }
537
538 value = env;
539
540 return true;
541}
542
543
568
569
583
584
598
599
610{
611 return f_flags;
612}
613
614
626{
627 return (f_flags & flag) != 0;
628}
629
630
651
652
679
680
693{
694 if(default_value != nullptr)
695 {
696 set_default(std::string(default_value));
697 }
698}
699
700
715
716
723std::string const & option_info::get_default() const
724{
725 return f_default_value;
726}
727
728
764void option_info::set_help(std::string const & help)
765{
766 f_help = help;
767}
768
769
777void option_info::set_help(char const * help)
778{
779 if(help != nullptr)
780 {
781 set_help(std::string(help));
782 }
783}
784
785
796std::string const & option_info::get_help() const
797{
798 return f_help;
799}
800
801
840
841
868{
870
871 // make sure that all existing values validate against this
872 // new validator
873 //
874 std::size_t const size(f_value.size());
875 bool const r(validate_all_values());
876 if(size != f_value.size())
877 {
878 value_changed(0);
879 }
880 return r;
881}
882
883
895{
896 snapdev::NOT_USED(null_ptr);
897
898 f_validator.reset();
899
900 return true;
901}
902
903
926{
927 if(static_cast<size_t>(idx) >= f_value.size())
928 {
929 throw getopt_undefined( // LCOV_EXCL_LINE
930 "option_info::validates(): no value at index " // LCOV_EXCL_LINE
931 + std::to_string(idx) // LCOV_EXCL_LINE
932 + " (idx >= " // LCOV_EXCL_LINE
933 + std::to_string(f_value.size()) // LCOV_EXCL_LINE
934 + ") for --" // LCOV_EXCL_LINE
935 + f_name // LCOV_EXCL_LINE
936 + " so you can't get this value."); // LCOV_EXCL_LINE
937 }
938
939 // the value is considered valid when:
940 // * there is no validator
941 // * if the value is empty
942 // * when the value validate against the specified validator
943 //
944 if(f_validator == nullptr
945 || f_value[idx].empty()
946 || f_validator->validate(f_value[idx]))
947 {
948 return true;
949 }
950
951 cppthread::log << cppthread::log_level_t::error
952 << "input \""
953 << f_value[idx]
954 << "\" given to parameter --"
955 << f_name
956 << " is not considered valid."
957 << cppthread::end;
958
959 // get rid of that value since it does not validate
960 //
961 f_value.erase(f_value.begin() + idx);
962 if(f_value.empty())
963 {
965 }
966
967 return false;
968}
969
970
992
993
1003{
1004 if(destination->has_flag(GETOPT_FLAG_ALIAS))
1005 {
1006 throw getopt_invalid(
1007 "option_info::set_alias(): you can't set an alias as"
1008 " an alias of another option.");
1009 }
1010
1012}
1013
1014
1025
1026
1043{
1044 f_multiple_separators.clear();
1045 if(separators == nullptr)
1046 {
1047 return;
1048 }
1049
1050 for(; *separators != nullptr; ++separators)
1051 {
1053 }
1054}
1055
1056
1075
1076
1100
1101
1115
1116
1130
1131
1148bool option_info::has_value(std::string const & value) const
1149{
1150 auto const it(std::find(f_value.begin(), f_value.end(), value));
1151 return it != f_value.end();
1152}
1153
1154
1178 std::string const & value
1179 , string_list_t const & option_keys
1180 , option_source_t source)
1181{
1182 return set_value(
1184 ? f_value.size()
1185 : 0
1186 , value
1187 , option_keys
1188 , source);
1189}
1190
1191
1225 int idx
1226 , std::string const & value
1227 , string_list_t const & option_keys
1228 , option_source_t source)
1229{
1231 {
1232 throw getopt_logic_error(
1233 "option_info::set_value(): called with SOURCE_UNDEFINED ("
1234 + std::to_string(static_cast<int>(source))
1235 + ").");
1236 }
1237
1239 {
1240 return false;
1241 }
1242
1245 {
1246 cppthread::log << cppthread::log_level_t::error
1247 << "option \"--"
1248 << f_name
1249 << "\" can't be directly updated."
1250 << cppthread::end;
1251 return false;
1252 }
1253
1255 if(multiple)
1256 {
1257 if(static_cast<size_t>(idx) > f_value.size())
1258 {
1259 throw getopt_logic_error(
1260 "option_info::set_value(): no value at index "
1261 + std::to_string(idx)
1262 + " and it is not the last available index + 1 (idx > "
1263 + std::to_string(f_value.size())
1264 + ") so you can't set this value (try add_value() maybe?).");
1265 }
1266 }
1267 else
1268 {
1269 if(idx != 0)
1270 {
1271 throw getopt_logic_error(
1272 "option_info::set_value(): single value option \"--"
1273 + f_name
1274 + "\" does not accepts index "
1275 + std::to_string(idx)
1276 + " which is not 0.");
1277 }
1278 }
1279
1280 f_source = source;
1281 f_integer.clear();
1282 f_double.clear();
1283
1284 bool r(true);
1285 if(option_keys.empty())
1286 {
1287 if(static_cast<size_t>(idx) == f_value.size())
1288 {
1289 f_value.push_back(value);
1290 }
1291 else
1292 {
1293 if(f_value[idx] == value)
1294 {
1295 // no change, we can return as is
1296 //
1297 // note: we know that the value is valid here since the
1298 // validates() function removes invalid values from
1299 // the f_value array
1300 //
1301 return true;
1302 }
1303 f_value[idx] = value;
1304 }
1305
1306 if(validates(idx))
1307 {
1309 }
1310 else
1311 {
1312 r = false;
1313 }
1314 }
1315 else
1316 {
1317 bool changed(false);
1318 bool const append(multiple && idx >= static_cast<int>(f_value.size()));
1319 for(auto const & k : option_keys)
1320 {
1321 bool new_value(true);
1322 std::string const v(k + value);
1324 if(idx == -1)
1325 {
1326 f_value.push_back(v);
1327 changed = true;
1328 }
1329 else
1330 {
1331 if(f_value[idx] == v)
1332 {
1333 new_value = false;
1334 }
1335 else
1336 {
1337 changed = true;
1338 f_value[idx] = v;
1339 }
1340 }
1341 if(new_value)
1342 {
1343 if(validates(idx))
1344 {
1346 }
1347 else
1348 {
1349 r = false;
1350 }
1351 }
1352 }
1353 if(!changed)
1354 {
1355 return true;
1356 }
1357 }
1358
1359 return r;
1360}
1361
1362
1406 std::string const & value
1407 , string_list_t const & option_keys
1408 , option_source_t source)
1409{
1411 && option_keys.size() != 0)
1412 {
1413 throw getopt_logic_error(
1414 "option_info::set_multiple_value(): parameter --"
1415 + f_name
1416 + " does not support array keys.");
1417 }
1418
1420 {
1421 throw getopt_logic_error(
1422 "option_info::set_multiple_values(): called with SOURCE_UNDEFINED ("
1423 + std::to_string(static_cast<int>(source))
1424 + ").");
1425 }
1426
1429
1431 && result.size() > 1)
1432 {
1433 throw getopt_logic_error(
1434 "option_info::set_multiple_value(): parameter --"
1435 + f_name
1436 + " expects zero or one parameter. The set_multiple_value() function should not be called with parameters that only accept one value.");
1437 }
1438
1439 if(!option_keys.empty())
1440 {
1442 for(auto const & k : option_keys)
1443 {
1444 for(auto & r : result)
1445 {
1446 // note: the keys are expected to already include the ending ':'
1447 //
1448 keyed_result.push_back(k + r);
1449 }
1450 }
1451 result.swap(keyed_result);
1452 }
1453
1454 f_source = source;
1455 f_value.swap(result);
1456 f_integer.clear();
1457 f_double.clear();
1458
1459 bool const r(validate_all_values());
1460
1461 if(f_value != result)
1462 {
1463 // TBD: should we not call this function with all instances?
1464 // i.e. for(int idx(0); idx < f_value.size(); ++idx) ...
1465 // and check each value in f_value with the old value in
1466 // the result variable (knowing that result may be smaller)
1467 //
1468 value_changed(0);
1469 }
1470
1471 return r;
1472}
1473
1474
1494{
1495 bool all_valid(true);
1496 if(f_validator != nullptr)
1497 {
1498 for(size_t idx(0); idx < f_value.size(); )
1499 {
1500 if(!validates(idx))
1501 {
1502 // the value was removed, so do not increment `idx`
1503 //
1504 all_valid = false;
1505 }
1506 else
1507 {
1508 ++idx;
1509 }
1510 }
1511 }
1512
1513 return all_valid;
1514}
1515
1516
1533{
1534 return !f_value.empty();
1535}
1536
1537
1562{
1563 return f_source;
1564}
1565
1566
1584{
1585 g_trace_sources = trace;
1586}
1587
1588
1600{
1601 return f_trace_sources;
1602}
1603
1604
1612{
1613 g_configuration_filename = filename;
1614}
1615
1616
1632size_t option_info::size() const
1633{
1634 return f_value.size();
1635}
1636
1637
1662std::string option_info::get_value(int idx, bool raw) const
1663{
1664 if(static_cast<size_t>(idx) >= f_value.size())
1665 {
1666 throw getopt_undefined(
1667 "option_info::get_value(): no value at index "
1668 + std::to_string(idx)
1669 + " (idx >= "
1670 + std::to_string(f_value.size())
1671 + ") for --"
1672 + f_name
1673 + " so you can't get this value.");
1674 }
1675
1676 if(!raw
1677 && f_variables != nullptr
1679 {
1680 return f_variables->process_value(f_value[idx]);
1681 }
1682 else
1683 {
1684 return f_value[idx];
1685 }
1686}
1687
1688
1717{
1718 if(idx < 0)
1719 {
1720 throw getopt_logic_error("idx cannot be negative in find_value_index_by_key()");
1721 }
1722 if(f_value.empty())
1723 {
1724 throw getopt_undefined(
1725 "option_info::find_value_index_by_key(): --"
1726 + f_name
1727 + " has no values defined.");
1728 }
1729
1730 if(key.back() != ':')
1731 {
1732 key += ':';
1733 }
1734 int const max(f_value.size());
1735 for(; idx < max; ++idx)
1736 {
1737 if(f_value[idx].rfind(key, 0) == 0)
1738 {
1739 return idx;
1740 }
1741 }
1742
1743 return -1;
1744}
1745
1746
1772{
1773 if(static_cast<size_t>(idx) >= f_value.size())
1774 {
1775 throw getopt_undefined(
1776 "option_info::get_long(): no value at index "
1777 + std::to_string(idx)
1778 + " (idx >= "
1779 + std::to_string(f_value.size())
1780 + ") for --"
1781 + f_name
1782 + " so you can't get this value.");
1783 }
1784
1785 // since we may change the f_integer vector between threads,
1786 // add protection (i.e. most everything else is created at the
1787 // beginning so in the main thread)
1788 //
1789 cppthread::guard lock(get_global_mutex());
1790
1791 if(f_integer.size() != f_value.size())
1792 {
1793 // we did not yet convert to integers do that now
1794 //
1795 size_t const max(f_value.size());
1796 for(size_t i(f_integer.size()); i < max; ++i)
1797 {
1798 std::int64_t v;
1800 {
1801 f_integer.clear();
1802
1803 cppthread::log << cppthread::log_level_t::error
1804 << "invalid number ("
1805 << f_value[i]
1806 << ") in parameter --"
1807 << f_name
1808 << " at offset "
1809 << i
1810 << "."
1811 << cppthread::end;
1812 return -1;
1813 }
1814 f_integer.push_back(v);
1815 }
1816 }
1817
1818 return f_integer[idx];
1819}
1820
1821
1847{
1848 if(static_cast<size_t>(idx) >= f_value.size())
1849 {
1850 throw getopt_undefined(
1851 "option_info::get_double(): no value at index "
1852 + std::to_string(idx)
1853 + " (idx >= "
1854 + std::to_string(f_value.size())
1855 + ") for --"
1856 + f_name
1857 + " so you can't get this value.");
1858 }
1859
1860 // since we may change the f_integer vector between threads,
1861 // add protection (i.e. most everything else is created at the
1862 // beginning so in the main thread)
1863 //
1864 cppthread::guard lock(get_global_mutex());
1865
1866 if(f_double.size() != f_value.size())
1867 {
1868 // we did not yet convert to doubles do that now
1869 //
1870 size_t const max(f_value.size());
1871 for(size_t i(f_double.size()); i < max; ++i)
1872 {
1873 double v;
1875 {
1876 f_double.clear();
1877
1878 cppthread::log << cppthread::log_level_t::error
1879 << "invalid number ("
1880 << f_value[i]
1881 << ") in parameter --"
1882 << f_name
1883 << " at offset "
1884 << i
1885 << "."
1886 << cppthread::end;
1887 return -1;
1888 }
1889 f_double.push_back(v);
1890 }
1891 }
1892
1893 return f_double[idx];
1894}
1895
1896
1926{
1927 if(!always)
1928 {
1929 if(!is_defined())
1930 {
1931 return;
1932 }
1933 }
1934
1936}
1937
1938
1951
1952
1962{
1963 if(is_defined())
1964 {
1966 f_value.clear();
1967 f_integer.clear();
1968 f_double.clear();
1969
1970 value_changed(0);
1971 }
1972}
1973
1974
1987{
1988 cppthread::guard lock(get_global_mutex());
1989
1991 f_callbacks.emplace_back(f_next_callback_id, c);
1992 return f_next_callback_id;
1993}
1994
1995
2006{
2007 cppthread::guard lock(get_global_mutex());
2008
2009 auto it(std::find_if(
2010 f_callbacks.begin()
2011 , f_callbacks.end()
2012 , [id](auto e)
2013 {
2014 return e.f_id == id;
2015 }));
2016 if(it != f_callbacks.end())
2017 {
2018 f_callbacks.erase(it);
2019 }
2020}
2021
2022
2039{
2041
2043 callbacks.reserve(f_callbacks.size());
2044
2045 {
2046 cppthread::guard lock(get_global_mutex());
2048 }
2049
2050 for(auto e : callbacks)
2051 {
2052 e.f_callback(*this);
2053 }
2054}
2055
2056
2057
2066{
2067 if(!g_trace_sources)
2068 {
2069 return;
2070 }
2071
2072 std::string s;
2073 switch(f_source)
2074 {
2076 s = "command-line";
2077 break;
2078
2080 s = "configuration=\"" + g_configuration_filename + "\"";
2081 break;
2082
2084 s = "direct";
2085 break;
2086
2088 s = "dynamic";
2089 break;
2090
2092 s = "environment-variable";
2093 break;
2094
2096 // this happens on a reset or all the values were invalid
2097 //
2098 f_trace_sources.push_back(f_name + " [*undefined-source*]");
2099 return;
2100
2101 }
2102
2103 if(f_value.empty())
2104 {
2105 // this should never ever happen
2106 // (if f_value is empty then f_source == SOURCE_UNDEFINED)
2107 //
2108 f_trace_sources.push_back(f_name + " [*undefined-value*]"); // LCOV_EXCL_LINE
2109 }
2110 else
2111 {
2112 // TODO: change the algorithm, if the option supports
2113 //
2115 || static_cast<std::size_t>(idx) >= f_value.size())
2116 {
2117 f_trace_sources.push_back(f_name + "=" + f_value[0] + " [" + s + "]");
2118 }
2119 else
2120 {
2121 f_trace_sources.push_back(f_name + "[" + std::to_string(idx) + "]=" + f_value[idx] + " [" + s + "]");
2122 }
2123 }
2124}
2125
2126
2127} // namespace advgetopt
2128// vim: ts=4 sw=4 et
string_list_t get_section_name_list() const
Retrieve a list of section names.
void set_flags(flag_t flags)
Get the flags.
bool validates(int idx=0)
Check a value validity.
void unlock()
Unlock this value.
void add_flag(flag_t flag)
Make sure a given flag is set.
std::string get_environment_variable_name() const
Retrieve the environment variable name of this option.
bool is_default_option() const
Check whether this is the default option.
variables::pointer_t get_variables() const
Retrieve the list of variables held by this option info.
option_source_t f_source
void remove_default()
Remove the default value.
std::vector< long > f_integer
flag_t get_flags() const
Retrieve the flags.
std::string get_value(int idx=0, bool raw=false) const
Retrieve the value.
long get_long(int idx=0) const
Get the value as a long.
string_list_t f_value
bool has_value(std::string const &value) const
Check whether one of the values matches the input.
bool set_multiple_values(std::string const &value, string_list_t const &option_keys=string_list_t(), option_source_t source=option_source_t::SOURCE_DIRECT)
Set a multi-value at once.
validator::pointer_t f_validator
std::string f_default_value
callback_vector_t f_callbacks
bool is_defined() const
Check whether a value is defined.
string_list_t const & trace_sources() const
Get the trace of this option.
callback_id_t add_callback(callback_t const &c)
Add a callback to call on a change to this value.
std::vector< callback_entry_t > callback_vector_t
void lock(bool always=true)
Lock this value.
size_t size() const
Retrieve the number of values defined for this option.
pointer_t get_alias_destination() const
Get a link to the destination alias.
void set_environment_variable_name(std::string const &name)
Set the option specific environment variable name.
std::string const & get_default() const
Retrieve the default value.
void value_changed(int idx)
Call whenever the value changed so we can handle callbacks.
std::shared_ptr< option_info > pointer_t
Definition option_info.h:78
string_list_t f_trace_sources
void set_short_name(short_name_t short_name)
Assign a short name to an option.
void reset()
Reset this value.
void trace_source(int idx)
Remember the source information at of this last change.
pointer_t f_alias_destination
void set_help(std::string const &help)
Set the help string for this option.
bool has_default() const
Check whether this option has a default value.
bool get_environment_variable_value(std::string &value, char const *intro=nullptr) const
Retrieve the environment variable value of this option.
std::string get_section_name() const
Retrieve the name of the sections.
bool validate_all_values()
Validate all the values of this option_info object.
static void set_trace_sources(bool trace)
Whether the sources should be traced.
variables::pointer_t f_variables
void set_variables(variables::pointer_t vars)
Assign variables to this option info.
option_info(std::string const &name, short_name_t short_name=NO_SHORT_NAME)
Create a new option_info object.
std::function< void(option_info const &opt)> callback_t
Definition option_info.h:82
static void set_configuration_filename(std::string const &filename)
Save the filename of the current configuration file.
string_list_t const & get_multiple_separators() const
Retrieve the list of separators for this argument.
std::string get_basename() const
Retrieve the name of the option without any section names.
bool set_validator(std::string const &name_and_params)
Set the validator for this option.
option_source_t source() const
Return the source of this option info.
std::string const & get_name() const
Get the long name of the option.
int find_value_index_by_key(std::string key, int idx=0) const
Get the index at which a value with the given key is defined.
void set_default(std::string const &default_value)
Set the default value.
short_name_t get_short_name() const
Get the short name of the option.
bool set_value(int idx, std::string const &value, string_list_t const &option_keys=string_list_t(), option_source_t source=option_source_t::SOURCE_DIRECT)
Replace a value.
double get_double(int idx=0) const
Get the value as a double.
std::string f_environment_variable_name
bool has_flag(flag_t flag) const
Check whether a flag is set.
void remove_callback(callback_id_t id)
Remove a callback.
std::string const & get_help() const
Get the help string.
string_list_t f_multiple_separators
short_name_t f_short_name
bool add_value(std::string const &value, string_list_t const &option_keys=string_list_t(), option_source_t source=option_source_t::SOURCE_DIRECT)
Add a value to this option.
void set_alias_destination(pointer_t destination)
Set the alias option.
validator::pointer_t get_validator() const
Retrieve a pointer to the validator.
void remove_flag(flag_t flag)
Make sure a given flag is not set.
void set_multiple_separators(string_list_t const &separators)
Set the list of separators.
std::vector< double > f_double
static bool convert_string(std::string const &number, double &result)
Convert a string to a double value.
static bool convert_string(std::string const &number, std::int64_t &result)
Convert a string to an std::int64_t value.
static pointer_t create(std::string const &name, string_list_t const &data)
std::shared_ptr< validator > pointer_t
Definition validator.h:64
std::shared_ptr< variables > pointer_t
Definition variables.h:61
Definitions of the advanced getopt exceptions.
std::string g_configuration_filename
The filename of the configuration being processed.
The advgetopt environment to parse command line options.
Definition version.h:37
static constexpr flag_t GETOPT_FLAG_LOCK
Definition flags.h:80
void split_string(std::string const &str, string_list_t &result, string_list_t const &separators)
Split a string in sub-strings separated by separators.
Definition utils.cpp:347
static constexpr flag_t GETOPT_FLAG_ARRAY
Definition flags.h:57
constexpr flag_t option_flags_merge()
Definition flags.h:87
static constexpr flag_t GETOPT_FLAG_DYNAMIC_CONFIGURATION
Definition flags.h:48
static constexpr flag_t GETOPT_FLAG_PROCESS_VARIABLES
Definition flags.h:56
short_name_t string_to_short_name(std::string const &name)
Transform a string to a short name.
constexpr short_name_t NO_SHORT_NAME
Definition option_info.h:51
std::uint32_t flag_t
Definition flags.h:41
cppthread::mutex & get_global_mutex()
Get a global mutex.
Definition utils.cpp:123
char32_t short_name_t
Definition option_info.h:49
static constexpr flag_t GETOPT_FLAG_DEFAULT_OPTION
Definition flags.h:54
std::string short_name_to_string(short_name_t short_name)
Convert a short name to a UTF-8 string.
static constexpr flag_t GETOPT_FLAG_HAS_DEFAULT
Definition flags.h:55
static constexpr flag_t GETOPT_FLAG_MULTIPLE
Definition flags.h:53
std::string unquote(std::string const &s, std::string const &pairs)
Remove single (') or double (") quotes from a string.
Definition utils.cpp:168
std::string option_with_dashes(std::string const &s)
Convert the _ found in a string to - instead.
Definition utils.cpp:259
std::vector< std::string > string_list_t
Definition utils.h:41
static constexpr flag_t GETOPT_FLAG_ALIAS
Definition flags.h:50
Declaration of the option_info class used to record available options.
Declaration of validators which can be used to verify the parameters.
Declaration of validators which can be used to verify the parameters.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.