1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "DF_definitions.hxx"
23 #include "DF_Label.hxx"
24 #include "DF_Container.hxx"
28 //Static method that returns an ID of the give type of attributes
29 const string& DF_Container::GetID()
31 static string id = "DF_Container_srn";
35 //Creates if not exists a Container attribute and places if is not placed it the Label
36 DF_Container* DF_Container::Set(DF_Label& theLabel)
38 DF_Attribute* attr = NULL;
39 if(!(attr = theLabel.FindAttribute(DF_Container::GetID()))) {
40 attr = new DF_Container;
41 theLabel.AddAttribute(attr);
44 return dynamic_cast<DF_Container*>(attr);
48 DF_Container::DF_Container()
57 DF_Container::~DF_Container()
65 //Sets an integer value of the attribute with given ID
66 void DF_Container::SetInt(const string& theID, int theValue)
68 _ints[theID] = theValue;
71 //Returns an integer value of the attribute with given ID
72 int DF_Container::GetInt(const string& theID)
79 //Returns True if there is an integer with given ID
80 bool DF_Container::HasIntID(const string& theID)
82 if(_ints.find(theID) != _ints.end()) return true;
86 //Sets a double value of the attribute with given ID
87 void DF_Container::SetDouble(const string& theID, const double& theValue)
89 _doubles[theID] = theValue;
93 //Returns a double value of the attribute with given ID
94 double DF_Container::GetDouble(const string& theID)
96 if(!HasDoubleID(theID)) return 0.0;
97 return _doubles[theID];
100 //Returns True if there is a double with given ID
101 bool DF_Container::HasDoubleID(const string& theID)
103 if(_doubles.find(theID) != _doubles.end()) return true;
107 //Sets a string value of the attribute with given ID
108 void DF_Container::SetString(const string& theID, const string& theValue)
110 _strings[theID] = theValue;
113 //Returns a string value of the attribute with given ID
114 string DF_Container::GetString(const string& theID)
116 if(!HasStringID(theID)) return "";
117 return _strings[theID];
120 //Returns True if there is a string with given ID
121 bool DF_Container::HasStringID(const string& theID)
123 if(_strings.find(theID) != _strings.end()) return true;
127 //Sets a boolean value of the attribute with given ID
128 void DF_Container::SetBool(const string& theID, bool theValue)
130 _bools[theID] = theValue;
133 //Returns a boolean value of the attribute with given ID
134 bool DF_Container::GetBool(const string& theID)
136 if(!HasBoolID(theID)) return false;
137 return _bools[theID];
140 //Returns True if there is a boolean value with given ID
141 bool DF_Container::HasBoolID(const string& theID)
143 if(_bools.find(theID) != _bools.end()) return true;
147 //Clears a content of the attribute
148 void DF_Container::Clear()
156 //ID is a string that uniquely identify the given type of Attributes within the Application.
157 const string& DF_Container::ID() const
162 //Restores a content of this Attribute from another Attribute
163 void DF_Container::Restore(DF_Attribute* theAttribute)
167 DF_Container* attr = dynamic_cast<DF_Container*>(theAttribute);
170 typedef map<string, int>::const_iterator SI;
171 for(SI p = attr->_ints.begin(); p != attr->_ints.end(); p++)
172 _ints[p->first] = p->second;
174 typedef map<string, double>::const_iterator SD;
175 for(SD p = attr->_doubles.begin(); p != attr->_doubles.end(); p++)
176 _doubles[p->first] = p->second;
178 typedef map<string, string>::const_iterator SS;
179 for(SS p = attr->_strings.begin(); p != attr->_strings.end(); p++)
180 _strings[p->first] = p->second;
182 typedef map<string, bool>::const_iterator SB;
183 for(SB p = attr->_bools.begin(); p != attr->_bools.end(); p++)
184 _bools[p->first] = p->second;
187 //Creates a new empty copy oà this Attribute
188 DF_Attribute* DF_Container::NewEmpty() const
190 return new DF_Container();
193 //Pastes a content of this Attribute into another Attribute
194 void DF_Container::Paste(DF_Attribute* theIntoAttribute)
196 DF_Container* attr = dynamic_cast<DF_Container*>(theIntoAttribute);
201 typedef map<string, int>::const_iterator SI;
202 for(SI p = _ints.begin(); p != _ints.end(); p++)
203 attr->_ints[p->first] = p->second;
205 typedef map<string, double>::const_iterator SD;
206 for(SD p = _doubles.begin(); p != _doubles.end(); p++)
207 attr->_doubles[p->first] = p->second;
209 typedef map<string, string>::const_iterator SS;
210 for(SS p = _strings.begin(); p != _strings.end(); p++)
211 attr->_strings[p->first] = p->second;
213 typedef map<string, bool>::const_iterator SB;
214 for(SB p = _bools.begin(); p != _bools.end(); p++)
215 attr-> _bools[p->first] = p->second;