|
| 1 | +/** |
| 2 | + * libtransport -- C++ library for easy XMPP Transports development |
| 3 | + * |
| 4 | + * Copyright (C) 2011, Jan Kaluza <[email protected]> |
| 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 |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 19 | + */ |
| 20 | + |
| 21 | +#pragma once |
| 22 | + |
| 23 | +#include <boost/program_options.hpp> |
| 24 | +#include <boost/foreach.hpp> |
| 25 | +#include <boost/format.hpp> |
| 26 | +#include <boost/algorithm/string.hpp> |
| 27 | +#include <boost/assign.hpp> |
| 28 | +#include <boost/bind.hpp> |
| 29 | +#include <boost/signal.hpp> |
| 30 | + |
| 31 | +/// Represents variable:value pairs. |
| 32 | +typedef boost::program_options::variables_map Variables; |
| 33 | + |
| 34 | +/// Represents config file. |
| 35 | + |
| 36 | +/// It's used to load config file and allows others parts of libtransport to be configured |
| 37 | +/// properly. ManagerConfig files are text files which use "ini" format. Variables are divided into multiple |
| 38 | +/// sections. Every class is configurable with some variables which change its behavior. Check particular |
| 39 | +/// class documentation to get a list of all relevant variables for that class. |
| 40 | +class ManagerConfig { |
| 41 | + public: |
| 42 | + /// Constructor. |
| 43 | + ManagerConfig() {} |
| 44 | + |
| 45 | + /// Destructor |
| 46 | + virtual ~ManagerConfig() {} |
| 47 | + |
| 48 | + /// Loads data from config file. |
| 49 | + |
| 50 | + /// You can pass your extra options which will be recognized by |
| 51 | + /// the parser using opts parameter. |
| 52 | + /// \param configfile path to config file |
| 53 | + /// \param opts extra options which will be recognized by a parser |
| 54 | + bool load(const std::string &configfile, boost::program_options::options_description &opts); |
| 55 | + |
| 56 | + /// Loads data from config file. |
| 57 | + |
| 58 | + /// This function loads only config variables needed by libtransport. |
| 59 | + /// \see load(const std::string &, boost::program_options::options_description &) |
| 60 | + /// \param configfile path to config file |
| 61 | + bool load(const std::string &configfile); |
| 62 | + |
| 63 | + /// Returns value of variable defined by key. |
| 64 | + |
| 65 | + /// For variables in sections you can use "section.variable" key format. |
| 66 | + /// \param key config variable name |
| 67 | + const boost::program_options::variable_value &operator[] (const std::string &key) { |
| 68 | + return m_variables[key]; |
| 69 | + } |
| 70 | + |
| 71 | + /// Returns path to config file from which data were loaded. |
| 72 | + const std::string &getManagerConfigFile() { return m_file; } |
| 73 | + |
| 74 | + /// This signal is emitted when config is loaded/reloaded. |
| 75 | + boost::signal<void ()> onManagerConfigReloaded; |
| 76 | + |
| 77 | + private: |
| 78 | + Variables m_variables; |
| 79 | + std::string m_file; |
| 80 | +}; |
0 commit comments