FileConfigurator.hh
1.66 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* ParameterConfigurator.hh
*
* Created on: 18 oct. 2012
* Author: AKKA IS
*/
#ifndef PARAMETERCONFIGURATOR_HH_
#define PARAMETERCONFIGURATOR_HH_
#include <typeinfo>
#include <list>
#include <boost/any.hpp>
namespace AMDA
{
namespace Parameters
{
/**
* @brief context of FileConfigurator
* @see FileConfigurator
*/
class CfgContext
{
public:
typedef std::list<boost::any> Data;
/**
* @brief add an any values in context
*/
template<typename T>
void push(T v) {
_data.push_back(v);
}
/**
* @brief get any value added with type T
*/
template<typename T>
T get() const {
for ( Data::const_reverse_iterator rit = _data.rbegin(); rit != _data.rend(); ++rit ) {
if ( (*rit).type() == typeid(T)) {
return boost::any_cast<T>(*rit);
}
}
return NULL;
}
private:
Data _data;
};
/**
* @brief Interface to parse a xml or other file
*/
class FileConfigurator
{
public:
/**
* Destructor.
*/
virtual ~FileConfigurator() {}
/**
* Must be implemented to parse file
*/
virtual void proceed(const char* filename, const CfgContext& context, bool optionalFile = false) = 0;
/**
* @brief _path getter
*/
const std::string& getParamPath() { return _path; }
/**
* @brief _path setter
*/
void setParamPath(const std::string& path) { _path = path; }
private:
/**
* @brief path for find file
*/
std::string _path;
};
} /* namespace Parameters */
} /* namespace AMDA */
#endif /* PARAMETERCONFIGURATOR_HH_ */