PhoenixClockMock  1.0.0
Tool to manipulate mock of clock
Loading...
Searching...
No Matches
main_restore.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include "OptionParser.h"
8
10
12
14OptionParser createOptionParser(){
15 OptionParser parser(true, __PROGRAM_VERSION__);
16 parser.setExampleLongOption("phoenix_clock_mock_restore --input=file.clockmock");
17 parser.setExampleShortOption("phoenix_clock_mock_restore -i file2.mock file2.clockmock");
18
19 parser.addOption("input", "i", OptionType::FILENAME, true, "List of input clock mock to be restored");
20 return parser;
21}
22
24
27bool restoreMockFile(const PPath & inputFile){
28 size_t fileSize(inputFile.getFileSize());
29 size_t nbClockTime = ((fileSize - sizeof(size_t))*(fileSize >= sizeof(size_t) ))/sizeof(size_t);
30 FILE* fp = fopen(inputFile.c_str(), "r+");
31 if(fp == NULL){
32 std::cerr << "restoreMockFile : cannot open file '"<<inputFile<<"'" << std::endl;
33 return false;
34 }
35 fseek(fp, 0l, SEEK_SET);
36 bool b = data_save(fp, nbClockTime);
37 fseek(fp, 0l, SEEK_END);
38 fclose(fp);
39 return b;
40}
41
43
46bool restoreAllMock(const std::vector<PPath> & vecInputFile){
47 bool b(true);
48 for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end(); ++itFile){
49 b &= restoreMockFile(*itFile);
50 }
51 return b;
52}
53
54int main(int argc, char** argv){
55 OptionParser parser = createOptionParser();
56 parser.parseArgument(argc, argv);
57 const OptionMode & defaultMode = parser.getDefaultMode();
58 std::vector<PPath> vecInputFile;
59 defaultMode.getValue(vecInputFile, "input");
60 return restoreAllMock(vecInputFile) - 1;
61}
62
63
int main(int argc, char **argv)
bool restoreAllMock(const std::vector< PPath > &vecInputFile)
Restore all mock files.
OptionParser createOptionParser()
Create the OptionParser of this program.
bool restoreMockFile(const PPath &inputFile)
Restore a mock file.