0024788: Foundation Classes - remove Dico_Dictionary
[occt.git] / src / MoniTool / MoniTool_AttrList.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
42cf5bc1 15#include <MoniTool_AttrList.hxx>
7fd59977 16#include <MoniTool_IntVal.hxx>
17#include <MoniTool_RealVal.hxx>
42cf5bc1 18#include <Standard_Transient.hxx>
7fd59977 19#include <TCollection_HAsciiString.hxx>
7fd59977 20
b311480e 21MoniTool_AttrList::MoniTool_AttrList () { }
7fd59977 22
23 MoniTool_AttrList::MoniTool_AttrList (const MoniTool_AttrList& other)
24 : theattrib (other.AttrList()) { }
25
26// #### ATTRIBUTES ####
27
28
29// Integer -> IntVal, Real -> RealVal, CString -> HAsciiString
30
31 void MoniTool_AttrList::SetAttribute
32 (const Standard_CString name, const Handle(Standard_Transient)& val)
33{
997e128f 34 theattrib.Bind(name,val);
7fd59977 35}
36
37 Standard_Boolean MoniTool_AttrList::RemoveAttribute
38 (const Standard_CString name)
39{
997e128f 40 if (theattrib.IsEmpty()) return Standard_False;
41 return theattrib.UnBind(name);
7fd59977 42}
43
44 Standard_Boolean MoniTool_AttrList::GetAttribute
45 (const Standard_CString name, const Handle(Standard_Type)& type,
46 Handle(Standard_Transient)& val) const
47{
997e128f 48 if (theattrib.IsEmpty()) { val.Nullify(); return Standard_False; }
49 if (!theattrib.Find(name, val)) { val.Nullify(); return Standard_False; }
7fd59977 50 if (!val->IsKind(type)) { val.Nullify(); return Standard_False; }
51 return Standard_True;
52}
53
54 Handle(Standard_Transient) MoniTool_AttrList::Attribute
55 (const Standard_CString name) const
56{
57 Handle(Standard_Transient) atr;
997e128f 58 if (theattrib.IsEmpty()) return atr;
59 if (!theattrib.Find(name, atr))
60 atr.Nullify();
7fd59977 61 return atr;
62}
63
64 MoniTool_ValueType MoniTool_AttrList::AttributeType
65 (const Standard_CString name) const
66{
67 Handle(Standard_Transient) atr = Attribute(name);
68 if (atr.IsNull()) return MoniTool_ValueVoid;
69 if (atr->DynamicType() == STANDARD_TYPE(MoniTool_IntVal))
70 return MoniTool_ValueInteger;
71 if (atr->DynamicType() == STANDARD_TYPE(MoniTool_RealVal))
72 return MoniTool_ValueReal;
73 if (atr->DynamicType() == STANDARD_TYPE(TCollection_HAsciiString))
74 return MoniTool_ValueText;
75 return MoniTool_ValueIdent;
76}
77
78
79 void MoniTool_AttrList::SetIntegerAttribute
80 (const Standard_CString name, const Standard_Integer val)
81{
82 Handle(MoniTool_IntVal) ival = new MoniTool_IntVal;
83 ival->CValue() = val;
84 SetAttribute (name, ival);
85}
86
87 Standard_Boolean MoniTool_AttrList::GetIntegerAttribute
88 (const Standard_CString name, Standard_Integer& val) const
89{
90 Handle(MoniTool_IntVal) ival = Handle(MoniTool_IntVal)::DownCast
91 (Attribute(name));
92 if (ival.IsNull()) { val = 0; return Standard_False; }
93 val = ival->Value();
94 return Standard_True;
95}
96
97 Standard_Integer MoniTool_AttrList::IntegerAttribute
98 (const Standard_CString name) const
99{
100 Handle(MoniTool_IntVal) ival = Handle(MoniTool_IntVal)::DownCast
101 (Attribute(name));
102 if (ival.IsNull()) return 0;
103 return ival->Value();
104}
105
106 void MoniTool_AttrList::SetRealAttribute
107 (const Standard_CString name, const Standard_Real val)
108{
109 Handle(MoniTool_RealVal) rval = new MoniTool_RealVal;
110 rval->CValue() = val;
111 SetAttribute (name,rval);
112}
113
114 Standard_Boolean MoniTool_AttrList::GetRealAttribute
115 (const Standard_CString name, Standard_Real& val) const
116{
117 Handle(MoniTool_RealVal) rval = Handle(MoniTool_RealVal)::DownCast
118 (Attribute(name));
119 if (rval.IsNull()) { val = 0.0; return Standard_False; }
120 val = rval->Value();
121 return Standard_True;
122}
123
124 Standard_Real MoniTool_AttrList::RealAttribute (const Standard_CString name) const
125{
126 Handle(MoniTool_RealVal) rval = Handle(MoniTool_RealVal)::DownCast
127 (Attribute(name));
128 if (rval.IsNull()) return 0;
129 return rval->Value();
130}
131
132 void MoniTool_AttrList::SetStringAttribute
133 (const Standard_CString name, const Standard_CString val)
134{
135 Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString (val);
136 SetAttribute (name,hval);
137}
138
139 Standard_Boolean MoniTool_AttrList::GetStringAttribute
140 (const Standard_CString name, Standard_CString& val) const
141{
142 Handle(TCollection_HAsciiString) hval = Handle(TCollection_HAsciiString)::DownCast
143 (Attribute(name));
144 if (hval.IsNull()) { val = ""; return Standard_False; }
145 val = hval->ToCString();
146 return Standard_True;
147}
148
149 Standard_CString MoniTool_AttrList::StringAttribute (const Standard_CString name) const
150{
151 Handle(TCollection_HAsciiString) hval = Handle(TCollection_HAsciiString)::DownCast
152 (Attribute(name));
153 if (hval.IsNull()) return "";
154 return hval->ToCString();
155}
156
997e128f 157 const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& MoniTool_AttrList::AttrList () const
7fd59977 158 { return theattrib; }
159
160 void MoniTool_AttrList::SameAttributes (const MoniTool_AttrList& other)
161 { theattrib = other.AttrList(); }
162
163 void MoniTool_AttrList::GetAttributes
164 (const MoniTool_AttrList& other,
165 const Standard_CString fromname, const Standard_Boolean copied)
166{
997e128f 167 const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& list = other.AttrList();
168 if (list.IsEmpty()) return;
169
170 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator iter(list);
171 for (; iter.More(); iter.Next()) {
172 TCollection_AsciiString name = iter.Key();
173 if (!name.StartsWith(fromname))
174 continue;
7fd59977 175 Handle(Standard_Transient) atr = iter.Value();
176 Handle(Standard_Transient) newatr = atr;
177
178// Copy ? according type
179 if (copied) {
180 Handle(MoniTool_IntVal) ival = Handle(MoniTool_IntVal)::DownCast(atr);
181 if (!ival.IsNull()) {
182 Standard_Integer intval = ival->Value();
183 ival = new MoniTool_IntVal;
184 ival->CValue() = intval;
185 newatr = ival;
186 }
187 Handle(MoniTool_RealVal) rval = Handle(MoniTool_RealVal)::DownCast(atr);
188 if (!rval.IsNull()) {
189 Standard_Real realval = rval->Value();
190 rval = new MoniTool_RealVal;
191 rval->CValue() = realval;
192 newatr = rval;
193 }
194 Handle(TCollection_HAsciiString) hval = Handle(TCollection_HAsciiString)::DownCast(atr);
195 if (!hval.IsNull()) {
196 Handle(TCollection_HAsciiString) strval = new TCollection_HAsciiString
197 (hval->ToCString());
198 newatr = strval;
199 }
200
201 }
997e128f 202 theattrib.Bind(name, newatr);
7fd59977 203 }
204}