PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
dico_replace_var.h File Reference
#include "PNestedCall.h"
#include "DicoValue.h"
+ Include dependency graph for dico_replace_var.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef std::map< PString, PStringPMapKnownVar
 Map of known variables. More...
 

Functions

void dico_create_nested_call (PNestedCall &call, const PString &baseStr, const PString &varBegin, const PString &varEnd)
 Create the nested calls of the input base string. More...
 
void dico_replace_nested_call (PString &out, const PNestedCall &call, const PMapKnownVar &mapKeyVariable, const PString &varBegin, const PString &varEnd)
 Replace the nested call by the variables in map. More...
 
void dico_replace_var (DicoValue &dico, const PString &varIdentifier="$")
 Replace all the variables which are string in the given DicoValue, when ${variable} apprears in the value. More...
 
PString dico_replace_var_str (const PString &baseStr, const PMapKnownVar &mapKeyVariable, const PString &varBegin="${", const PString &varEnd="}")
 Update the suffix of the file. More...
 

Typedef Documentation

◆ PMapKnownVar

typedef std::map<PString, PString> PMapKnownVar

Map of known variables.

Definition at line 14 of file dico_replace_var.h.

Function Documentation

◆ dico_create_nested_call()

void dico_create_nested_call ( PNestedCall call,
const PString baseStr,
const PString varBegin,
const PString varEnd 
)

Create the nested calls of the input base string.

Parameters
[out]call: PNestedCall to be created
baseStr: basic suffix to be used
varBegin: characters which announce the begining of a variable (example ${)
varEnd: characters which announce the ending of a variable (example })

Definition at line 21 of file dico_replace_var.cpp.

21  {
22  PFileParser parser;
23  parser.setFileContent(baseStr);
24  while(!parser.isEndOfFile()){
25  PString prevCall(parser.getUntilKeyWithoutPatern(varBegin));
26  if(prevCall != ""){
27  PNestedStr str;
28  str.setValue(prevCall);
29  str.setIsVarCall(false);
30  call.getVecNestedStr().push_back(str);
31  }
32  PString varNameCall(parser.getUntilKeyWithoutPatern(varEnd));
33  if(varNameCall != ""){
34  PNestedStr str;
35  str.setValue(varNameCall);
36  str.setIsVarCall(true);
37  call.getVecNestedStr().push_back(str);
38  }
39  }
40 }
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition: PFileParser.h:20
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void setFileContent(const PString &fileContent)
Set the file content.
Definition: PFileParser.cpp:50
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Definition: PFileParser.cpp:88
const std::vector< PNestedStr > & getVecNestedStr() const
Gets the vecNestedStr of the PNestedCall.
Nested string or variable call.
Definition: PNestedCall.h:14
void setValue(const PString &value)
Sets the value of the PNestedStr.
Definition: PNestedCall.cpp:39
void setIsVarCall(bool isVarCall)
Sets the isVarCall of the PNestedStr.
Definition: PNestedCall.cpp:46
Extends the std::string.
Definition: PString.h:16

References PFileParser::getUntilKeyWithoutPatern(), PNestedCall::getVecNestedStr(), PFileParser::isEndOfFile(), PFileParser::setFileContent(), PNestedStr::setIsVarCall(), and PNestedStr::setValue().

Referenced by dico_replace_var_str().

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

◆ dico_replace_nested_call()

void dico_replace_nested_call ( PString out,
const PNestedCall call,
const PMapKnownVar mapKeyVariable,
const PString varBegin,
const PString varEnd 
)

Replace the nested call by the variables in map.

Parameters
[out]out: output string with replaced variables
call: nested call to create the output string
mapKeyVariable: map of all defined variabled to be used
varBegin: characters which announce the begining of a variable (example ${) (in case variable is not found)
varEnd: characters which announce the ending of a variable (example }) (in case variable is not found)

Definition at line 49 of file dico_replace_var.cpp.

49  {
50  const std::vector<PNestedStr> & vecNestedStr = call.getVecNestedStr();
51  for(std::vector<PNestedStr>::const_iterator it(vecNestedStr.begin()); it != vecNestedStr.end(); ++it){
52  if(it->getIsVarCall()){
53  PMapKnownVar::const_iterator itCall(mapKeyVariable.find(varBegin + it->getValue() + varEnd));
54  if(itCall != mapKeyVariable.end()){
55  out += itCall->second;
56  }else{
57  out += varBegin + it->getValue() + varEnd;
58  }
59  }else{
60  out += it->getValue();
61  }
62  }
63 }

References PNestedCall::getVecNestedStr().

Referenced by dico_replace_var_str().

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

◆ dico_replace_var()

void dico_replace_var ( DicoValue dico,
const PString varIdentifier 
)

Replace all the variables which are string in the given DicoValue, when ${variable} apprears in the value.

Parameters
dico: DicoValue to be updated
varIdentifier: String used to detect the variable names (example: '$' for ${varName}, § for §{varName})

Definition at line 218 of file dico_replace_var.cpp.

218  {
219  //Let's find all the defined variables, linked to the DicoValue, string only
220  PMapKnownVar mapReadyVar;
221  PVecReplaceVar mapNestedVar;
222  MapVarWithNestedCall mapVarWithNestedCall;
223  dico_find_all_var(mapReadyVar, mapNestedVar, mapVarWithNestedCall, dico, varIdentifier);
224 
225  //Update variables with nested call, separate those with nested call from the other
226  dico_update_all_var(mapReadyVar, mapNestedVar, mapVarWithNestedCall, varIdentifier);
227 }
std::vector< std::pair< PNestedCall, DicoValue * > > PVecReplaceVar
Map used to replace variable value in nested calls (VariableName, PNestedCall)
void dico_update_all_var(PMapKnownVar &mapReadyVar, PVecReplaceVar &mapNestedVar, MapVarWithNestedCall &mapVarWithNestedCall, const PString &varIdentifier)
Update the variable which contains nested calls.
void dico_find_all_var(PMapKnownVar &mapReadyVar, PVecReplaceVar &mapNestedVar, MapVarWithNestedCall &mapVarWithNestedCall, DicoValue &dico, const PString &varIdentifier)
Get the variable which contains only a value and those with nested calls.
std::map< PString, std::pair< PNestedCall, DicoValue * > > MapVarWithNestedCall
Map of the variables which uses nested call.
std::map< PString, PString > PMapKnownVar
Map of known variables.

References dico_find_all_var(), and dico_update_all_var().

+ Here is the call graph for this function:

◆ dico_replace_var_str()

PString dico_replace_var_str ( const PString baseStr,
const PMapKnownVar mapKeyVariable,
const PString varBegin,
const PString varEnd 
)

Update the suffix of the file.

Parameters
baseStr: basic suffix to be used
mapKeyVariable: map of all defined variabled to be used
varBegin: characters which announce the begining of a variable (example ${)
varEnd: characters which announce the ending of a variable (example })
Returns
updated string

Definition at line 72 of file dico_replace_var.cpp.

72  {
73  if(varBegin == "" || varEnd == ""){return baseStr;}
74  PNestedCall call;
75  dico_create_nested_call(call, baseStr, varBegin, varEnd);
76  PString out("");
77  dico_replace_nested_call(out, call, mapKeyVariable, varBegin, varEnd);
78  return out;
79 }
Class used to parse nested call variables.
Definition: PNestedCall.h:36
void dico_replace_nested_call(PString &out, const PNestedCall &call, const PMapKnownVar &mapKeyVariable, const PString &varBegin, const PString &varEnd)
Replace the nested call by the variables in map.
void dico_create_nested_call(PNestedCall &call, const PString &baseStr, const PString &varBegin, const PString &varEnd)
Create the nested calls of the input base string.

References dico_create_nested_call(), and dico_replace_nested_call().

Referenced by checkVarReplaceStr().

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