PhoenixYml  0.5.0
Yml parser for Phoenix
Loading...
Searching...
No Matches
vec_value_utils.cpp File Reference
#include "vec_value_utils.h"
+ Include dependency graph for vec_value_utils.cpp:

Go to the source code of this file.

Functions

VecValueaddChildToParentVecValue (VecValue &mainVecValue, const std::vector< size_t > &vecIndentation, bool isCompactMode, const VecValue &child, size_t currentIndentation)
 Add the given child to the main VecValue and return a pointer to the added child.
 
VecValueaddChildToParentVecValueAddListItem (VecValue &mainVecValue, const std::vector< size_t > &vecIndentation, bool isCompactMode, const VecValue &child, size_t currentIndentation)
 Add the given child to the main VecValue and return a pointer to the added child.
 
VecValuegetLastVecValue (VecValue &vecVal, size_t depth)
 Get the last VecValue added at the specified depth.
 
VecValuegetParentVecValue (VecValue &vecAllVal, const std::vector< size_t > &vecIndentation, size_t currentIndentation)
 Get the parent VecValue by respect to its indentation.
 
VecValuegetParentVecValueListItem (VecValue &vecAllVal, const std::vector< size_t > &vecIndentation, size_t currentIndentation, const VecValue &child)
 Get the parent VecValue by respect to its indentation.
 
void getVecParentPtr (std::vector< VecValue * > &vecParentPtr, VecValue &vecAllVal)
 Get the parent pointer vector.
 
std::vector< VecValue * > getVecParentPtr (VecValue &vecAllVal)
 Get the parent pointer vector.
 
void vecValueToDicoValue (DicoValue &dicoValue, const VecValue &vecVal, bool isMainValue)
 Convert a VecValue into a DicoValue.
 

Function Documentation

◆ addChildToParentVecValue()

VecValue * addChildToParentVecValue ( VecValue & mainVecValue,
const std::vector< size_t > & vecIndentation,
bool isCompactMode,
const VecValue & child,
size_t currentIndentation )

Add the given child to the main VecValue and return a pointer to the added child.

Parameters
[out]mainVecValue: main VecValue to be used
vecIndentation: vector of the last indentation of the children VecValue
isCompactMode: true if the compact mode is enabled, false otherwise
child: child VecValue to be added to the main VecValue
currentIndentation: indentation of the current VecValue
Returns
pointer to the added child (cannot be NULL)

Definition at line 110 of file vec_value_utils.cpp.

110 {
111 VecValue * parent = NULL;
112 if(isCompactMode){
113 parent = &mainVecValue;
114 }else{
115 if(currentIndentation != -1lu){
116 parent = getParentVecValue(mainVecValue, vecIndentation, currentIndentation);
117 }else{
118 parent = getLastVecValue(mainVecValue);
119 }
120 }
121 parent->getVecChild().push_back(child);
122 return &(parent->getVecChild().back());
123}
Vector of keys and values.
Definition VecValue.h:15
const std::vector< VecValue > & getVecChild() const
Gets the vecChild of the VecValue.
Definition VecValue.cpp:104
VecValue * getParentVecValue(VecValue &vecAllVal, const std::vector< size_t > &vecIndentation, size_t currentIndentation)
Get the parent VecValue by respect to its indentation.
VecValue * getLastVecValue(VecValue &vecVal, size_t depth)
Get the last VecValue added at the specified depth.

References getLastVecValue(), getParentVecValue(), and VecValue::getVecChild().

Referenced by parse_yml_dicoContent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChildToParentVecValueAddListItem()

VecValue * addChildToParentVecValueAddListItem ( VecValue & mainVecValue,
const std::vector< size_t > & vecIndentation,
bool isCompactMode,
const VecValue & child,
size_t currentIndentation )

Add the given child to the main VecValue and return a pointer to the added child.

Parameters
[out]mainVecValue: main VecValue to be used
vecIndentation: vector of the last indentation of the children VecValue
isCompactMode: true if the compact mode is enabled, false otherwise
child: child VecValue to be added to the main VecValue
currentIndentation: indentation of the current VecValue
Returns
pointer to the added child (cannot be NULL)

Definition at line 133 of file vec_value_utils.cpp.

133 {
134 VecValue * parent = NULL;
135 if(isCompactMode){
136 parent = &mainVecValue;
137 }else{
138 if(currentIndentation != -1lu){
139 parent = getParentVecValueListItem(mainVecValue, vecIndentation, currentIndentation, child);
140 }else{
141 parent = getLastVecValue(mainVecValue);
142 }
143 }
144 parent->getVecChild().push_back(child);
145 return &(parent->getVecChild().back());
146}
VecValue * getParentVecValueListItem(VecValue &vecAllVal, const std::vector< size_t > &vecIndentation, size_t currentIndentation, const VecValue &child)
Get the parent VecValue by respect to its indentation.

References getLastVecValue(), getParentVecValueListItem(), and VecValue::getVecChild().

Referenced by parse_yml_listContent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastVecValue()

VecValue * getLastVecValue ( VecValue & vecVal,
size_t depth )

Get the last VecValue added at the specified depth.

Parameters
vecVal: VecValue to be used
depth: depth of the last VecValue to be returned
Returns
pointer to the corresponding VecValue (cannot be NULL)

Definition at line 15 of file vec_value_utils.cpp.

15 {
16 VecVecValue & vecChildren = vecVal.getVecChild();
17 if(vecChildren.size() == 0lu || depth == 0lu){return &vecVal;}
18 else{return getLastVecValue(vecChildren.back(), depth - 1lu);}
19}
std::vector< VecValue > VecVecValue

References getLastVecValue(), and VecValue::getVecChild().

Referenced by addChildToParentVecValue(), addChildToParentVecValueAddListItem(), getLastVecValue(), getParentVecValue(), and getParentVecValueListItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParentVecValue()

VecValue * getParentVecValue ( VecValue & vecAllVal,
const std::vector< size_t > & vecIndentation,
size_t currentIndentation )

Get the parent VecValue by respect to its indentation.

Parameters
[out]vecAllVal: main VecValue
vecIndentation: vector of the last indentation of the children VecValue
currentIndentation: indentation of the current VecValue
Returns
pointer to the corresponding VecValue (cannot be NULL)

Definition at line 27 of file vec_value_utils.cpp.

27 {
28 if(vecIndentation.size() == 0lu){
29 return getLastVecValue(vecAllVal);
30 }
31 size_t depth(0lu);
32 std::vector<size_t>::const_iterator it(vecIndentation.begin());
33 bool isCurrentLower(true);
34 while(isCurrentLower && it != vecIndentation.end()){
35 isCurrentLower = *it < currentIndentation;
36 if(isCurrentLower){
37 ++depth;
38 }
39 ++it;
40 }
41 VecValue * out = getLastVecValue(vecAllVal, depth);
42 return out;
43}

References getLastVecValue().

Referenced by addChildToParentVecValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParentVecValueListItem()

VecValue * getParentVecValueListItem ( VecValue & vecAllVal,
const std::vector< size_t > & vecIndentation,
size_t currentIndentation,
const VecValue & child )

Get the parent VecValue by respect to its indentation.

Parameters
[out]vecAllVal: main VecValue
vecIndentation: vector of the last indentation of the children VecValue
currentIndentation: indentation of the current VecValue
child: child to be added to the parent
Returns
pointer to the corresponding VecValue (cannot be NULL)

Definition at line 73 of file vec_value_utils.cpp.

73 {
74 if(vecIndentation.size() == 0lu){
75 return getLastVecValue(vecAllVal);
76 }
77 size_t childIndentation(child.getIndentation());
78 VecValue * out = NULL;
79 std::vector<VecValue*> vecParentPtr = getVecParentPtr(vecAllVal);
80 std::vector<VecValue*>::const_reverse_iterator itParent(vecParentPtr.rbegin());
81 bool isCurrentGreater(true);
82 while(isCurrentGreater && itParent != vecParentPtr.rend()){
83 if((*itParent)->getType() == VecValueType::KEY && child.getType() == VecValueType::LIST_ITEM){
84 isCurrentGreater = (*itParent)->getIndentation() > childIndentation;
85// if(!isCurrentGreater){
86// std::cout << "getParentVecValueListItem : Parent("<<(*itParent)->getKey()<<").getType() : " << (*itParent)->getType() << ", ParentIndentation = "<<(*itParent)->getIndentation()<<", child.getType() = " << child.getType() << ", key = '"<<child.getKey()<<"', value = '"<<child.getValue()<<"', childIndentation = "<<childIndentation << std::endl;
87// }
88 }else{
89 if((*itParent)->getType() != VecValueType::LIST_ITEM && (*itParent)->getType() != VecValueType::VALUE &&
91 {
92 isCurrentGreater = (*itParent)->getIndentation() >= childIndentation;
93 }
94 }
95 //If we check with a > instead a >=, we have to check if the parent of a LIST_ITEM is a KEY
96 out = *itParent;
97 ++itParent;
98 }
99 return out;
100}
const VecValueType::VecValueType & getType() const
Gets the type of the VecValue.
Definition VecValue.cpp:118
size_t getIndentation() const
Gets the indentation of the VecValue.
Definition VecValue.cpp:132
void getVecParentPtr(std::vector< VecValue * > &vecParentPtr, VecValue &vecAllVal)
Get the parent pointer vector.

References VecValue::getIndentation(), getLastVecValue(), VecValue::getType(), getVecParentPtr(), VecValueType::KEY, VecValueType::LIST_ITEM, and VecValueType::VALUE.

Referenced by addChildToParentVecValueAddListItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getVecParentPtr() [1/2]

void getVecParentPtr ( std::vector< VecValue * > & vecParentPtr,
VecValue & vecAllVal )

Get the parent pointer vector.

Parameters
[out]vecParentPtr: vector of pointer of all parent chain
vecAllVal: Main VecValue

Definition at line 49 of file vec_value_utils.cpp.

49 {
50 vecParentPtr.push_back(&vecAllVal);
51 if(vecAllVal.getVecChild().size() != 0lu){
52 getVecParentPtr(vecParentPtr, vecAllVal.getVecChild().back());
53 }
54}

References VecValue::getVecChild(), and getVecParentPtr().

Referenced by getParentVecValueListItem(), getVecParentPtr(), and getVecParentPtr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getVecParentPtr() [2/2]

std::vector< VecValue * > getVecParentPtr ( VecValue & vecAllVal)

Get the parent pointer vector.

Parameters
vecAllVal: Main VecValue
Returns
vector of pointer of all parent chain

Definition at line 60 of file vec_value_utils.cpp.

60 {
61 std::vector<VecValue*> vecParentPtr;
62 getVecParentPtr(vecParentPtr, vecAllVal);
63 return vecParentPtr;
64}

References getVecParentPtr().

+ Here is the call graph for this function:

◆ vecValueToDicoValue()

void vecValueToDicoValue ( DicoValue & dicoValue,
const VecValue & vecVal,
bool isMainValue )

Convert a VecValue into a DicoValue.

Parameters
[out]dicoValue: converted DicoValue
vecVal: vector of value
isMainValue: true if the VecValue is the main one

Definition at line 153 of file vec_value_utils.cpp.

153 {
154 PString key(vecVal.getKey());
155 const VecVecValue & vecChildren = vecVal.getVecChild();
156 if(vecChildren.size() == 0lu){
157 PString value(vecVal.getValue());
158 if(key == ""){ //The vecVal is a value only
159 DicoValue subDico;
160 subDico.setValue(value);
161 dicoValue.getVecChild().push_back(subDico);
162 }else{ //The vecVal is a key-value
163 DicoValue subDico;
164 subDico.setKey(key);
165 subDico.setValue(value);
166 dicoValue.getMapChild()[key] = subDico;
167 }
168 }else{
169 if(key != ""){
170 DicoValue subDico;
171 subDico.setKey(vecVal.getKey());
172 for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
173 vecValueToDicoValue(subDico, *it, false);
174 }
175 dicoValue.getMapChild()[key] = subDico;
176 }else{
177 if(isMainValue){
178 for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
179 vecValueToDicoValue(dicoValue, *it, false);
180 }
181 }else{
182 DicoValue dashValue;
183 for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
184 vecValueToDicoValue(dashValue, *it, false);
185 }
186 dicoValue.getVecChild().push_back(dashValue);
187 }
188 }
189 }
190}
const PString & getValue() const
Gets the value of the VecValue.
Definition VecValue.cpp:76
const PString & getKey() const
Gets the key of the VecValue.
Definition VecValue.cpp:90
void vecValueToDicoValue(DicoValue &dicoValue, const VecValue &vecVal, bool isMainValue)
Convert a VecValue into a DicoValue.

References VecValue::getKey(), VecValue::getValue(), VecValue::getVecChild(), and vecValueToDicoValue().

Referenced by parser_yml(), and vecValueToDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: