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 |
|
|
|
13 |
|
|
///Create the OptionParser of this program |
14 |
|
|
/** @return OptionParser of this program |
15 |
|
|
*/ |
16 |
|
2 |
OptionParser createOptionParser(){ |
17 |
✓✓ |
4 |
OptionParser parser(true, __PROGRAM_VERSION__); |
18 |
✓✓ |
2 |
parser.setExampleLongOption("phoenix_mock_merge --input=file.pmock --output=merged.pmock"); |
19 |
✓✓ |
2 |
parser.setExampleShortOption("phoenix_mock_merge -i file2.mock file2.pmock -o merged.pmock"); |
20 |
|
|
|
21 |
✓✓✓✓
|
2 |
parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be merged"); |
22 |
|
|
|
23 |
✓ |
4 |
std::string defaultOutputFile("./merged.pmock"); |
24 |
✓✓✓✓ ✓ |
2 |
parser.addOption("output", "o", defaultOutputFile, "Name of the output merged mock file"); |
25 |
|
4 |
return parser; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
///Merge mock files |
29 |
|
|
/** @param vecInputFile : vector of input files to be merged |
30 |
|
|
* @param outputFile : output file name to be saved |
31 |
|
|
* @return true on success, false otherwise |
32 |
|
|
*/ |
33 |
|
2 |
bool mergeMock(const std::vector<std::string> & vecInputFile, const std::string & outputFile){ |
34 |
|
2 |
std::vector<std::vector<char> > vecMessage; |
35 |
|
2 |
bool b(true); |
36 |
✓✓✓✓ ✓✓ |
6 |
for(std::vector<std::string>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){ |
37 |
|
8 |
std::vector<std::vector<char> > vecTmpFile; |
38 |
✓✓✓ |
4 |
if(data_load(*itFile, vecTmpFile)){ |
39 |
✓✓ |
3 |
concatenateVecMessage(vecMessage, vecTmpFile); |
40 |
|
|
}else{ |
41 |
|
1 |
b = false; |
42 |
|
|
} |
43 |
|
|
} |
44 |
✓✓ |
2 |
if(b){ |
45 |
✓ |
1 |
b &= data_save(outputFile, vecMessage); |
46 |
|
|
} |
47 |
|
4 |
return b; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
2 |
int main(int argc, char** argv){ |
51 |
✓ |
4 |
OptionParser parser = createOptionParser(); |
52 |
✓ |
2 |
parser.parseArgument(argc, argv); |
53 |
|
|
|
54 |
✓ |
2 |
const OptionMode & defaultMode = parser.getDefaultMode(); |
55 |
|
4 |
std::vector<std::string> vecInputFile; |
56 |
✓ |
2 |
std::string outputFile(""); |
57 |
✓✓ |
2 |
defaultMode.getValue(vecInputFile, "input"); |
58 |
✓✓ |
2 |
defaultMode.getValue(outputFile, "output"); |
59 |
✓ |
2 |
return mergeMock(vecInputFile, outputFile) - 1; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|