PhoenixFileParser  1.5.1
Set of tools to ease file parsing
Loading...
Searching...
No Matches
directory_replace_placeholder.cpp File Reference
+ Include dependency graph for directory_replace_placeholder.cpp:

Go to the source code of this file.

Functions

bool directory_replace_placeholder (const PPath &outputDir, const PPath &inputConfigDir, const PMapString &mapReplacePlaceholder)
 Replace placeholder in a directory and its content by respect to the given map of value for all place holder.
 
bool directory_replace_placeholderFile (const PPath &outputDir, const PPath &inputConfigDir, const PMapString &mapReplacePlaceholder)
 Replace placeholder in a directory and its content by respect to the given map of value for all place holder (file only)
 

Function Documentation

◆ directory_replace_placeholder()

bool directory_replace_placeholder ( const PPath & outputDir,
const PPath & inputConfigDir,
const PMapString & mapReplacePlaceholder )

Replace placeholder in a directory and its content by respect to the given map of value for all place holder.

Parameters
outputDir: output directory
inputConfigDir: input configuration directory
mapReplacePlaceholder: map of placeholders and values to be replaced with
Returns
true on success, false otherwise

Definition at line 37 of file directory_replace_placeholder.cpp.

37 {
38 if(!outputDir.createDirectory()){
39 std::cerr << "directory_replace_placeholder : cannot create dir '"<<outputDir<<"'" << std::endl;
40 return false;
41 }
42 //Let's get content of inputConfigDir
43 PVecPath vecDirInputDir = inputConfigDir.getAllDirectoryInDir();
44 bool b(true);
45 for(PVecPath::iterator itDir(vecDirInputDir.begin()); itDir != vecDirInputDir.end(); ++itDir){
46 PPath relativeDir = itDir->replace(mapReplacePlaceholder);
47 PPath fullInputDir = inputConfigDir / *itDir;
48 PPath fullOutputDir = outputDir / relativeDir;
49 b &= fullOutputDir.createDirectory();
50
51 b &= directory_replace_placeholderFile(fullOutputDir, fullInputDir, mapReplacePlaceholder);
52 b &= directory_replace_placeholder(fullOutputDir, fullInputDir, mapReplacePlaceholder);
53 }
54 b &= directory_replace_placeholderFile(outputDir, inputConfigDir, mapReplacePlaceholder);
55 if(!b){
56 std::cerr << "directory_replace_placeholder : cannot create output directories architecture" << std::endl;
57 std::cerr << "\tinputConfigDir = '"<<inputConfigDir<<"'" << std::endl;
58 std::cerr << "\toutputDir = '"<<outputDir<<"'" << std::endl;
59 return false;
60 }
61 return b;
62}
bool directory_replace_placeholder(const PPath &outputDir, const PPath &inputConfigDir, const PMapString &mapReplacePlaceholder)
Replace placeholder in a directory and its content by respect to the given map of value for all place...
bool directory_replace_placeholderFile(const PPath &outputDir, const PPath &inputConfigDir, const PMapString &mapReplacePlaceholder)
Replace placeholder in a directory and its content by respect to the given map of value for all place...

References directory_replace_placeholder(), and directory_replace_placeholderFile().

Referenced by directory_replace_placeholder().

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

◆ directory_replace_placeholderFile()

bool directory_replace_placeholderFile ( const PPath & outputDir,
const PPath & inputConfigDir,
const PMapString & mapReplacePlaceholder )

Replace placeholder in a directory and its content by respect to the given map of value for all place holder (file only)

Parameters
outputDir: output directory
inputConfigDir: input configuration directory
mapReplacePlaceholder: map of placeholders and values to be replaced with
Returns
true on success, false otherwise

Definition at line 16 of file directory_replace_placeholder.cpp.

16 {
17 bool b(true);
18 PVecPath vecFileInputDir = inputConfigDir.getAllFileInDir();
19 for(PVecPath::iterator it(vecFileInputDir.begin()); it != vecFileInputDir.end(); ++it){
20 PPath relativeFile = it->replace(mapReplacePlaceholder);
21 PPath fullFile = inputConfigDir / *it;
22 PString fileContent = fullFile.loadFileContent();
23 //TODO : this could be optimised with the dico_replace_var algorithm, but this is enough for now
24 PString replacedContent = fileContent.replace(mapReplacePlaceholder);
25 PPath outputFile = outputDir / relativeFile;
26 b &= outputFile.saveFileContent(replacedContent);
27 }
28 return b;
29}

Referenced by directory_replace_placeholder().

+ Here is the caller graph for this function: