All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
config-file.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
7 #ifndef NDN_MANAGEMENT_CONFIG_FILE_HPP
8 #define NDN_MANAGEMENT_CONFIG_FILE_HPP
9 
10 #include "../common.hpp"
11 
12 #include <boost/property_tree/ptree.hpp>
13 #include <boost/filesystem.hpp>
14 
15 namespace ndn {
16 
17 class ConfigFile : noncopyable
18 {
19 public:
20 
21  class Error : public std::runtime_error
22  {
23  public:
24  Error(const std::string& what)
25  : std::runtime_error(what)
26  {
27 
28  }
29  };
30 
31  typedef boost::property_tree::ptree Parsed;
32 
38  ConfigFile();
39 
40  ~ConfigFile();
41 
42  const boost::filesystem::path&
43  getPath() const;
44 
45  const Parsed&
46  getParsedConfiguration() const;
47 
48 private:
49 
50  bool
51  open();
52 
53  void
54  close();
55 
65  const Parsed&
66  parse();
67 
78  boost::filesystem::path
79  findConfigFile();
80 
81 private:
82  boost::filesystem::path m_path; // absolute path to active configuration file (if any)
83  std::ifstream m_input;
84  Parsed m_config;
85 };
86 
87 inline const boost::filesystem::path&
89 {
90  return m_path;
91 }
92 
93 inline const ConfigFile::Parsed&
95 {
96  return m_config;
97 }
98 
99 } // namespace ndn
100 
101 
102 #endif // NDN_MANAGEMENT_CONFIG_FILE_HPP
103 
const Parsed & getParsedConfiguration() const
Definition: config-file.hpp:94
boost::property_tree::ptree Parsed
Definition: config-file.hpp:31
const boost::filesystem::path & getPath() const
Definition: config-file.hpp:88
ConfigFile()
Locate, open, and parse a library configuration file.
Definition: config-file.cpp:15
Error(const std::string &what)
Definition: config-file.hpp:24