main.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nlsr-runner.hpp"
23 #include "version.hpp"
24 
25 #include <boost/exception/get_error_info.hpp>
26 #include <sstream>
27 
28 template<typename E>
29 std::string
30 getExtendedErrorMessage(const E& exception)
31 {
32  std::ostringstream errorMessage;
33  errorMessage << exception.what();
34 
35  const char* const* file = boost::get_error_info<boost::throw_file>(exception);
36  const int* line = boost::get_error_info<boost::throw_line>(exception);
37  const char* const* func = boost::get_error_info<boost::throw_function>(exception);
38  if (file && line) {
39  errorMessage << " [from " << *file << ":" << *line;
40  if (func) {
41  errorMessage << " in " << *func;
42  }
43  errorMessage << "]";
44  }
45 
46  return errorMessage.str();
47 }
48 
49 int
50 main(int32_t argc, char** argv)
51 {
52  using namespace nlsr;
53 
54  std::string programName(argv[0]);
55 
56  std::string configFileName = "nlsr.conf";
57 
58  int32_t opt;
59  while ((opt = getopt(argc, argv, "df:hV")) != -1) {
60  switch (opt) {
61  case 'f':
62  configFileName = optarg;
63  break;
64  case 'V':
65  std::cout << NLSR_VERSION_BUILD_STRING << std::endl;
66  return EXIT_SUCCESS;
67  break;
68  case 'h':
69  default:
70  NlsrRunner::printUsage(programName);
71  return EXIT_FAILURE;
72  }
73  }
74 
75  NlsrRunner runner(configFileName);
76 
77  try {
78  runner.run();
79  }
80  catch (const std::exception& e) {
81  std::cerr << getExtendedErrorMessage(e) << std::endl;
82  return EXIT_FAILURE;
83  }
84 
85  return EXIT_SUCCESS;
86 }
A wrapper class to instantiate and configure an NLSR object.
Definition: nlsr-runner.hpp:44
int main(int32_t argc, char **argv)
Definition: main.cpp:50
std::string getExtendedErrorMessage(const E &exception)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: main.cpp:30
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void run()
Instantiate, configure, and start the NLSR process.
Definition: nlsr-runner.cpp:39
static void printUsage(const std::string &programName)
Definition: nlsr-runner.cpp:72