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 | #include "EnumItem.hh" |
15 | #include "Value.hh" | |
16 | ||
17 | namespace Common { | |
18 | ||
19 | // ================================= | |
20 | // ===== EnumItem | |
21 | // ================================= | |
22 | ||
23 | EnumItem::EnumItem(Identifier *p_name, Value *p_value) | |
24 | : Node(), Location(), name(p_name), value(p_value) | |
25 | { | |
26 | if (!p_name) FATAL_ERROR("NULL parameter: Common::EnumItem::EnumItem()"); | |
27 | } | |
28 | ||
29 | EnumItem::EnumItem(const EnumItem& p) | |
30 | : Node(p), Location(p) | |
31 | { | |
32 | name=p.name->clone(); | |
33 | value=p.value?p.value->clone():0; | |
34 | } | |
35 | ||
36 | EnumItem::~EnumItem() | |
37 | { | |
38 | delete name; | |
39 | delete value; | |
40 | } | |
41 | ||
42 | EnumItem *EnumItem::clone() const | |
43 | { | |
44 | return new EnumItem(*this); | |
45 | } | |
46 | ||
47 | void EnumItem::set_fullname(const string& p_fullname) | |
48 | { | |
49 | Node::set_fullname(p_fullname); | |
50 | if(value) value->set_fullname(p_fullname); | |
51 | } | |
52 | ||
53 | void EnumItem::set_my_scope(Scope *p_scope) | |
54 | { | |
55 | if(value) value->set_my_scope(p_scope); | |
56 | } | |
57 | ||
58 | void EnumItem::set_value(Value *p_value) | |
59 | { | |
60 | if(!p_value) FATAL_ERROR("NULL parameter: Common::EnumItem::set_value()"); | |
61 | if(value) FATAL_ERROR("Common::EnumItem::set_value()"); | |
62 | value=p_value; | |
63 | } | |
64 | ||
65 | void EnumItem::set_text(const string& p_text) | |
66 | { | |
67 | text = p_text; | |
68 | } | |
69 | ||
970ed795 EL |
70 | void EnumItem::dump(unsigned level) const |
71 | { | |
72 | name->dump(level); | |
73 | if(value) { | |
74 | DEBUG(level, "with value:"); | |
75 | value->dump(level+1); | |
76 | } | |
77 | } | |
78 | ||
79 | // ================================= | |
80 | // ===== EnumItems | |
81 | // ================================= | |
82 | ||
83 | EnumItems::EnumItems(const EnumItems& p) | |
84 | : Node(p), my_scope(0) | |
85 | { | |
86 | for (size_t i = 0; i < p.eis_v.size(); i++) add_ei(p.eis_v[i]->clone()); | |
87 | } | |
88 | ||
89 | EnumItems::~EnumItems() | |
90 | { | |
91 | for(size_t i = 0; i < eis_v.size(); i++) delete eis_v[i]; | |
92 | eis_v.clear(); | |
93 | eis_m.clear(); | |
94 | } | |
95 | ||
96 | void EnumItems::release_eis() | |
97 | { | |
98 | eis_v.clear(); | |
99 | eis_m.clear(); | |
100 | } | |
101 | ||
102 | EnumItems* EnumItems::clone() const | |
103 | { | |
104 | return new EnumItems(*this); | |
105 | } | |
106 | ||
107 | void EnumItems::set_fullname(const string& p_fullname) | |
108 | { | |
109 | Node::set_fullname(p_fullname); | |
110 | for (size_t i = 0; i < eis_v.size(); i++) { | |
111 | EnumItem *ei = eis_v[i]; | |
112 | ei->set_fullname(p_fullname + "." + ei->get_name().get_dispname()); | |
113 | } | |
114 | } | |
115 | ||
116 | void EnumItems::set_my_scope(Scope *p_scope) | |
117 | { | |
118 | my_scope = p_scope; | |
119 | for(size_t i = 0; i < eis_v.size(); i++) | |
120 | eis_v[i]->set_my_scope(p_scope); | |
121 | } | |
122 | ||
123 | void EnumItems::add_ei(EnumItem *p_ei) | |
124 | { | |
125 | if(!p_ei) | |
126 | FATAL_ERROR("NULL parameter: Common::EnumItems::add_ei()"); | |
127 | eis_v.add(p_ei); | |
128 | const Identifier& id = p_ei->get_name(); | |
129 | const string& name = id.get_name(); | |
130 | if (!eis_m.has_key(name)) eis_m.add(name, p_ei); | |
131 | p_ei->set_fullname(get_fullname()+"."+id.get_dispname()); | |
132 | p_ei->set_my_scope(my_scope); | |
133 | } | |
134 | ||
135 | void EnumItems::dump(unsigned level) const | |
136 | { | |
137 | for (size_t i = 0; i < eis_v.size(); i++) eis_v[i]->dump(level); | |
138 | } | |
139 | ||
140 | } |