PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
main_merge.cpp File Reference
#include "OptionParser.h"
#include "phoenix_clock_mock.h"
+ Include dependency graph for main_merge.cpp:

Go to the source code of this file.

Functions

OptionParser createOptionParser ()
 Create the OptionParser of this program. More...
 
int main (int argc, char **argv)
 
bool mergeMock (const std::vector< PString > &vecInputFile, const PString &outputFile)
 Merge mock files. More...
 

Function Documentation

◆ createOptionParser()

OptionParser createOptionParser ( )

Create the OptionParser of this program.

Returns
OptionParser of this program

Definition at line 14 of file main_merge.cpp.

14  {
15  OptionParser parser(true, __PROGRAM_VERSION__);
16  parser.setExampleLongOption("phoenix_clock_mock_merge --input=file.clockmock --output=merged.clockmock");
17  parser.setExampleShortOption("phoenix_clock_mock_merge -i file2.clockmock file2.clockmock -o merged.clockmock");
18 
19  parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be merged");
20 
21  PString defaultOutputFile("./merged.clockmock");
22  parser.addOption("output", "o", defaultOutputFile, "Name of the output merged mock file");
23  return parser;
24 }
Parse the options passed to a program.
Definition: OptionParser.h:15
Extends the std::string.
Definition: PString.h:16

References OptionParser::addOption(), OptionType::FILENAME, OptionParser::setExampleLongOption(), and OptionParser::setExampleShortOption().

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 48 of file main_merge.cpp.

48  {
50  parser.parseArgument(argc, argv);
51 
52  const OptionMode & defaultMode = parser.getDefaultMode();
53  std::vector<PString> vecInputFile;
54  PString outputFile("");
55  defaultMode.getValue(vecInputFile, "input");
56  defaultMode.getValue(outputFile, "output");
57  return mergeMock(vecInputFile, outputFile) - 1;
58 }
Describe a mode in the program arguments.
Definition: OptionMode.h:13
bool getValue(T &value, const PString &optionName) const
Get the value of the option.
void parseArgument(int argc, char **argv)
Parse the arguments passed to the program.
const OptionMode & getDefaultMode() const
Get default mode.
bool mergeMock(const std::vector< PString > &vecInputFile, const PString &outputFile)
Merge mock files.
Definition: main_merge.cpp:31
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition: main_merge.cpp:14

References createOptionParser(), OptionParser::getDefaultMode(), OptionMode::getValue(), mergeMock(), and OptionParser::parseArgument().

+ Here is the call graph for this function:

◆ mergeMock()

bool mergeMock ( const std::vector< PString > &  vecInputFile,
const PString outputFile 
)

Merge mock files.

Parameters
vecInputFile: vector of input files to be merged
outputFile: output file name to be saved
Returns
true on success, false otherwise

Definition at line 31 of file main_merge.cpp.

31  {
32  VecTime vecMessage;
33  bool b(true);
34  for(std::vector<PString>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
35  VecTime vecTmpFile;
36  if(data_load(*itFile, vecTmpFile)){
37  concatenateVecTime(vecMessage, vecTmpFile);
38  }else{
39  b = false;
40  }
41  }
42  if(b){
43  b &= data_save(outputFile, vecMessage);
44  }
45  return b;
46 }
std::vector< time_t > VecTime
Definition: PClockMock.h:12
bool data_load(FILE *iter, T &data)
Load data from a message.
Definition: data_file.h:39
bool data_save(FILE *iter, const T &data)
Save data in a message.
Definition: data_file.h:18
void concatenateVecTime(VecTime &vecOutput, const VecTime vecInput)
Concatenate vector of message into an other one.

References concatenateVecTime(), data_load(), and data_save().

Referenced by main().

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