+#include <unistd.h>
+
+namespace
+{
+
+template <class C>
+void ReadConfigFile(const std::string & filePath, void (C::* callback)(const std::string&, const std::string&), C * obj)
+{
+ std::ifstream stream(filePath.c_str());
+ std::string line;
+ size_t num = 0;
+ while (std::getline(stream, line))
+ {
+ ++num;
+ line = Trim(line);
+ std::string::size_type pos = line.find_first_of('#');
+ if (pos != std::string::npos)
+ line = line.substr(0, pos);
+ if (line.empty())
+ continue;
+ pos = line.find_first_of('=');
+ if (pos == std::string::npos)
+ {
+ std::ostringstream error;
+ error << "Bad file format, missing '=' in '" << filePath << ":" << num << "'.";
+ throw std::runtime_error(error.str().c_str());
+ }
+ (obj->*callback)(Trim(line.substr(0, pos)), Trim(line.substr(pos + 1, line.length() - pos - 1)));
+ }
+}
+
+} // namespace anonymous
+