1 #include "DF_definitions.hxx"
2 #include "DF_Label.hxx"
3 #include "DF_Container.hxx"
7 //Static method that returns an ID of the give type of attributes
8 const string& DF_Container::GetID()
10 static string id = "DF_Container_srn";
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)
17 DF_Attribute* attr = NULL;
18 if(!(attr = theLabel.FindAttribute(DF_Container::GetID()))) {
19 attr = new DF_Container;
20 theLabel.AddAttribute(attr);
23 return dynamic_cast<DF_Container*>(attr);
27 DF_Container::DF_Container()
36 DF_Container::~DF_Container()
44 //Sets an integer value of the attribute with given ID
45 void DF_Container::SetInt(const string& theID, int theValue)
47 _ints[theID] = theValue;
50 //Returns an integer value of the attribute with given ID
51 int DF_Container::GetInt(const string& theID)
58 //Returns True if there is an integer with given ID
59 bool DF_Container::HasIntID(const string& theID)
61 if(_ints.find(theID) != _ints.end()) return true;
65 //Sets a double value of the attribute with given ID
66 void DF_Container::SetDouble(const string& theID, const double& theValue)
68 _doubles[theID] = theValue;
72 //Returns a double value of the attribute with given ID
73 double DF_Container::GetDouble(const string& theID)
75 if(!HasDoubleID(theID)) return 0.0;
76 return _doubles[theID];
79 //Returns True if there is a double with given ID
80 bool DF_Container::HasDoubleID(const string& theID)
82 if(_doubles.find(theID) != _doubles.end()) return true;
86 //Sets a string value of the attribute with given ID
87 void DF_Container::SetString(const string& theID, const string& theValue)
89 _strings[theID] = theValue;
92 //Returns a string value of the attribute with given ID
93 string DF_Container::GetString(const string& theID)
95 if(!HasStringID(theID)) return "";
96 return _strings[theID];
99 //Returns True if there is a string with given ID
100 bool DF_Container::HasStringID(const string& theID)
102 if(_strings.find(theID) != _strings.end()) return true;
106 //Sets a boolean value of the attribute with given ID
107 void DF_Container::SetBool(const string& theID, bool theValue)
109 _bools[theID] = theValue;
112 //Returns a boolean value of the attribute with given ID
113 bool DF_Container::GetBool(const string& theID)
115 if(!HasBoolID(theID)) return false;
116 return _bools[theID];
119 //Returns True if there is a boolean value with given ID
120 bool DF_Container::HasBoolID(const string& theID)
122 if(_bools.find(theID) != _bools.end()) return true;
126 //Clears a content of the attribute
127 void DF_Container::Clear()
135 //ID is a string that uniquely identify the given type of Attributes within the Application.
136 const string& DF_Container::ID() const
141 //Restores a content of this Attribute from another Attribute
142 void DF_Container::Restore(DF_Attribute* theAttribute)
146 DF_Container* attr = dynamic_cast<DF_Container*>(theAttribute);
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;
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;
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;
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;
166 //Creates a new empty copy oà this Attribute
167 DF_Attribute* DF_Container::NewEmpty() const
169 return new DF_Container();
172 //Pastes a content of this Attribute into another Attribute
173 void DF_Container::Paste(DF_Attribute* theIntoAttribute)
175 DF_Container* attr = dynamic_cast<DF_Container*>(theIntoAttribute);
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;
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;
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;
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;