Line data Source code
1 : // Copyright (c) 2006-2022 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/advgetopt
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : #pragma once
20 :
21 : /** \file
22 : * \brief Declaration of the variable class.
23 : *
24 : * The advgetopt library supports variables in its configuration files.
25 : *
26 : * This class handles the variable data store and replacement in strings.
27 : */
28 :
29 : // self
30 : //
31 : #include <advgetopt/utils.h>
32 :
33 :
34 : // C++
35 : //
36 : #include <map>
37 : #include <memory>
38 : #include <string>
39 :
40 :
41 :
42 : namespace advgetopt
43 : {
44 :
45 :
46 :
47 733 : class variables
48 : {
49 : public:
50 : typedef std::shared_ptr<variables> pointer_t;
51 : typedef std::map<std::string, std::string> variable_t;
52 :
53 : bool has_variable(std::string const & name) const;
54 : std::string get_variable(std::string const & name) const;
55 : variable_t const & get_variables() const;
56 : void set_variable(
57 : std::string const & name
58 : , std::string const & value
59 : , bool overwrite = true);
60 :
61 : std::string process_value(std::string const & value) const;
62 :
63 : static std::string canonicalize_variable_name(std::string const & name);
64 :
65 : private:
66 : typedef string_set_t variable_names_t;
67 :
68 : std::string recursive_process_value(
69 : std::string const & value
70 : , variable_names_t & names) const;
71 :
72 : variable_t f_variables = variable_t();
73 : };
74 :
75 :
76 :
77 : } // namespace advgetopt
78 : // vim: ts=4 sw=4 et
|