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");
22 PPath defaultOutputFile(
"./split.clockmock");
23 parser.
addOption(
"output",
"o", defaultOutputFile,
"Name of the output split mock file");
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)");
39 PPath extention(extentionFile);
41 extention =
PPath(
"clockmock");
54 bool splitMock(
const std::vector<PPath> & vecInputFile,
const PPath & outputFile,
55 size_t offsetPart,
size_t sizePart,
size_t nbPart)
57 if(sizePart == 0lu && nbPart == 0lu){
58 std::cerr <<
"Error sizePart cannot be 0 id nbPart == 0, aborting split" << std::endl;
63 for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
66 size_t nbTimeIn(vecTmpFile.size());
68 if(offsetPart <= nbTimeIn){
69 sizePart = (nbTimeIn - offsetPart)/nbPart;
71 std::cerr <<
"splitMock : cannot split nbTimeIn = " << nbTimeIn <<
", into nbPart = "<<nbPart<<
" of size sizePart = "<<sizePart<<
" and offset offsetPart = " << offsetPart << std::endl;
74 for(
size_t i(0lu); i < nbPart; ++i){
76 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
86 }
else if(nbPart == 0lu){
87 if((sizePart + offsetPart) <= nbTimeIn){
88 nbPart = (nbTimeIn-offsetPart)/sizePart;
89 for(
size_t i(0lu); i < nbPart; ++i){
91 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
100 if((sizePart*nbPart + offsetPart) <= nbTimeIn){
101 for(
size_t i(0lu); i < nbPart; ++i){
103 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
107 std::cerr <<
"splitMock : cannot split nbTimeIn = " << nbTimeIn <<
", into nbPart = "<<nbPart<<
" of size sizePart = "<<sizePart<<
" and offset offsetPart = " << offsetPart << std::endl;
118 int main(
int argc,
char** argv){
123 std::vector<PPath> vecInputFile;
124 PPath outputFile(
"");
125 defaultMode.
getValue(vecInputFile,
"input");
126 defaultMode.
getValue(outputFile,
"output");
128 size_t offsetPart(0lu), sizePart(1lu), nbPart(0lu);
129 defaultMode.
getValue(offsetPart,
"offset");
130 defaultMode.
getValue(sizePart,
"sizepart");
131 defaultMode.
getValue(nbPart,
"nbpart");
133 return splitMock(vecInputFile, outputFile, offsetPart, sizePart, nbPart) - 1;
std::vector< time_t > VecTime
Describe a mode in the program arguments.
bool getValue(T &value, const PString &optionName) const
Get the value of the option.
Parse the options passed to a program.
void parseArgument(int argc, char **argv)
Parse the arguments passed to the program.
void addOption(const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, const PString &docString)
Add an option in the OptionParser.
void setExampleShortOption(const PString &example)
Set the example usage of the program.
void setExampleLongOption(const PString &example)
Set the example usage of the program.
const OptionMode & getDefaultMode() const
Get default mode.
Path of a directory or a file.
PPath & eraseExtension()
Erase the extension of the PPath.
PString getExtension() const
Get file extension.
static PString toString(const T &value)
Convert a value to a PString.
bool data_load(FILE *iter, T &data)
Load data from a message.
bool data_save(FILE *iter, const T &data)
Save data in a message.
bool splitMock(const std::vector< PPath > &vecInputFile, const PPath &outputFile, size_t offsetPart, size_t sizePart, size_t nbPart)
Merge mock files.
int main(int argc, char **argv)
PPath phoenix_mockMakeOutputFile(const PPath &baseFileName, size_t indexFile, const PPath &extentionFile)
Make the output file name.
OptionParser createOptionParser()
Create the OptionParser of this program.
void splitVecTime(VecTime &vecOutput, const VecTime vecInput, size_t offsetPart, size_t sizePart)
Split a vector of messages into an other.