From 5680aa99001cb50c707c4187cd8ada0c41a573dd Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 30 Jun 2016 10:13:01 +0200 Subject: implemented virtual DetectorModule with simple send via udp --- src/ConfigReader/ConfigReader.cpp | 25 ++++++++++++++++++++ src/ConfigReader/ConfigReader.h | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/ConfigReader/ConfigReader.cpp create mode 100644 src/ConfigReader/ConfigReader.h (limited to 'src/ConfigReader') 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 +#include +#include + +#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 + +#include + +#include + +class ConfigReader { +public: + ConfigReader(const char* configFile); + ConfigReader(const ConfigReader& configReader) { + } + + template + 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 + 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 -- cgit v1.2.3