author | Florian Pose <fp@igh-essen.com> |
Fri, 25 Jul 2008 14:10:04 +0000 | |
changeset 1149 | f1fce286d53b |
parent 1146 | f18d124d7fbc |
child 1151 | 1fc1535dec29 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#ifndef __COMMAND_H__ |
|
8 |
#define __COMMAND_H__ |
|
9 |
||
10 |
#include <stdexcept> |
|
11 |
#include <vector> |
|
12 |
using namespace std; |
|
13 |
||
14 |
#include "MasterDevice.h" |
|
15 |
||
16 |
/*****************************************************************************/ |
|
17 |
||
18 |
extern unsigned int masterIndex; |
|
19 |
extern int slavePosition; |
|
20 |
extern int domainIndex; |
|
21 |
extern string dataTypeStr; |
|
22 |
extern bool force; |
|
23 |
||
24 |
/****************************************************************************/ |
|
25 |
||
26 |
class InvalidUsageException: |
|
27 |
public runtime_error |
|
28 |
{ |
|
29 |
friend class Command; |
|
30 |
||
31 |
protected: |
|
32 |
/** Constructor with stringstream parameter. */ |
|
33 |
InvalidUsageException( |
|
34 |
const stringstream &s /**< Message. */ |
|
35 |
): runtime_error(s.str()) {} |
|
36 |
}; |
|
37 |
||
38 |
/****************************************************************************/ |
|
39 |
||
40 |
class CommandException: |
|
41 |
public runtime_error |
|
42 |
{ |
|
43 |
friend class Command; |
|
44 |
||
45 |
protected: |
|
46 |
/** Constructor with stringstream parameter. */ |
|
47 |
CommandException( |
|
48 |
const stringstream &s /**< Message. */ |
|
49 |
): runtime_error(s.str()) {} |
|
50 |
}; |
|
51 |
||
52 |
/****************************************************************************/ |
|
53 |
||
54 |
class Command |
|
55 |
{ |
|
56 |
public: |
|
57 |
Command(const string &, const string &); |
|
58 |
virtual ~Command(); |
|
59 |
||
60 |
enum Verbosity { |
|
61 |
Quiet, |
|
62 |
Normal, |
|
63 |
Verbose |
|
64 |
}; |
|
65 |
void setVerbosity(Verbosity); |
|
66 |
||
67 |
const string &getName() const; |
|
68 |
const string &getBriefDescription() const; |
|
69 |
Verbosity getVerbosity() const; |
|
70 |
||
71 |
bool matchesSubstr(const string &) const; |
|
72 |
bool matchesAbbrev(const string &) const; |
|
73 |
||
74 |
virtual string helpString() const = 0; |
|
75 |
||
76 |
typedef vector<string> StringVector; |
|
77 |
virtual void execute(MasterDevice &, const StringVector &) = 0; |
|
78 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
79 |
static string numericInfo(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
80 |
|
1142 | 81 |
protected: |
82 |
void throwInvalidUsageException(const stringstream &); |
|
83 |
void throwCommandException(const stringstream &); |
|
84 |
||
85 |
enum {BreakAfterBytes = 16}; |
|
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
86 |
|
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
87 |
static string alStateString(uint8_t); |
1142 | 88 |
|
89 |
private: |
|
90 |
string name; |
|
91 |
string briefDesc; |
|
92 |
Verbosity verbosity; |
|
93 |
||
94 |
Command(); |
|
95 |
}; |
|
96 |
||
97 |
/****************************************************************************/ |
|
98 |
||
99 |
inline const string &Command::getName() const |
|
100 |
{ |
|
101 |
return name; |
|
102 |
} |
|
103 |
||
104 |
/****************************************************************************/ |
|
105 |
||
106 |
inline const string &Command::getBriefDescription() const |
|
107 |
{ |
|
108 |
return briefDesc; |
|
109 |
} |
|
110 |
||
111 |
/****************************************************************************/ |
|
112 |
||
113 |
inline Command::Verbosity Command::getVerbosity() const |
|
114 |
{ |
|
115 |
return verbosity; |
|
116 |
} |
|
117 |
||
118 |
/****************************************************************************/ |
|
119 |
||
120 |
#endif |