diff options
author | Tobias Frust <tobiasfrust@gmail.com> | 2016-06-30 10:13:01 +0200 |
---|---|---|
committer | Tobias Frust <tobiasfrust@gmail.com> | 2016-06-30 10:13:01 +0200 |
commit | 5680aa99001cb50c707c4187cd8ada0c41a573dd (patch) | |
tree | fcbe575cd20e35dbe3d2b7def5e7c801d576aaf8 /src/ConfigReader | |
parent | 1dc95b4eed7974549ef43a87e0777aa343b30fd4 (diff) | |
download | ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.tar.gz ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.tar.bz2 ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.tar.xz ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.zip |
implemented virtual DetectorModule with simple send via udp
Diffstat (limited to 'src/ConfigReader')
-rw-r--r-- | src/ConfigReader/ConfigReader.cpp | 25 | ||||
-rw-r--r-- | src/ConfigReader/ConfigReader.h | 48 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/ConfigReader/ConfigReader.cpp b/src/ConfigReader/ConfigReader.cpp new file mode 100644 index 0000000..7589d6a --- /dev/null +++ b/src/ConfigReader/ConfigReader.cpp @@ -0,0 +1,25 @@ +/* + * ConfigReader.cpp + * + * Created on: 18.04.2016 + * Author: Tobias Frust (t.frust@hzdr.de) + */ + +#include <iostream> +#include <iomanip> +#include <cstdlib> + +#include "ConfigReader.h" + +ConfigReader::ConfigReader(const char* configFile) { + try { + cfg.readFile(configFile); + } catch (const libconfig::FileIOException &fioex) { + std::cerr << "I/O error while reading file." << std::endl; + exit(1); + } catch (const libconfig::ParseException &pex) { + std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() + << " - " << pex.getError() << std::endl; + exit(1); + } +} diff --git a/src/ConfigReader/ConfigReader.h b/src/ConfigReader/ConfigReader.h new file mode 100644 index 0000000..2819f41 --- /dev/null +++ b/src/ConfigReader/ConfigReader.h @@ -0,0 +1,48 @@ +/* + * Copyright 2016 Tobias Frust + * + * ConfigReader.h + * + * Created on: 18.04.2016 + * Author: Tobias Frust (t.frust@hzdr.de) + */ + +#ifndef CONFIGREADER_H +#define CONFIGREADER_H +#pragma once + +#include <boost/log/trivial.hpp> + +#include <libconfig.h++> + +#include <string> + +class ConfigReader { +public: + ConfigReader(const char* configFile); + ConfigReader(const ConfigReader& configReader) { + } + + template<typename T> + bool lookupValue(const std::string& identifier, T& value) { + bool ret = cfg.lookupValue(identifier.c_str(), value); + BOOST_LOG_TRIVIAL(debug) << "Configuration value " << identifier << ": " << value; + return ret; + } + + template<typename T> + bool lookupValue(const std::string& identifier, int index, T& value) { + libconfig::Setting& s = cfg.lookup(identifier.c_str()); + if(s.getLength() > index){ + value = s[index]; + BOOST_LOG_TRIVIAL(debug) << "Configuration value " << identifier << "[" << index << "]: " << value; + return true; + } + return false; + } + +private: + libconfig::Config cfg; +}; + +#endif |