diff Resources/CodeGeneration/testCppHandler/main.cpp @ 653:4eccf698e52f

Fixed CRLF to LF in various files (found through grepping the source tree)
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 14 May 2019 13:49:12 +0200
parents 6405435480ae
children 342f3e04bfa9
line wrap: on
line diff
--- a/Resources/CodeGeneration/testCppHandler/main.cpp	Tue May 14 09:49:24 2019 +0200
+++ b/Resources/CodeGeneration/testCppHandler/main.cpp	Tue May 14 13:49:12 2019 +0200
@@ -1,139 +1,139 @@
-#include <string>
-#include <fstream>
-#include <filesystem>
-#include <regex>
-using namespace std;
-namespace fs = std::filesystem;
-
-#include <boost/program_options.hpp>
-using namespace boost::program_options;
-
-#include "VsolMessages_generated.hpp"
-
-/**
-Transforms `str` by replacing occurrences of `oldStr` with `newStr`, using 
-plain text (*not* regular expressions.)
-*/
-static inline void ReplaceInString(
-  string& str,
-  const std::string& oldStr,
-  const std::string& newStr)
-{
-  std::string::size_type pos = 0u;
-  while ((pos = str.find(oldStr, pos)) != std::string::npos) {
-    str.replace(pos, oldStr.length(), newStr);
-    pos += newStr.length();
-  }
-}
-
-string SlurpFile(const string& fileName)
-{
-  ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate);
-
-  ifstream::pos_type fileSize = ifs.tellg();
-  ifs.seekg(0, ios::beg);
-
-  vector<char> bytes(fileSize);
-  ifs.read(bytes.data(), fileSize);
-
-  return string(bytes.data(), fileSize);
-}
-
-class MyHandler : public VsolMessages::IHandler
-{
-public:
-  virtual bool Handle(const VsolMessages::A& value) override
-  {
-    VsolMessages::StoneDumpValue(cout, value);
-    return true;
-  }
-  virtual bool Handle(const VsolMessages::B& value) override
-  {
-    VsolMessages::StoneDumpValue(cout, value);
-    return true;
-  }
-  virtual bool Handle(const VsolMessages::C& value) override
-  {
-    VsolMessages::StoneDumpValue(cout, value);
-    return true;
-  }
-  virtual bool Handle(const VsolMessages::Message1& value) override
-  {
-    VsolMessages::StoneDumpValue(cout, value);
-    return true;
-  }
-  virtual bool Handle(const VsolMessages::Message2& value) override
-  {
-    VsolMessages::StoneDumpValue(cout, value);
-    return true;
-  }
-};
-
-template<typename T>
-void ProcessPath(T filePath)
-{
-  cout << "+--------------------------------------------+\n";
-  cout << "| Processing: " << filePath.path().string() << "\n";
-  cout << "+--------------------------------------------+\n";
-  MyHandler handler;
-  auto contents = SlurpFile(filePath.path().string());
-  VsolMessages::StoneDispatchToHandler(contents, &handler);
-}
-
-int main(int argc, char** argv)
-{
-  try
-  {
-
-    options_description desc("Allowed options");
-    desc.add_options()
-      // First parameter describes option name/short name
-      // The second is parameter to option
-      // The third is description
-      ("help,h", "print usage message")
-      ("pattern,p", value<string>(), "pattern for input")
-      ;
-
-    variables_map vm;
-    store(parse_command_line(argc, argv, desc), vm);
-
-    if (vm.count("help"))
-    {
-      cout << desc << "\n";
-      return 0;
-    }
-
-    notify(vm);
-
-    string pattern = vm["pattern"].as<string>();
-
-    // tranform globbing pattern into regex
-    // we should deal with -, ., *...
-    string regexPatternStr = pattern;
-    cout << "Pattern is: " << regexPatternStr << endl;
-    ReplaceInString(regexPatternStr, "\\", "\\\\");
-    ReplaceInString(regexPatternStr, "-", "\\-");
-    ReplaceInString(regexPatternStr, ".", "\\.");
-    ReplaceInString(regexPatternStr, "*", ".*");
-    ReplaceInString(regexPatternStr, "?", ".");
-    cout << "Corresponding regex is: " << regexPatternStr << endl;
-
-    regex regexPattern(regexPatternStr);
-
-    for (auto& p : fs::directory_iterator("."))
-    {
-      auto fileName = p.path().filename().string();
-      if (regex_match(fileName, regexPattern))
-      {
-        ProcessPath(p);
-      }
-    }
-    return 0;
-
-
-  }
-  catch (exception& e)
-  {
-    cerr << e.what() << "\n";
-  }
+#include <string>
+#include <fstream>
+#include <filesystem>
+#include <regex>
+using namespace std;
+namespace fs = std::filesystem;
+
+#include <boost/program_options.hpp>
+using namespace boost::program_options;
+
+#include "VsolMessages_generated.hpp"
+
+/**
+Transforms `str` by replacing occurrences of `oldStr` with `newStr`, using 
+plain text (*not* regular expressions.)
+*/
+static inline void ReplaceInString(
+  string& str,
+  const std::string& oldStr,
+  const std::string& newStr)
+{
+  std::string::size_type pos = 0u;
+  while ((pos = str.find(oldStr, pos)) != std::string::npos) {
+    str.replace(pos, oldStr.length(), newStr);
+    pos += newStr.length();
+  }
+}
+
+string SlurpFile(const string& fileName)
+{
+  ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate);
+
+  ifstream::pos_type fileSize = ifs.tellg();
+  ifs.seekg(0, ios::beg);
+
+  vector<char> bytes(fileSize);
+  ifs.read(bytes.data(), fileSize);
+
+  return string(bytes.data(), fileSize);
+}
+
+class MyHandler : public VsolMessages::IHandler
+{
+public:
+  virtual bool Handle(const VsolMessages::A& value) override
+  {
+    VsolMessages::StoneDumpValue(cout, value);
+    return true;
+  }
+  virtual bool Handle(const VsolMessages::B& value) override
+  {
+    VsolMessages::StoneDumpValue(cout, value);
+    return true;
+  }
+  virtual bool Handle(const VsolMessages::C& value) override
+  {
+    VsolMessages::StoneDumpValue(cout, value);
+    return true;
+  }
+  virtual bool Handle(const VsolMessages::Message1& value) override
+  {
+    VsolMessages::StoneDumpValue(cout, value);
+    return true;
+  }
+  virtual bool Handle(const VsolMessages::Message2& value) override
+  {
+    VsolMessages::StoneDumpValue(cout, value);
+    return true;
+  }
+};
+
+template<typename T>
+void ProcessPath(T filePath)
+{
+  cout << "+--------------------------------------------+\n";
+  cout << "| Processing: " << filePath.path().string() << "\n";
+  cout << "+--------------------------------------------+\n";
+  MyHandler handler;
+  auto contents = SlurpFile(filePath.path().string());
+  VsolMessages::StoneDispatchToHandler(contents, &handler);
+}
+
+int main(int argc, char** argv)
+{
+  try
+  {
+
+    options_description desc("Allowed options");
+    desc.add_options()
+      // First parameter describes option name/short name
+      // The second is parameter to option
+      // The third is description
+      ("help,h", "print usage message")
+      ("pattern,p", value<string>(), "pattern for input")
+      ;
+
+    variables_map vm;
+    store(parse_command_line(argc, argv, desc), vm);
+
+    if (vm.count("help"))
+    {
+      cout << desc << "\n";
+      return 0;
+    }
+
+    notify(vm);
+
+    string pattern = vm["pattern"].as<string>();
+
+    // tranform globbing pattern into regex
+    // we should deal with -, ., *...
+    string regexPatternStr = pattern;
+    cout << "Pattern is: " << regexPatternStr << endl;
+    ReplaceInString(regexPatternStr, "\\", "\\\\");
+    ReplaceInString(regexPatternStr, "-", "\\-");
+    ReplaceInString(regexPatternStr, ".", "\\.");
+    ReplaceInString(regexPatternStr, "*", ".*");
+    ReplaceInString(regexPatternStr, "?", ".");
+    cout << "Corresponding regex is: " << regexPatternStr << endl;
+
+    regex regexPattern(regexPatternStr);
+
+    for (auto& p : fs::directory_iterator("."))
+    {
+      auto fileName = p.path().filename().string();
+      if (regex_match(fileName, regexPattern))
+      {
+        ProcessPath(p);
+      }
+    }
+    return 0;
+
+
+  }
+  catch (exception& e)
+  {
+    cerr << e.what() << "\n";
+  }
 }
\ No newline at end of file