Sync with 5.4.0
[deliverable/titan.core.git] / compiler2 / EnumItem.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 #ifndef ENUM_HH_
9 #define ENUM_HH_
10
11 #include "Setting.hh"
12 #include "Identifier.hh"
13
14 namespace Common {
15
16 /**
17 * Class to represent an Enumeration item. Is like a NamedValue, but
18 * the value can be NULL, and a(n integer) value can be assigned
19 * later.
20 */
21 class EnumItem : public Node, public Location {
22 private:
23 Identifier *name;
24 Value *value;
25 string text; ///< for TEXT encoding instruction
26 /** Copy constructor not implemented */
27 EnumItem(const EnumItem&);
28 /** Assignment disabled */
29 EnumItem& operator=(const EnumItem&);
30 public:
31 EnumItem(Identifier *p_name, Value *p_value);
32 virtual ~EnumItem();
33 virtual EnumItem *clone() const;
34 virtual void set_fullname(const string& p_fullname);
35 const Identifier& get_name() const { return *name; }
36 Value *get_value() const { return value; }
37 void set_value(Value *p_value);
38 const string& get_text() const { return text; }
39 void set_text(const string& p_text);
40 virtual void set_my_scope(Scope *p_scope);
41 virtual void dump(unsigned level) const;
42 };
43
44 /**
45 * Class to represent a collection of enumerated items.
46 */
47 class EnumItems : public Node {
48 private:
49 Scope *my_scope;
50 vector<EnumItem> eis_v;
51 /** Stores the first occurrence of EnumItem with id. The string key
52 * refers to the id of the ei, the value is the ei itself. */
53 map<string, EnumItem> eis_m;
54 /** Copy constructor not implemented */
55 EnumItems(const EnumItems& p);
56 /** Assignment disabled */
57 EnumItems& operator=(const EnumItems& p);
58 public:
59 EnumItems() : Node(), my_scope(0), eis_v(), eis_m() { }
60 virtual ~EnumItems();
61 /** Clears the vector and the map, but does not delete the items */
62 void release_eis();
63 virtual EnumItems *clone() const;
64 virtual void set_fullname(const string& p_fullname);
65 void set_my_scope(Scope *p_scope);
66 void add_ei(EnumItem *p_nv);
67 size_t get_nof_eis() const { return eis_v.size(); }
68 EnumItem* get_ei_byIndex(const size_t p_i) { return eis_v[p_i]; }
69 bool has_ei_withName(const Identifier& p_name) const
70 { return eis_m.has_key(p_name.get_name()); }
71 EnumItem* get_ei_byName(const Identifier& p_name) const
72 { return eis_m[p_name.get_name()]; }
73 virtual void dump(unsigned level) const;
74 };
75
76 }
77
78 #endif /* ENUM_HH_ */
This page took 0.051822 seconds and 6 git commands to generate.