Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/kernel.git] / src / DF / DF_Container.cxx
1 #include "DF_definitions.hxx"
2 #include "DF_Label.hxx"
3 #include "DF_Container.hxx"
4
5 using namespace std;
6
7 //Static method that returns an ID of the give type of attributes
8 const string& DF_Container::GetID()
9 {
10   static string id = "DF_Container_srn";
11   return id;
12 }
13
14 //Creates if not exists a Container attribute and places if is not placed it the Label
15 DF_Container* DF_Container::Set(DF_Label& theLabel) 
16 {
17   DF_Attribute* attr = NULL;
18   if(!(attr = theLabel.FindAttribute(DF_Container::GetID()))) {
19     attr = new DF_Container;
20     theLabel.AddAttribute(attr);
21   }
22   
23   return dynamic_cast<DF_Container*>(attr);
24 }
25
26 //Constructor
27 DF_Container::DF_Container() 
28 {
29   _ints.clear();
30   _doubles.clear();
31   _bools.clear();
32   _strings.clear();
33 }
34
35 //Destructor
36 DF_Container::~DF_Container() 
37 {
38   _ints.clear();
39   _doubles.clear();
40   _bools.clear();
41   _strings.clear();
42 }
43
44 //Sets an integer value of the attribute with given ID
45 void DF_Container::SetInt(const string& theID, int theValue) 
46 {
47   _ints[theID] = theValue;
48 }
49
50 //Returns an integer value of the attribute with given ID
51 int DF_Container::GetInt(const string& theID) 
52 {
53   if(!HasIntID(theID)) 
54     return 0;
55   return _ints[theID];
56 }
57
58 //Returns True if there is an integer with given ID
59 bool DF_Container::HasIntID(const string& theID) 
60 {
61   if(_ints.find(theID) != _ints.end()) return true;
62   return false;
63 }
64
65 //Sets a double value of the attribute with given ID
66 void DF_Container::SetDouble(const string& theID, const double& theValue) 
67 {
68   _doubles[theID] = theValue;
69 }
70
71
72 //Returns a double value of the attribute with given ID
73 double DF_Container::GetDouble(const string& theID) 
74 {
75   if(!HasDoubleID(theID)) return 0.0;
76   return _doubles[theID];
77 }
78
79 //Returns True if there is a double with given ID
80 bool DF_Container::HasDoubleID(const string& theID) 
81 {
82   if(_doubles.find(theID) != _doubles.end()) return true;
83   return false;
84 }
85  
86 //Sets a string value of the attribute with given ID
87 void DF_Container::SetString(const string& theID, const string& theValue) 
88 {
89   _strings[theID] = theValue;
90 }
91
92 //Returns a string  value of the attribute with given ID
93 string DF_Container::GetString(const string& theID) 
94 {
95   if(!HasStringID(theID)) return "";
96   return _strings[theID];
97 }
98
99 //Returns True if there is a string with given ID
100 bool DF_Container::HasStringID(const string& theID) 
101 {
102   if(_strings.find(theID) != _strings.end()) return true;
103   return false;
104 }
105
106 //Sets a boolean value of the attribute with given ID
107 void DF_Container::SetBool(const string& theID, bool theValue) 
108 {
109   _bools[theID] = theValue;
110 }
111
112 //Returns a boolean value of the attribute with given ID
113 bool DF_Container::GetBool(const string& theID) 
114 {
115   if(!HasBoolID(theID)) return false;
116   return _bools[theID];
117 }
118
119 //Returns True if there is a boolean value with given ID
120 bool DF_Container::HasBoolID(const string& theID) 
121 {
122   if(_bools.find(theID) != _bools.end()) return true;
123   return false;
124 }
125
126 //Clears a content of the attribute
127 void DF_Container::Clear()
128 {
129   _ints.clear();
130   _doubles.clear();
131   _strings.clear();
132   _bools.clear();
133 }
134
135 //ID is a string that uniquely identify the given type of Attributes within the Application.
136 const string& DF_Container::ID() const
137 {
138   return GetID();
139 }
140
141 //Restores a content of this Attribute from another Attribute
142 void DF_Container::Restore(DF_Attribute* theAttribute) 
143 {
144   Clear();
145
146   DF_Container* attr = dynamic_cast<DF_Container*>(theAttribute);
147   if(!attr) return;
148
149   typedef map<string, int>::const_iterator SI;
150   for(SI p = attr->_ints.begin(); p != attr->_ints.end(); p++) 
151     _ints[p->first] = p->second;
152
153   typedef map<string, double>::const_iterator SD;
154   for(SD p = attr->_doubles.begin(); p != attr->_doubles.end(); p++) 
155     _doubles[p->first] = p->second;
156
157   typedef map<string, string>::const_iterator SS;
158   for(SS p = attr->_strings.begin(); p != attr->_strings.end(); p++) 
159     _strings[p->first] = p->second;
160
161   typedef map<string, bool>::const_iterator SB;
162   for(SB p = attr->_bools.begin(); p != attr->_bools.end(); p++) 
163     _bools[p->first] = p->second;
164 }
165
166 //Creates a new empty copy oà this Attribute
167 DF_Attribute* DF_Container::NewEmpty() const 
168 {
169   return new DF_Container();
170 }
171
172 //Pastes a content of this Attribute into another Attribute 
173 void DF_Container::Paste(DF_Attribute* theIntoAttribute) 
174 {
175   DF_Container* attr = dynamic_cast<DF_Container*>(theIntoAttribute);
176   if(!attr) return;  
177
178   attr->Clear();
179
180   typedef map<string, int>::const_iterator SI;
181   for(SI p = _ints.begin(); p != _ints.end(); p++) 
182     attr->_ints[p->first] = p->second;
183
184   typedef map<string, double>::const_iterator SD;
185   for(SD p = _doubles.begin(); p != _doubles.end(); p++) 
186     attr->_doubles[p->first] = p->second;
187
188   typedef map<string, string>::const_iterator SS;
189   for(SS p = _strings.begin(); p != _strings.end(); p++) 
190     attr->_strings[p->first] = p->second;
191
192   typedef map<string, bool>::const_iterator SB;
193   for(SB p = _bools.begin(); p != _bools.end(); p++) 
194    attr-> _bools[p->first] = p->second;
195 }
196