comparison Resources/CodeGeneration/testCppHandler/main.cpp @ 494:fc17251477d6 bgo-commands-codegen

TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
author bgo-osimis
date Sat, 23 Feb 2019 10:18:13 +0100
parents
children 6405435480ae
comparison
equal deleted inserted replaced
493:6fbf2eae7c88 494:fc17251477d6
1 #include <string>
2 #include <filesystem>
3 #include <regex>
4 using namespace std;
5 namespace fs = std::filesystem;
6
7 #include <boost/program_options.hpp>
8 using namespace boost::program_options;
9
10 #include "VsolMessages_generated.hpp"
11
12 /**
13 Transforms `str` by replacing occurrences of `oldStr` with `newStr`, using
14 plain text (*not* regular expressions.)
15 */
16 static inline void ReplaceInString(
17 string& str,
18 const std::string& oldStr,
19 const std::string& newStr)
20 {
21 std::string::size_type pos = 0u;
22 while ((pos = str.find(oldStr, pos)) != std::string::npos) {
23 str.replace(pos, oldStr.length(), newStr);
24 pos += newStr.length();
25 }
26 }
27
28 int main(int argc, char** argv)
29 {
30 try
31 {
32 string pattern;
33
34 options_description desc("Allowed options");
35 desc.add_options()
36 // First parameter describes option name/short name
37 // The second is parameter to option
38 // The third is description
39 ("help,h", "print usage message")
40 ("pattern,p", value(&pattern), "pattern for input")
41 ;
42
43 variables_map vm;
44 store(parse_command_line(argc, argv, desc), vm);
45
46 if (vm.count("help"))
47 {
48 cout << desc << "\n";
49 return 0;
50 }
51
52 // tranform globbing pattern into regex
53 // we should deal with -, ., *...
54 string regexPatternStr = pattern;
55 regex regexPattern(regexPatternStr);
56
57 for (auto& p : fs::directory_iterator("."))
58 {
59 if (regex_match(p.path().string(), regexPattern))
60 std::cout << "\"" << p << "\" is a match\n";
61 else
62 std::cout << "\"" << p << "\" is *not* a match\n";
63 }
64 return 0;
65
66
67 }
68 catch (exception& e)
69 {
70 cerr << e.what() << "\n";
71 }
72 }