advgetopt 2.0.47
Parse complex command line arguments and configuration files in C++.
option_info.cpp
Go to the documentation of this file.
1// Copyright (c) 2006-2024 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
468{
469 if(name != nullptr)
470 {
471 set_environment_variable_name(std::string(name));
472 }
473}
474
475
496
497
513 std::string & value
514 , char const * intro) const
515{
516 // make it empty by default
517 //
518 value.clear();
519
521 {
522 return false;
523 }
524
525 std::string name(f_environment_variable_name);
526 if(intro != nullptr)
527 {
528 name = intro + name;
529 }
530
531 char const * env(getenv(name.c_str()));
532 if(env == nullptr)
533 {
534 return false;
535 }
536
537 value = env;
538
539 return true;
540}
541
542
567
568
582
583
597
598
609{
610 return f_flags;
611}
612
613
625{
626 return (f_flags & flag) != 0;
627}
628
629
650
651
678
679
692{
693 if(default_value != nullptr)
694 {
695 set_default(std::string(default_value));
696 }
697}
698
699
714
715
722std::string const & option_info::get_default() const
723{
724 return f_default_value;
725}
726
727
763void option_info::set_help(std::string const & help)
764{
765 f_help = help;
766}
767
768
776void option_info::set_help(char const * help)
777{
778 if(help != nullptr)
779 {
780 set_help(std::string(help));
781 }
782}
783
784
795std::string const & option_info::get_help() const
796{
797 return f_help;
798}
799
800
839
840
867{
869
870 // make sure that all existing values validate against this
871 // new validator
872 //
873 std::size_t const size(f_value.size());
874 bool const r(validate_all_values());
875 if(size != f_value.size())
876 {
877 value_changed(0);
878 }
879 return r;
880}
881
882
894{
895 snapdev::NOT_USED(null_ptr);
896
897 f_validator.reset();
898
899 return true;
900}
901
902
925{
926 if(static_cast<size_t>(idx) >= f_value.size())
927 {
928 throw getopt_undefined( // LCOV_EXCL_LINE
929 "option_info::validates(): no value at index " // LCOV_EXCL_LINE
930 + std::to_string(idx) // LCOV_EXCL_LINE
931 + " (idx >= " // LCOV_EXCL_LINE
932 + std::to_string(f_value.size()) // LCOV_EXCL_LINE
933 + ") for --" // LCOV_EXCL_LINE
934 + f_name // LCOV_EXCL_LINE
935 + " so you can't get this value."); // LCOV_EXCL_LINE
936 }
937
938 // the value is considered valid when:
939 // * there is no validator
940 // * if the value is empty
941 // * when the value validate against the specified validator
942 //
943 if(f_validator == nullptr
944 || f_value[idx].empty()
945 || f_validator->validate(f_value[idx]))
946 {
947 return true;
948 }
949
950 cppthread::log << cppthread::log_level_t::error
951 << "input \""
952 << f_value[idx]
953 << "\" given to parameter --"
954 << f_name
955 << " is not considered valid."
956 << cppthread::end;
957
958 // get rid of that value since it does not validate
959 //
960 f_value.erase(f_value.begin() + idx);
961 if(f_value.empty())
962 {
964 }
965
966 return false;
967}
968
969
991
992
1002{
1003 if(destination->has_flag(GETOPT_FLAG_ALIAS))
1004 {
1005 throw getopt_invalid(
1006 "option_info::set_alias(): you can't set an alias as"
1007 " an alias of another option.");
1008 }
1009
1011}
1012
1013
1024
1025
1042{
1043 f_multiple_separators.clear();
1044 if(separators == nullptr)
1045 {
1046 return;
1047 }
1048
1049 for(; *separators != nullptr; ++separators)
1050 {
1052 }
1053}
1054
1055
1074
1075
1099
1100
1114
1115
1129
1130
1147bool option_info::has_value(std::string const & value) const
1148{
1149 auto const it(std::find(f_value.begin(), f_value.end(), value));
1150 return it != f_value.end();
1151}
1152
1153
1177 std::string const & value
1178 , string_list_t const & option_keys
1179 , option_source_t source)
1180{
1181 return set_value(
1183 ? f_value.size()
1184 : 0
1185 , value
1186 , option_keys
1187 , source);
1188}
1189
1190
1224 int idx
1225 , std::string const & value
1226 , string_list_t const & option_keys
1227 , option_source_t source)
1228{
1230 {
1231 throw getopt_logic_error(
1232 "option_info::set_value(): called with SOURCE_UNDEFINED ("
1233 + std::to_string(static_cast<int>(source))
1234 + ").");
1235 }
1236
1238 {
1239 return false;
1240 }
1241
1244 {
1245 cppthread::log << cppthread::log_level_t::error
1246 << "option \"--"
1247 << f_name
1248 << "\" can't be directly updated."
1249 << cppthread::end;
1250 return false;
1251 }
1252
1254 if(multiple)
1255 {
1256 if(static_cast<size_t>(idx) > f_value.size())
1257 {
1258 throw getopt_logic_error(
1259 "option_info::set_value(): no value at index "
1260 + std::to_string(idx)
1261 + " and it is not the last available index + 1 (idx > "
1262 + std::to_string(f_value.size())
1263 + ") so you can't set this value (try add_value() maybe?).");
1264 }
1265 }
1266 else
1267 {
1268 if(idx != 0)
1269 {
1270 throw getopt_logic_error(
1271 "option_info::set_value(): single value option \"--"
1272 + f_name
1273 + "\" does not accepts index "
1274 + std::to_string(idx)
1275 + " which is not 0.");
1276 }
1277 }
1278
1279 f_source = source;
1280 f_integer.clear();
1281 f_double.clear();
1282
1283 bool r(true);
1284 if(option_keys.empty())
1285 {
1286 if(static_cast<size_t>(idx) == f_value.size())
1287 {
1288 f_value.push_back(value);
1289 }
1290 else
1291 {
1292 if(f_value[idx] == value)
1293 {
1294 // no change, we can return as is
1295 //
1296 // note: we know that the value is valid here since the
1297 // validates() function removes invalid values from
1298 // the f_value array
1299 //
1300 return true;
1301 }
1302 f_value[idx] = value;
1303 }
1304
1305 if(validates(idx))
1306 {
1308 }
1309 else
1310 {
1311 r = false;
1312 }
1313 }
1314 else
1315 {
1316 bool changed(false);
1317 bool const append(multiple && idx >= static_cast<int>(f_value.size()));
1318 for(auto const & k : option_keys)
1319 {
1320 bool new_value(true);
1321 std::string const v(k + value);
1323 if(idx == -1)
1324 {
1325 f_value.push_back(v);
1326 changed = true;
1327 }
1328 else
1329 {
1330 if(f_value[idx] == v)
1331 {
1332 new_value = false;
1333 }
1334 else
1335 {
1336 changed = true;
1337 f_value[idx] = v;
1338 }
1339 }
1340 if(new_value)
1341 {
1342 if(validates(idx))
1343 {
1345 }
1346 else
1347 {
1348 r = false;
1349 }
1350 }
1351 }
1352 if(!changed)
1353 {
1354 return true;
1355 }
1356 }
1357
1358 return r;
1359}
1360
1361
1405 std::string const & value
1406 , string_list_t const & option_keys
1407 , option_source_t source)
1408{
1410 && option_keys.size() != 0)
1411 {
1412 throw getopt_logic_error(
1413 "option_info::set_multiple_value(): parameter --"
1414 + f_name
1415 + " does not support array keys.");
1416 }
1417
1419 {
1420 throw getopt_logic_error(
1421 "option_info::set_multiple_values(): called with SOURCE_UNDEFINED ("
1422 + std::to_string(static_cast<int>(source))
1423 + ").");
1424 }
1425
1428
1430 && result.size() > 1)
1431 {
1432 throw getopt_logic_error(
1433 "option_info::set_multiple_value(): parameter --"
1434 + f_name
1435 + " expects zero or one parameter. The set_multiple_value() function should not be called with parameters that only accept one value.");
1436 }
1437
1438 if(!option_keys.empty())
1439 {
1441 for(auto const & k : option_keys)
1442 {
1443 for(auto & r : result)
1444 {
1445 // note: the keys are expected to already include the ending ':'
1446 //
1447 keyed_result.push_back(k + r);
1448 }
1449 }
1450 result.swap(keyed_result);
1451 }
1452
1453 f_source = source;
1454 f_value.swap(result);
1455 f_integer.clear();
1456 f_double.clear();
1457
1458 bool const r(validate_all_values());
1459
1460 if(f_value != result)
1461 {
1462 // TBD: should we not call this function with all instances?
1463 // i.e. for(int idx(0); idx < f_value.size(); ++idx) ...
1464 // and check each value in f_value with the old value in
1465 // the result variable (knowing that result may be smaller)
1466 //
1467 value_changed(0);
1468 }
1469
1470 return r;
1471}
1472
1473
1493{
1494 bool all_valid(true);
1495 if(f_validator != nullptr)
1496 {
1497 for(size_t idx(0); idx < f_value.size(); )
1498 {
1499 if(!validates(idx))
1500 {
1501 // the value was removed, so do not increment `idx`
1502 //
1503 all_valid = false;
1504 }
1505 else
1506 {
1507 ++idx;
1508 }
1509 }
1510 }
1511
1512 return all_valid;
1513}
1514
1515
1532{
1533 return !f_value.empty();
1534}
1535
1536
1561{
1562 return f_source;
1563}
1564
1565
1583{
1584 g_trace_sources = trace;
1585}
1586
1587
1599{
1600 return f_trace_sources;
1601}
1602
1603
1611{
1612 g_configuration_filename = filename;
1613}
1614
1615
1631size_t option_info::size() const
1632{
1633 return f_value.size();
1634}
1635
1636
1661std::string option_info::get_value(int idx, bool raw) const
1662{
1663 if(static_cast<size_t>(idx) >= f_value.size())
1664 {
1665 throw getopt_undefined(
1666 "option_info::get_value(): no value at index "
1667 + std::to_string(idx)
1668 + " (idx >= "
1669 + std::to_string(f_value.size())
1670 + ") for --"
1671 + f_name
1672 + " so you can't get this value.");
1673 }
1674
1675 if(!raw
1676 && f_variables != nullptr
1678 {
1679 return f_variables->process_value(f_value[idx]);
1680 }
1681 else
1682 {
1683 return f_value[idx];
1684 }
1685}
1686
1687
1716{
1717 if(idx < 0)
1718 {
1719 throw getopt_logic_error("idx cannot be negative in find_value_index_by_key()");
1720 }
1721 if(f_value.empty())
1722 {
1723 throw getopt_undefined(
1724 "option_info::find_value_index_by_key(): --"
1725 + f_name
1726 + " has no values defined.");
1727 }
1728
1729 if(key.back() != ':')
1730 {
1731 key += ':';
1732 }
1733 int const max(f_value.size());
1734 for(; idx < max; ++idx)
1735 {
1736 if(f_value[idx].rfind(key, 0) == 0)
1737 {
1738 return idx;
1739 }
1740 }
1741
1742 return -1;
1743}
1744
1745
1771{
1772 if(static_cast<size_t>(idx) >= f_value.size())
1773 {
1774 throw getopt_undefined(
1775 "option_info::get_long(): no value at index "
1776 + std::to_string(idx)
1777 + " (idx >= "
1778 + std::to_string(f_value.size())
1779 + ") for --"
1780 + f_name
1781 + " so you can't get this value.");
1782 }
1783
1784 // since we may change the f_integer vector between threads,
1785 // add protection (i.e. most everything else is created at the
1786 // beginning so in the main thread)
1787 //
1788 cppthread::guard lock(get_global_mutex());
1789
1790 if(f_integer.size() != f_value.size())
1791 {
1792 // we did not yet convert to integers do that now
1793 //
1794 size_t const max(f_value.size());
1795 for(size_t i(f_integer.size()); i < max; ++i)
1796 {
1797 std::int64_t v;
1799 {
1800 f_integer.clear();
1801
1802 cppthread::log << cppthread::log_level_t::error
1803 << "invalid number ("
1804 << f_value[i]
1805 << ") in parameter --"
1806 << f_name
1807 << " at offset "
1808 << i
1809 << "."
1810 << cppthread::end;
1811 return -1;
1812 }
1813 f_integer.push_back(v);
1814 }
1815 }
1816
1817 return f_integer[idx];
1818}
1819
1820
1846{
1847 if(static_cast<size_t>(idx) >= f_value.size())
1848 {
1849 throw getopt_undefined(
1850 "option_info::get_double(): no value at index "
1851 + std::to_string(idx)
1852 + " (idx >= "
1853 + std::to_string(f_value.size())
1854 + ") for --"
1855 + f_name
1856 + " so you can't get this value.");
1857 }
1858
1859 // since we may change the f_integer vector between threads,
1860 // add protection (i.e. most everything else is created at the
1861 // beginning so in the main thread)
1862 //
1863 cppthread::guard lock(get_global_mutex());
1864
1865 if(f_double.size() != f_value.size())
1866 {
1867 // we did not yet convert to doubles do that now
1868 //
1869 size_t const max(f_value.size());
1870 for(size_t i(f_double.size()); i < max; ++i)
1871 {
1872 double v;
1874 {
1875 f_double.clear();
1876
1877 cppthread::log << cppthread::log_level_t::error
1878 << "invalid number ("
1879 << f_value[i]
1880 << ") in parameter --"
1881 << f_name
1882 << " at offset "
1883 << i
1884 << "."
1885 << cppthread::end;
1886 return -1;
1887 }
1888 f_double.push_back(v);
1889 }
1890 }
1891
1892 return f_double[idx];
1893}
1894
1895
1925{
1926 if(!always)
1927 {
1928 if(!is_defined())
1929 {
1930 return;
1931 }
1932 }
1933
1935}
1936
1937
1950
1951
1961{
1962 if(is_defined())
1963 {
1965 f_value.clear();
1966 f_integer.clear();
1967 f_double.clear();
1968
1969 value_changed(0);
1970 }
1971}
1972
1973
1986{
1987 cppthread::guard lock(get_global_mutex());
1988
1990 f_callbacks.emplace_back(f_next_callback_id, c);
1991 return f_next_callback_id;
1992}
1993
1994
2005{
2006 cppthread::guard lock(get_global_mutex());
2007
2008 auto it(std::find_if(
2009 f_callbacks.begin()
2010 , f_callbacks.end()
2011 , [id](auto e)
2012 {
2013 return e.f_id == id;
2014 }));
2015 if(it != f_callbacks.end())
2016 {
2017 f_callbacks.erase(it);
2018 }
2019}
2020
2021
2038{
2040
2042 callbacks.reserve(f_callbacks.size());
2043
2044 {
2045 cppthread::guard lock(get_global_mutex());
2047 }
2048
2049 for(auto e : callbacks)
2050 {
2051 e.f_callback(*this);
2052 }
2053}
2054
2055
2056
2065{
2066 if(!g_trace_sources)
2067 {
2068 return;
2069 }
2070
2071 std::string s;
2072 switch(f_source)
2073 {
2075 s = "command-line";
2076 break;
2077
2079 s = "configuration=\"" + g_configuration_filename + "\"";
2080 break;
2081
2083 s = "direct";
2084 break;
2085
2087 s = "dynamic";
2088 break;
2089
2091 s = "environment-variable";
2092 break;
2093
2095 // this happens on a reset or all the values were invalid
2096 //
2097 f_trace_sources.push_back(f_name + " [*undefined-source*]");
2098 return;
2099
2100 }
2101
2102 if(f_value.empty())
2103 {
2104 // this should never ever happen
2105 // (if f_value is empty then f_source == SOURCE_UNDEFINED)
2106 //
2107 f_trace_sources.push_back(f_name + " [*undefined-value*]"); // LCOV_EXCL_LINE
2108 }
2109 else
2110 {
2111 // TODO: change the algorithm, if the option supports
2112 //
2114 || static_cast<std::size_t>(idx) >= f_value.size())
2115 {
2116 f_trace_sources.push_back(f_name + "=" + f_value[0] + " [" + s + "]");
2117 }
2118 else
2119 {
2120 f_trace_sources.push_back(f_name + "[" + std::to_string(idx) + "]=" + f_value[idx] + " [" + s + "]");
2121 }
2122 }
2123}
2124
2125
2126} // namespace advgetopt
2127// 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.
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.