Titan Core Initial Contribution
[deliverable/titan.core.git] / compiler2 / EnumItem.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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 /// Return the name for the "enum hack"
37 string get_name_hacked(Type *p_type) const;
38 Value *get_value() const { return value; }
39 void set_value(Value *p_value);
40 const string& get_text() const { return text; }
41 void set_text(const string& p_text);
42 virtual void set_my_scope(Scope *p_scope);
43 virtual void dump(unsigned level) const;
44 };
45
46 /**
47 * Class to represent a collection of enumerated items.
48 */
49 class EnumItems : public Node {
50 private:
51 Scope *my_scope;
52 vector<EnumItem> eis_v;
53 /** Stores the first occurrence of EnumItem with id. The string key
54 * refers to the id of the ei, the value is the ei itself. */
55 map<string, EnumItem> eis_m;
56 /** Copy constructor not implemented */
57 EnumItems(const EnumItems& p);
58 /** Assignment disabled */
59 EnumItems& operator=(const EnumItems& p);
60 public:
61 EnumItems() : Node(), my_scope(0), eis_v(), eis_m() { }
62 virtual ~EnumItems();
63 /** Clears the vector and the map, but does not delete the items */
64 void release_eis();
65 virtual EnumItems *clone() const;
66 virtual void set_fullname(const string& p_fullname);
67 void set_my_scope(Scope *p_scope);
68 void add_ei(EnumItem *p_nv);
69 size_t get_nof_eis() const { return eis_v.size(); }
70 EnumItem* get_ei_byIndex(const size_t p_i) { return eis_v[p_i]; }
71 bool has_ei_withName(const Identifier& p_name) const
72 { return eis_m.has_key(p_name.get_name()); }
73 EnumItem* get_ei_byName(const Identifier& p_name) const
74 { return eis_m[p_name.get_name()]; }
75 virtual void dump(unsigned level) const;
76 };
77
78 }
79
80 #endif /* ENUM_HH_ */
This page took 0.038522 seconds and 6 git commands to generate.