Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Raduly, Csaba | |
11 | * Szabados, Kristof | |
12 | * | |
13 | ******************************************************************************/ | |
970ed795 EL |
14 | #ifndef ENUM_HH_ |
15 | #define ENUM_HH_ | |
16 | ||
17 | #include "Setting.hh" | |
18 | #include "Identifier.hh" | |
19 | ||
20 | namespace Common { | |
21 | ||
22 | /** | |
23 | * Class to represent an Enumeration item. Is like a NamedValue, but | |
24 | * the value can be NULL, and a(n integer) value can be assigned | |
25 | * later. | |
26 | */ | |
27 | class EnumItem : public Node, public Location { | |
28 | private: | |
29 | Identifier *name; | |
30 | Value *value; | |
31 | string text; ///< for TEXT encoding instruction | |
32 | /** Copy constructor not implemented */ | |
33 | EnumItem(const EnumItem&); | |
34 | /** Assignment disabled */ | |
35 | EnumItem& operator=(const EnumItem&); | |
36 | public: | |
37 | EnumItem(Identifier *p_name, Value *p_value); | |
38 | virtual ~EnumItem(); | |
39 | virtual EnumItem *clone() const; | |
40 | virtual void set_fullname(const string& p_fullname); | |
41 | const Identifier& get_name() const { return *name; } | |
970ed795 EL |
42 | Value *get_value() const { return value; } |
43 | void set_value(Value *p_value); | |
44 | const string& get_text() const { return text; } | |
45 | void set_text(const string& p_text); | |
46 | virtual void set_my_scope(Scope *p_scope); | |
47 | virtual void dump(unsigned level) const; | |
48 | }; | |
49 | ||
50 | /** | |
51 | * Class to represent a collection of enumerated items. | |
52 | */ | |
53 | class EnumItems : public Node { | |
54 | private: | |
55 | Scope *my_scope; | |
56 | vector<EnumItem> eis_v; | |
57 | /** Stores the first occurrence of EnumItem with id. The string key | |
58 | * refers to the id of the ei, the value is the ei itself. */ | |
59 | map<string, EnumItem> eis_m; | |
60 | /** Copy constructor not implemented */ | |
61 | EnumItems(const EnumItems& p); | |
62 | /** Assignment disabled */ | |
63 | EnumItems& operator=(const EnumItems& p); | |
64 | public: | |
65 | EnumItems() : Node(), my_scope(0), eis_v(), eis_m() { } | |
66 | virtual ~EnumItems(); | |
67 | /** Clears the vector and the map, but does not delete the items */ | |
68 | void release_eis(); | |
69 | virtual EnumItems *clone() const; | |
70 | virtual void set_fullname(const string& p_fullname); | |
71 | void set_my_scope(Scope *p_scope); | |
72 | void add_ei(EnumItem *p_nv); | |
73 | size_t get_nof_eis() const { return eis_v.size(); } | |
74 | EnumItem* get_ei_byIndex(const size_t p_i) { return eis_v[p_i]; } | |
75 | bool has_ei_withName(const Identifier& p_name) const | |
76 | { return eis_m.has_key(p_name.get_name()); } | |
77 | EnumItem* get_ei_byName(const Identifier& p_name) const | |
78 | { return eis_m[p_name.get_name()]; } | |
79 | virtual void dump(unsigned level) const; | |
80 | }; | |
81 | ||
82 | } | |
83 | ||
84 | #endif /* ENUM_HH_ */ |