10 #include <boost/property_tree/ini_parser.hpp>
11 #include <boost/filesystem.hpp>
16 : m_path(findConfigFile())
27 if (m_input.is_open())
33 boost::filesystem::path
34 ConfigFile::findConfigFile()
36 using namespace boost::filesystem;
38 path home(std::getenv(
"HOME"));
41 home /=
".ndn/client.conf";
44 return absolute(home);
48 #ifdef NDN_CPP_SYSCONFDIR
49 path sysconfdir(NDN_CPP_SYSCONFDIR);
50 sysconfdir /=
"ndn/client.conf";
52 if (exists(sysconfdir))
54 return absolute(sysconfdir);
56 #endif // NDN_CPP_SYSCONFDIR
58 path etc(
"/etc/ndn/client.conf");
77 m_input.open(m_path.c_str());
78 if (!m_input.good() || !m_input.is_open())
88 if (m_input.is_open())
100 throw Error(
"Failed to locate configuration file for parsing");
102 else if (!m_input.is_open() && !open())
104 throw Error(
"Failed to open configuration file for parsing");
109 boost::property_tree::read_ini(m_input, m_config);
111 catch (boost::property_tree::ini_parser_error& error)
113 std::stringstream msg;
114 msg <<
"Failed to parse configuration file";
115 msg <<
" " << m_path;
116 msg <<
" " << error.message() <<
" line " << error.line();
117 throw Error(msg.str());
boost::property_tree::ptree Parsed
ConfigFile()
Locate, open, and parse a library configuration file.