PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
main_split.cpp File Reference
#include "PPath.h"
#include "OptionParser.h"
#include "phoenix_clock_mock.h"
+ Include dependency graph for main_split.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)
 
PPath phoenix_mockMakeOutputFile (const PPath &baseFileName, size_t indexFile, const PPath &extentionFile)
 Make the output file name. More...
 
bool splitMock (const std::vector< PPath > &vecInputFile, const PPath &outputFile, size_t offsetPart, size_t sizePart, size_t nbPart)
 Merge mock files. More...
 

Function Documentation

◆ createOptionParser()

OptionParser createOptionParser ( )

Create the OptionParser of this program.

Returns
OptionParser of this program

Definition at line 15 of file main_split.cpp.

15  {
16  OptionParser parser(true, __PROGRAM_VERSION__);
17  parser.setExampleLongOption("phoenix_clock_mock_split --input=file.clockmock --output=split.clockmock");
18  parser.setExampleShortOption("phoenix_clock_mock_split -i file2.clockmock file2.clockmock -o split.clockmock");
19 
20  parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be split");
21 
22  PPath defaultOutputFile("./split.clockmock");
23  parser.addOption("output", "o", defaultOutputFile, "Name of the output split mock file");
24 
25  size_t defaultOffset(0lu), defaultSizePart(1lu), defaultNbPart(0lu);
26  parser.addOption("offset", "f", defaultOffset, "Offset of the first message to be extracted in a split mock");
27  parser.addOption("sizepart", "s", defaultSizePart, "Size of each split part (number of messages in each part to be split)");
28  parser.addOption("nbpart", "n", defaultNbPart, "Number of output mock to be created (0 means automatic by respect to --offset and --sizepart)");
29  return parser;
30 }
Parse the options passed to a program.
Definition: OptionParser.h:15
Path of a directory or a file.
Definition: PPath.h:17

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 118 of file main_split.cpp.

118  {
119  OptionParser parser = createOptionParser();
120  parser.parseArgument(argc, argv);
121 
122  const OptionMode & defaultMode = parser.getDefaultMode();
123  std::vector<PPath> vecInputFile;
124  PPath outputFile("");
125  defaultMode.getValue(vecInputFile, "input");
126  defaultMode.getValue(outputFile, "output");
127 
128  size_t offsetPart(0lu), sizePart(1lu), nbPart(0lu);
129  defaultMode.getValue(offsetPart, "offset");
130  defaultMode.getValue(sizePart, "sizepart");
131  defaultMode.getValue(nbPart, "nbpart");
132 
133  return splitMock(vecInputFile, outputFile, offsetPart, sizePart, nbPart) - 1;
134 }
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 splitMock(const std::vector< PPath > &vecInputFile, const PPath &outputFile, size_t offsetPart, size_t sizePart, size_t nbPart)
Merge mock files.
Definition: main_split.cpp:54
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition: main_split.cpp:15

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

+ Here is the call graph for this function:

◆ phoenix_mockMakeOutputFile()

PPath phoenix_mockMakeOutputFile ( const PPath baseFileName,
size_t  indexFile,
const PPath extentionFile 
)

Make the output file name.

Parameters
baseFileName: base name of the file
indexFile: index of hte file
extentionFile: extention of the file
Returns
corresponding output file

Definition at line 38 of file main_split.cpp.

38  {
39  PPath extention(extentionFile);
40  if(extention == ""){
41  extention = PPath("clockmock");
42  }
43  return PPath(baseFileName + PString("_") + PString::toString(indexFile) + PString(".") + extention);
44 }
Extends the std::string.
Definition: PString.h:16
static PString toString(const T &value)
Convert a value to a PString.
Definition: PString_impl.h:18

References PString::toString().

Referenced by splitMock().

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

◆ splitMock()

bool splitMock ( const std::vector< PPath > &  vecInputFile,
const PPath outputFile,
size_t  offsetPart,
size_t  sizePart,
size_t  nbPart 
)

Merge mock files.

Parameters
vecInputFile: vector of input files to be merged
outputFile: output file name to be saved
offsetPart: offset of the first message to be extracted in a split mock
sizePart: size of each split part (number of messages in each part to be split)
nbPart: number of output mock to be created (0 means automatic by respect to –offset and –sizepart)
Returns
true on success, false otherwise

Definition at line 54 of file main_split.cpp.

56 {
57  if(sizePart == 0lu && nbPart == 0lu){
58  std::cerr << "Error sizePart cannot be 0 id nbPart == 0, aborting split" << std::endl;
59  return false;
60  }
61  PPath outputExtension(outputFile.getExtension()), baseOutputFile(outputFile.eraseExtension());
62  bool b(true);
63  for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
64  VecTime vecTmpFile;
65  if(data_load(*itFile, vecTmpFile)){
66  size_t nbTimeIn(vecTmpFile.size());
67  if(sizePart == 0lu){
68  if(offsetPart <= nbTimeIn){
69  sizePart = (nbTimeIn - offsetPart)/nbPart;
70  if(sizePart == 0lu){
71  std::cerr << "splitMock : cannot split nbTimeIn = " << nbTimeIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
72  b = false;
73  }else{
74  for(size_t i(0lu); i < nbPart; ++i){
75  VecTime vecMessage;
76  splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
77  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
78  }
79  }
80  }else{
81  VecTime vecMessage;
82 // splitVecTime(vecMessage, vecTmpFile, offsetPart, sizePart);
83  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
84  }
85 
86  }else if(nbPart == 0lu){
87  if((sizePart + offsetPart) <= nbTimeIn){
88  nbPart = (nbTimeIn-offsetPart)/sizePart;
89  for(size_t i(0lu); i < nbPart; ++i){
90  VecTime vecMessage;
91  splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
92  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
93  }
94  }else{
95  VecTime vecMessage;
96 // splitVecTime(vecMessage, vecTmpFile, offsetPart, sizePart);
97  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
98  }
99  }else{
100  if((sizePart*nbPart + offsetPart) <= nbTimeIn){
101  for(size_t i(0lu); i < nbPart; ++i){
102  VecTime vecMessage;
103  splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
104  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
105  }
106  }else{
107  std::cerr << "splitMock : cannot split nbTimeIn = " << nbTimeIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
108  b = false;
109  }
110  }
111  }else{
112  b = false;
113  }
114  }
115  return b;
116 }
std::vector< time_t > VecTime
Definition: PClockMock.h:12
PPath & eraseExtension()
Erase the extension of the PPath.
Definition: PPath.cpp:292
PString getExtension() const
Get file extension.
Definition: PPath.cpp:252
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
PPath phoenix_mockMakeOutputFile(const PPath &baseFileName, size_t indexFile, const PPath &extentionFile)
Make the output file name.
Definition: main_split.cpp:38
void splitVecTime(VecTime &vecOutput, const VecTime vecInput, size_t offsetPart, size_t sizePart)
Split a vector of messages into an other.

References data_load(), data_save(), PPath::eraseExtension(), PPath::getExtension(), phoenix_mockMakeOutputFile(), and splitVecTime().

Referenced by main().

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