DiaDes  0.1
DIAgnosis of Discrete-Event System
CmdInterface.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <boost/program_options.hpp>
3 #include "CmdInterface.hh"
4 
15 using namespace std;
16 
17 
18 #ifdef _WIN32
19 #include <windows.h>
20 #endif
21 
22 #include<fstream>
23 #include"CmdInterface.hh"
24 
25 
26 namespace Diades
27 {
28  namespace CmdInterface
29  {
30 
31  namespace Poptions = boost::program_options;
32 
37  FileSuffixes::FileSuffixes(const std::vector<std::string> & suffixes) : _suffixes()
38  {
39  std::transform(suffixes.begin(), suffixes.end(), std::inserter(_suffixes, _suffixes.end()),
40  [&](const std::string & suffix)
41  {
42  return std::make_pair(suffix, std::regex(_fileBase + suffix));
43  });
44  }
45 
53  bool
54  FileSuffixes::match(const std::string & fileName,
55  const std::string & suffix) const
56  {
57  auto it = _suffixes.find(suffix);
58  if(it == _suffixes.end())
59  {
60  return false;
61  }
62  return std::regex_match(fileName, it->second);
63  }
64 
65 
72  size_t
73  printUsage(const string & programName, Poptions::options_description & desc)
74  {
75  std::cout << "Usage: " << programName << "\n" << desc << "\n";
76  return SUCCESS;
77  }
78 
85  size_t
86  printUsage(const string & description)
87  {
88  cout << description << endl;
89  return SUCCESS;
90  }
91 
97  size_t
98  printCommandLineError(const string & msg)
99  {
100  cout << "Error: " << msg << '\n';
101  return ERROR_IN_COMMAND_LINE;
102  }
103 
109  size_t
110  printCommandLineWarning(const string & msg)
111  {
112  cout << "Error: " << msg << '\n';
114  }
115 
116 
117  /*******************************************************************************************************/
118 
127  bool
128  fileSuffixOk(const string & modelFile, const string & suffix)
129  {
130  vector<string> extensions;
131  extensions.push_back(suffix);
132  return Diades::Utils::getFileExtension(modelFile, extensions.begin(), extensions.end()) != extensions.end();
133  }
134 
135  /*******************************************************************************************************/
136 
144  string
145  getSuffix(const string & name)
146  {
147  string::size_type idx = name.rfind('.');
148  if(idx == string::npos)
149  {
150  return "";
151  }
152  return name.substr(idx + 1);
153  }
154 
155  };
156 };
157 
size_t printUsage(const string &programName, Poptions::options_description &desc)
Definition: CmdInterface.cc:73
const size_t SUCCESS
Definition: CmdInterface.hh:34
Some utilities to deal with the command line.
InputIterator getFileExtension(const std::basic_string< CharType, CharTraits > &fileName, InputIterator begin, InputIterator end)
Definition: StringTools.hh:57
std::unordered_map< std::string, std::regex > _suffixes
Definition: CmdInterface.hh:53
size_t printCommandLineError(const string &msg)
Definition: CmdInterface.cc:98
STL namespace.
const size_t ERROR_IN_COMMAND_LINE
Definition: CmdInterface.hh:32
bool match(const std::string &fileName, const std::string &suffix) const
Definition: CmdInterface.cc:54
string getSuffix(const string &name)
const size_t WARNING_IN_COMMAND_LINE
Definition: CmdInterface.hh:33
bool fileSuffixOk(const string &modelFile, const string &suffix)
Namespace of the Diades project.
size_t printCommandLineWarning(const string &msg)
FileSuffixes suffixes({"aut","ddaut"})
string description
Definition: abstract.cc:42