summaryrefslogtreecommitdiffstats
path: root/src/ConfigReader
diff options
context:
space:
mode:
authorTobias Frust <tobiasfrust@gmail.com>2016-07-11 15:15:32 +0200
committerGitHub <noreply@github.com>2016-07-11 15:15:32 +0200
commit8af3d595e2856f81a46a91d67e96f53cb3b25d0f (patch)
treebd2cb6e80b0db90713f9d24de09577125d6f3d85 /src/ConfigReader
parent13783f932576a285b08cf518a6b0d679aac3c897 (diff)
parent409e2fd20af5620066796e43410a92521376b2c1 (diff)
downloadods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.tar.gz
ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.tar.bz2
ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.tar.xz
ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.zip
Merge pull request #1 from tobiasfrust/master
Implemented DetectorSimulator with basic functionalities
Diffstat (limited to 'src/ConfigReader')
-rw-r--r--src/ConfigReader/ConfigReader.cpp25
-rw-r--r--src/ConfigReader/ConfigReader.h48
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