PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main_merge.cpp
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 #include "string_utils.h"
8 #include "convertToString.h"
9 #include "OptionParser.h"
10 
11 #include "phoenix_mock.h"
12 
14 
17  OptionParser parser(true, __PROGRAM_VERSION__);
18  parser.setExampleLongOption("phoenix_mock_merge --input=file.pmock --output=merged.pmock");
19  parser.setExampleShortOption("phoenix_mock_merge -i file2.mock file2.pmock -o merged.pmock");
20 
21  parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be merged");
22 
23  std::string defaultOutputFile("./merged.pmock");
24  parser.addOption("output", "o", defaultOutputFile, "Name of the output merged mock file");
25  return parser;
26 }
27 
29 
33 bool mergeMock(const std::vector<std::string> & vecInputFile, const std::string & outputFile){
34  std::vector<std::vector<char> > vecMessage;
35  bool b(true);
36  for(std::vector<std::string>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
37  std::vector<std::vector<char> > vecTmpFile;
38  if(data_load(*itFile, vecTmpFile)){
39  concatenateVecMessage(vecMessage, vecTmpFile);
40  }else{
41  b = false;
42  }
43  }
44  if(b){
45  b &= data_save(outputFile, vecMessage);
46  }
47  return b;
48 }
49 
50 int main(int argc, char** argv){
52  parser.parseArgument(argc, argv);
53 
54  const OptionMode & defaultMode = parser.getDefaultMode();
55  std::vector<std::string> vecInputFile;
56  std::string outputFile("");
57  defaultMode.getValue(vecInputFile, "input");
58  defaultMode.getValue(outputFile, "output");
59  return mergeMock(vecInputFile, outputFile) - 1;
60 }
61 
62 
concatenateVecMessage
void concatenateVecMessage(std::vector< std::vector< char > > &vecOutput, const std::vector< std::vector< char > > vecInput)
Concatenate vector of message into an other one.
Definition: phoenix_mock.cpp:13
string_utils.h
OptionMode::getValue
bool getValue(T &value, const std::string &optionName) const
Get the value of the option.
Definition: OptionMode_impl.h:18
createOptionParser
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition: main_merge.cpp:16
main
int main(int argc, char **argv)
Definition: main_merge.cpp:50
createReleaseCurl.parser
parser
Definition: createReleaseCurl.py:123
OptionParser
Parse the options passed to a program.
Definition: OptionParser.h:15
mergeMock
bool mergeMock(const std::vector< std::string > &vecInputFile, const std::string &outputFile)
Merge mock files.
Definition: main_merge.cpp:33
data_save
bool data_save(FILE *iter, const T &data)
Save data in a message.
Definition: data_file.h:18
convertToString.h
data_load
bool data_load(FILE *iter, T &data)
Load data from a message.
Definition: data_file.h:39
phoenix_mock.h
OptionParser.h
OptionMode
Describe a mode in the program arguments.
Definition: OptionMode.h:13
OptionType::FILENAME
@ FILENAME
Definition: OptionType.h:26