Debian Codegraph @

plugins/dm.objectives/Specifier.h

raw
1 #ifndef SPECIFIER_H_
2 #define SPECIFIER_H_
3
4 #include "SpecifierType.h"
5
6 #include <vector>
7 #include <ostream>
8
9 #include <memory>
10
11 namespace objectives {
12
13 class Component;
14
15 /**
16 * A Specifier is a simple data class which combines a SpecifierType with its
17 * associated string value.
18 */
19 class Specifier
20 {
21 // The type
22 SpecifierType _type;
23
24 // The value
25 std::string _value;
26
27 public:
28
29 /**
30 * Main constructor.
31 */
32 Specifier(
33 const SpecifierType& type = SpecifierType::SPEC_NONE(),
34 const std::string& value = ""
35 )
36 : _type(type), _value(value)
37 { }
38
39 /**
40 * Get the SpecifierType.
41 */
42 const SpecifierType& getType() const {
43 return _type;
44 }
45
46 /**
47 * Set the SpecifierType to something new
48 */
49 void setType(const SpecifierType& type) {
50 _type = type;
51 }
52
53 /**
54 * Get the specifier value.
55 */
56 const std::string& getValue() const {
57 return _value;
58 }
59
60 /**
61 * Set the specifier value to the given string.
62 */
63 void setValue(const std::string& value) {
64 _value = value;
65 }
66
67 /**
68 * Get a user-friendly string representing the contents of this Specifier.
69 */
70 std::string toString() const {
71 if (_type == SpecifierType::SPEC_NONE()) {
72 return _type.getDisplayName();
73 }
74 else {
75 return _type.getDisplayName() + " : " + _value;
76 }
77 }
78
79 /**
80 * greebo: Returns a human-readable chunk of text based on the values
81 * found in the given Component object. This is used for the user-friendly
82 * display of components.
83 */
84 std::string getSentence(Component& component);
85
86 public:
87
88 /**
89 * Specifier number enum.
90 */
91 enum SpecifierNumber {
92 FIRST_SPECIFIER,
93 SECOND_SPECIFIER,
94 MAX_SPECIFIERS
95 };
96
97 };
98
99 /**
100 * Specifier pointer type.
101 */
102 typedef std::shared_ptr<Specifier> SpecifierPtr;
103
104 /**
105 * Specifier list type.
106 */
107 typedef std::vector<SpecifierPtr> SpecifierList;
108
109 /**
110 * Stream insertion operator for Specifiers.
111 */
112 inline std::ostream& operator<< (std::ostream& os, const Specifier& spec)
113 {
114 os << "Specifier { type = " << spec.getType().getName()
115 << ", value = " << spec.getValue() << " }";
116 return os;
117 }
118
119 }
120
121 #endif /* SPECIFIER_H_ */