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 |
|
|
79 |
protected:
|
|
80 |
void throwInvalidUsageException(const stringstream &);
|
|
81 |
void throwCommandException(const stringstream &);
|
|
82 |
|
|
83 |
enum {BreakAfterBytes = 16};
|
|
84 |
static string numericInfo();
|
|
85 |
|
|
86 |
private:
|
|
87 |
string name;
|
|
88 |
string briefDesc;
|
|
89 |
Verbosity verbosity;
|
|
90 |
|
|
91 |
Command();
|
|
92 |
};
|
|
93 |
|
|
94 |
/****************************************************************************/
|
|
95 |
|
|
96 |
inline const string &Command::getName() const
|
|
97 |
{
|
|
98 |
return name;
|
|
99 |
}
|
|
100 |
|
|
101 |
/****************************************************************************/
|
|
102 |
|
|
103 |
inline const string &Command::getBriefDescription() const
|
|
104 |
{
|
|
105 |
return briefDesc;
|
|
106 |
}
|
|
107 |
|
|
108 |
/****************************************************************************/
|
|
109 |
|
|
110 |
inline Command::Verbosity Command::getVerbosity() const
|
|
111 |
{
|
|
112 |
return verbosity;
|
|
113 |
}
|
|
114 |
|
|
115 |
/****************************************************************************/
|
|
116 |
|
|
117 |
#endif
|