PhoenixFileParser  1.5.1
Set of tools to ease file parsing
Loading...
Searching...
No Matches
ConfigNodeIter_impl.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __CONFIGNODEITER_IMPL_H__
8#define __CONFIGNODEITER_IMPL_H__
9
10#include "ConfigNode.h"
11
12
14
17template<typename T>
18bool ConfigNodeIter::getValue(T & data) const{
19 if(p_current->hasValue()){
20 if(p_isWriteMode){
21 p_current->setValue(PString::toString(data));
22 }else{
23 data = PString::toValue<T>(p_current->getString());
24 }
25 return true;
26 }else{
27 *p_out << "ConfigNodeIter::getValue : no value in ConfigNode defined at " << p_current->getLocation() << std::endl;
28 return false;
29 }
30}
31
33
37template<typename T>
38bool ConfigNodeIter::getValue(T & data, const GenericConfigCheck * checker) const{
39 if(checker != NULL && p_isWriteMode){
40 if(!checker->isOk(*p_out)){
41 *p_out << "\tdefined in ConfigNode '"<<p_current->getName()<<"'. I am sorry but since this is not yet a file I do not have any line numbers" << std::endl;
42 return false;
43 }
44 }
45 if(getValue(data)){
46 if(checker != NULL){
47 if(checker->isOk(*p_out)){
48 return true;
49 }else{
50 *p_out << "\tdefined at " << p_current->getLocation() << std::endl;
51 }
52 }else{
53 return true;
54 }
55 }
56 return false;
57}
58
60
65template<typename T>
66bool ConfigNodeIter::getChildValue(const PString & childName, T & data, const GenericConfigCheck * checker){
67 if(!down(childName)){return false;}
68 if(!getValue(data, checker)){return false;}
69 up();
70 return true;
71}
72
73
74#endif
bool getChildValue(const PString &childName, T &data, const GenericConfigCheck *checker=NULL)
Get a value from the current ConfigNode and check data.
bool p_isWriteMode
True if the ConfigNodeIter is in writing mode.
bool down(const PString &childName)
Move to the child of the current node.
void up()
Move to the parent of the current node.
bool getValue(T &data) const
Get a value from the current ConfigNode.
ConfigNode * p_current
Current ConfigNode.
std::ostream * p_out
std::ostream to be used for the error messages
Generic class for a configuration check.
virtual bool isOk(std::ostream &out) const =0