summaryrefslogtreecommitdiffstats
path: root/src/ConfigReader/ConfigReader.h
blob: 2819f41dc077028b8aa7c8ec891eca30af648986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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