1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "DF_definitions.hxx"
21 #include "DF_Label.hxx"
22 #include "DF_Container.hxx"
24 //Static method that returns an ID of the give type of attributes
25 const std::string& DF_Container::GetID()
27 static std::string id = "DF_Container_srn";
31 //Creates if not exists a Container attribute and places if is not placed it the Label
32 DF_Container* DF_Container::Set(DF_Label& theLabel)
34 DF_Attribute* attr = NULL;
35 if(!(attr = theLabel.FindAttribute(DF_Container::GetID()))) {
36 attr = new DF_Container;
37 theLabel.AddAttribute(attr);
40 return dynamic_cast<DF_Container*>(attr);
44 DF_Container::DF_Container()
53 DF_Container::~DF_Container()
61 //Sets an integer value of the attribute with given ID
62 void DF_Container::SetInt(const std::string& theID, int theValue)
64 _ints[theID] = theValue;
67 //Returns an integer value of the attribute with given ID
68 int DF_Container::GetInt(const std::string& theID)
75 //Returns True if there is an integer with given ID
76 bool DF_Container::HasIntID(const std::string& theID)
78 if(_ints.find(theID) != _ints.end()) return true;
82 //Sets a double value of the attribute with given ID
83 void DF_Container::SetDouble(const std::string& theID, const double& theValue)
85 _doubles[theID] = theValue;
89 //Returns a double value of the attribute with given ID
90 double DF_Container::GetDouble(const std::string& theID)
92 if(!HasDoubleID(theID)) return 0.0;
93 return _doubles[theID];
96 //Returns True if there is a double with given ID
97 bool DF_Container::HasDoubleID(const std::string& theID)
99 if(_doubles.find(theID) != _doubles.end()) return true;
103 //Sets a string value of the attribute with given ID
104 void DF_Container::SetString(const std::string& theID, const std::string& theValue)
106 _strings[theID] = theValue;
109 //Returns a string value of the attribute with given ID
110 std::string DF_Container::GetString(const std::string& theID)
112 if(!HasStringID(theID)) return "";
113 return _strings[theID];
116 //Returns True if there is a string with given ID
117 bool DF_Container::HasStringID(const std::string& theID)
119 if(_strings.find(theID) != _strings.end()) return true;
123 //Sets a boolean value of the attribute with given ID
124 void DF_Container::SetBool(const std::string& theID, bool theValue)
126 _bools[theID] = theValue;
129 //Returns a boolean value of the attribute with given ID
130 bool DF_Container::GetBool(const std::string& theID)
132 if(!HasBoolID(theID)) return false;
133 return _bools[theID];
136 //Returns True if there is a boolean value with given ID
137 bool DF_Container::HasBoolID(const std::string& theID)
139 if(_bools.find(theID) != _bools.end()) return true;
143 //Clears a content of the attribute
144 void DF_Container::Clear()
152 //ID is a string that uniquely identify the given type of Attributes within the Application.
153 const std::string& DF_Container::ID() const
158 //Restores a content of this Attribute from another Attribute
159 void DF_Container::Restore(DF_Attribute* theAttribute)
163 DF_Container* attr = dynamic_cast<DF_Container*>(theAttribute);
166 typedef std::map<std::string, int>::const_iterator SI;
167 for(SI p = attr->_ints.begin(); p != attr->_ints.end(); p++)
168 _ints[p->first] = p->second;
170 typedef std::map<std::string, double>::const_iterator SD;
171 for(SD p = attr->_doubles.begin(); p != attr->_doubles.end(); p++)
172 _doubles[p->first] = p->second;
174 typedef std::map<std::string, std::string>::const_iterator SS;
175 for(SS p = attr->_strings.begin(); p != attr->_strings.end(); p++)
176 _strings[p->first] = p->second;
178 typedef std::map<std::string, bool>::const_iterator SB;
179 for(SB p = attr->_bools.begin(); p != attr->_bools.end(); p++)
180 _bools[p->first] = p->second;
183 //Creates a new empty copy oà this Attribute
184 DF_Attribute* DF_Container::NewEmpty() const
186 return new DF_Container();
189 //Pastes a content of this Attribute into another Attribute
190 void DF_Container::Paste(DF_Attribute* theIntoAttribute)
192 DF_Container* attr = dynamic_cast<DF_Container*>(theIntoAttribute);
197 typedef std::map<std::string, int>::const_iterator SI;
198 for(SI p = _ints.begin(); p != _ints.end(); p++)
199 attr->_ints[p->first] = p->second;
201 typedef std::map<std::string, double>::const_iterator SD;
202 for(SD p = _doubles.begin(); p != _doubles.end(); p++)
203 attr->_doubles[p->first] = p->second;
205 typedef std::map<std::string, std::string>::const_iterator SS;
206 for(SS p = _strings.begin(); p != _strings.end(); p++)
207 attr->_strings[p->first] = p->second;
209 typedef std::map<std::string, bool>::const_iterator SB;
210 for(SB p = _bools.begin(); p != _bools.end(); p++)
211 attr-> _bools[p->first] = p->second;