CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
config.cc
Go to the documentation of this file.
1// -*- C++ -*-
12#include <cstdlib>
13#include <iostream>
14#include <map>
15#include <functional>
16#include "base/config.h"
17
18using CNORXZ::String;
19using CNORXZ::SizeT;
20typedef std::map<String,std::function<String(void)>> CMapT;
21
23{
24 CMapT m;
25 m["--version"] = CNORXZ::Config::version;
26 m["--commit"] = CNORXZ::Config::commit;
27 m["--flags"] = CNORXZ::Config::flags;
28 return m;
29}
30
31void printUsage(const String& prog, const CMapT& cm)
32{
33 std::cout << "usage: " << prog << " ";
34 for(const auto& x: cm){
35 std::cout << "[" << x.first << "] ";
36 }
37 std::cout << std::endl;
38}
39
40int main(int argc, char** argv)
41{
42 const String prog(argv[0]);
43 const auto cm = configMap();
44 if(argc == 1){
45 printUsage(prog, cm);
46 }
47 try {
48 for(SizeT i = 1; i != static_cast<SizeT>(argc); ++i){
49 std::cout << cm.at( String(argv[i]) )() << std::endl;
50 }
51 }
52 catch(const std::out_of_range& e){
53 std::cerr << "caught exception: " << e.what() << std::endl;
54 printUsage(prog, cm);
55 return 1;
56 }
57 catch(...){
58 std::cerr << "caught generic exception" << std::endl;
59 }
60
61 return 0;
62}
std::map< String, std::function< String(void)> > CMapT
Definition config.cc:20
void printUsage(const String &prog, const CMapT &cm)
Definition config.cc:31
int main(int argc, char **argv)
Definition config.cc:40
auto configMap()
Definition config.cc:22
Runtime config functions declarations.
String version()
Definition config.cc:20
String commit()
Definition config.cc:25
String flags()
Definition config.cc:30
std::string String
Definition types.h:42
uint64_t SizeT
Definition types.h:38