Kryptostack
interpreter.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <memory>
8#include <unistd.h>
9#include "context.h"
10#include "helper.h"
11
12
17
18 bool verbose_ = false;
24 Interpreter( const Interpreter& ) = delete;
26 Interpreter& operator=( const Interpreter& ) = delete;
27
28public:
30 static Interpreter * get() {
31 static Interpreter * instance;
32 if( !instance ) instance = new Interpreter;
33 return instance;
34 }
35
38 bool getVerbose() const { return verbose_; }
39
41 Context * getContext() const { return current_; }
42
44 void setContext( Context * p_c ) { current_ = p_c; }
45
48 void commandline( int p_argc, char** p_argv ) {
49 opterr = 0; // shut down GetOpt error messages (return '?')
50
51 while ( int opt = getopt( p_argc, p_argv, "hv" ) != -1 )
52 switch ( opt ) {
53 case 'h':
54 cout << "HELP" << endl;
55 inErrExit( helptext, "help text"); // TODO: implement a small help text
56 break;
57 case 'v':
58 verbose_ = true;
59 cout << "KS:verbose mode activated" << endl;
60 break;
61 case '?':
62 inErrExit( unknownoption, string( "'") + char(optopt) + string("'") );
63 }
64 }
65};
The context of execution.
Definition: context.h:17
Interpreter status.
Definition: interpreter.h:16
public_other void commandline(int p_argc, char **p_argv)
command line parsing.
Definition: interpreter.h:48
Interpreter(const Interpreter &)=delete
delete the copy ctor.
Context * current_
For debugging purposes access to the current Context.
Definition: interpreter.h:19
void setContext(Context *p_c)
Setter for current context.
Definition: interpreter.h:44
static Interpreter * get()
Get the singelton pointer.
Definition: interpreter.h:30
public_accessor bool getVerbose() const
Getter for verbose mode.
Definition: interpreter.h:38
Context * getContext() const
getter for current context.
Definition: interpreter.h:41
Interpreter()
private ctor.
Definition: interpreter.h:22
bool verbose_
Execution in verbose mode or not.
Definition: interpreter.h:18
Interpreter & operator=(const Interpreter &)=delete
delete copy assignement.
The class Context.
#define public_other
other member functions
Definition: helper.h:16
#define public_accessor
accessor functions
Definition: helper.h:14
void inErrExit(InError p_err, const std::string &p_details)
Interpreter Error Message to cout and exit(1).
Definition: helper.cpp:81
Miscellaneous definitions and functions.