Directory: | ./ |
---|---|
File: | program/main_merge.cpp |
Date: | 2025-03-14 11:49:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 32 | 32 | 100.0% |
Branches: | 39 | 39 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "OptionParser.h" | ||
8 | |||
9 | #include "phoenix_clock_mock.h" | ||
10 | |||
11 | ///Create the OptionParser of this program | ||
12 | /** @return OptionParser of this program | ||
13 | */ | ||
14 | 2 | OptionParser createOptionParser(){ | |
15 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionParser parser(true, __PROGRAM_VERSION__); |
16 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | parser.setExampleLongOption("phoenix_clock_mock_merge --input=file.clockmock --output=merged.clockmock"); |
17 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | parser.setExampleShortOption("phoenix_clock_mock_merge -i file2.clockmock file2.clockmock -o merged.clockmock"); |
18 | |||
19 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be merged"); |
20 | |||
21 |
1/1✓ Branch 1 taken 2 times.
|
2 | PString defaultOutputFile("./merged.clockmock"); |
22 |
5/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | parser.addOption("output", "o", defaultOutputFile, "Name of the output merged mock file"); |
23 | 4 | return parser; | |
24 | 2 | } | |
25 | |||
26 | ///Merge mock files | ||
27 | /** @param vecInputFile : vector of input files to be merged | ||
28 | * @param outputFile : output file name to be saved | ||
29 | * @return true on success, false otherwise | ||
30 | */ | ||
31 | 2 | bool mergeMock(const std::vector<PString> & vecInputFile, const PString & outputFile){ | |
32 | 2 | VecTime vecMessage; | |
33 | 2 | bool b(true); | |
34 |
6/6✓ Branch 4 taken 5 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 2 times.
|
6 | for(std::vector<PString>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){ |
35 | 4 | VecTime vecTmpFile; | |
36 |
3/3✓ Branch 2 taken 4 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
|
4 | if(data_load(*itFile, vecTmpFile)){ |
37 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | concatenateVecTime(vecMessage, vecTmpFile); |
38 | }else{ | ||
39 | 1 | b = false; | |
40 | } | ||
41 | 4 | } | |
42 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(b){ |
43 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= data_save(outputFile, vecMessage); |
44 | } | ||
45 | 2 | return b; | |
46 | 2 | } | |
47 | |||
48 | 2 | int main(int argc, char** argv){ | |
49 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionParser parser = createOptionParser(); |
50 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser.parseArgument(argc, argv); |
51 | |||
52 |
1/1✓ Branch 1 taken 2 times.
|
2 | const OptionMode & defaultMode = parser.getDefaultMode(); |
53 | 2 | std::vector<PString> vecInputFile; | |
54 |
1/1✓ Branch 1 taken 2 times.
|
2 | PString outputFile(""); |
55 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | defaultMode.getValue(vecInputFile, "input"); |
56 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | defaultMode.getValue(outputFile, "output"); |
57 |
1/1✓ Branch 1 taken 2 times.
|
2 | return mergeMock(vecInputFile, outputFile) - 1; |
58 | 2 | } | |
59 | |||
60 | |||
61 |