NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
config-file.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25 #ifndef NFD_CORE_CONFIG_FILE_HPP
26 #define NFD_CORE_CONFIG_FILE_HPP
27 
28 #include "common.hpp"
29 
30 #include <boost/property_tree/ptree.hpp>
31 
32 namespace nfd {
33 
34 typedef boost::property_tree::ptree ConfigSection;
35 
37 typedef function<void(const ConfigSection& /*section*/,
38  bool /*isDryRun*/,
39  const std::string& /*filename*/)> ConfigSectionHandler;
40 
42 typedef function<void(const std::string& /*filename*/,
43  const std::string& /*sectionName*/,
44  const ConfigSection& /*section*/,
45  bool /*isDryRun*/)> UnknownConfigSectionHandler;
46 
47 class ConfigFile : noncopyable
48 {
49 public:
50 
51  class Error : public std::runtime_error
52  {
53  public:
54  explicit
55  Error(const std::string& what)
56  : std::runtime_error(what)
57  {
58 
59  }
60  };
61 
63 
64  static void
65  throwErrorOnUnknownSection(const std::string& filename,
66  const std::string& sectionName,
67  const ConfigSection& section,
68  bool isDryRun);
69 
70  static void
71  ignoreUnknownSection(const std::string& filename,
72  const std::string& sectionName,
73  const ConfigSection& section,
74  bool isDryRun);
75 
77  void
78  addSectionHandler(const std::string& sectionName,
79  ConfigSectionHandler subscriber);
80 
81 
88  void
89  parse(const std::string& filename, bool isDryRun);
90 
98  void
99  parse(const std::string& input, bool isDryRun, const std::string& filename);
100 
107  void
108  parse(std::istream& input, bool isDryRun, const std::string& filename);
109 
116  void
117  parse(const ConfigSection& config, bool isDryRun, const std::string& filename);
118 
119 private:
120 
121  void
122  process(bool isDryRun, const std::string& filename);
123 
124 private:
125  UnknownConfigSectionHandler m_unknownSectionCallback;
126 
127  typedef std::map<std::string, ConfigSectionHandler> SubscriptionTable;
128 
129  SubscriptionTable m_subscriptions;
130 
131  ConfigSection m_global;
132 };
133 
134 } // namespace nfd
135 
136 
137 #endif // NFD_CORE_CONFIG_FILE_HPP
function< void(const ConfigSection &, bool, const std::string &)> ConfigSectionHandler
callback for config file sections
Definition: config-file.hpp:39
Error(const std::string &what)
Definition: config-file.hpp:55
static void throwErrorOnUnknownSection(const std::string &filename, const std::string &sectionName, const ConfigSection &section, bool isDryRun)
Definition: config-file.cpp:36
void addSectionHandler(const std::string &sectionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
Definition: config-file.cpp:63
function< void(const std::string &, const std::string &, const ConfigSection &, bool)> UnknownConfigSectionHandler
callback for config file sections without a subscribed handler
Definition: config-file.hpp:45
boost::property_tree::ptree ConfigSection
ConfigFile(UnknownConfigSectionHandler unknownSectionCallback=throwErrorOnUnknownSection)
Definition: config-file.cpp:57
static void ignoreUnknownSection(const std::string &filename, const std::string &sectionName, const ConfigSection &section, bool isDryRun)
Definition: config-file.cpp:49
void parse(const std::string &filename, bool isDryRun)
Definition: config-file.cpp:70