1 // Created on: 1994-11-04
2 // Created by: Christian CAILLET
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _MoniTool_AttrList_HeaderFile
18 #define _MoniTool_AttrList_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <MoniTool_ValueType.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Real.hxx>
27 #include <NCollection_DataMap.hxx>
28 #include <Standard_Transient.hxx>
29 #include <TCollection_AsciiString.hxx>
31 //! a AttrList allows to record a list of attributes as Transients
32 //! which can be edited, changed ...
33 //! Each one is identified by a name
34 class MoniTool_AttrList
41 //! Creates an AttrList, empty
42 Standard_EXPORT MoniTool_AttrList();
44 //! Creates an AttrList from another one, definitions are shared
45 //! (calls SameAttributes)
46 Standard_EXPORT MoniTool_AttrList(const MoniTool_AttrList& other);
48 //! Adds an attribute with a given name (replaces the former one
49 //! with the same name if already exists)
50 Standard_EXPORT void SetAttribute (const Standard_CString name, const Handle(Standard_Transient)& val);
52 //! Removes an attribute
53 //! Returns True when done, False if this attribute did not exist
54 Standard_EXPORT Standard_Boolean RemoveAttribute (const Standard_CString name);
56 //! Returns an attribute from its name, filtered by a type
57 //! If no attribute has this name, or if it is not kind of this
58 //! type, <val> is Null and returned value is False
60 Standard_EXPORT Standard_Boolean GetAttribute (const Standard_CString name, const Handle(Standard_Type)& type, Handle(Standard_Transient)& val) const;
62 //! Returns an attribute from its name. Null Handle if not
63 //! recorded (whatever Transient, Integer, Real ...)
64 //! Integer is recorded as IntVal
65 //! Real is recorded as RealVal
66 //! Text is recorded as HAsciiString
67 Standard_EXPORT Handle(Standard_Transient) Attribute (const Standard_CString name) const;
69 //! Returns the type of an attribute :
70 //! ValueInt , ValueReal , ValueText (String) , ValueIdent (any)
71 //! or ValueVoid (not recorded)
72 Standard_EXPORT MoniTool_ValueType AttributeType (const Standard_CString name) const;
74 //! Adds an integer value for an attribute
75 Standard_EXPORT void SetIntegerAttribute (const Standard_CString name, const Standard_Integer val);
77 //! Returns an attribute from its name, as integer
78 //! If no attribute has this name, or not an integer,
79 //! <val> is 0 and returned value is False
81 Standard_EXPORT Standard_Boolean GetIntegerAttribute (const Standard_CString name, Standard_Integer& val) const;
83 //! Returns an integer attribute from its name. 0 if not recorded
84 Standard_EXPORT Standard_Integer IntegerAttribute (const Standard_CString name) const;
86 //! Adds a real value for an attribute
87 Standard_EXPORT void SetRealAttribute (const Standard_CString name, const Standard_Real val);
89 //! Returns an attribute from its name, as real
90 //! If no attribute has this name, or not a real
91 //! <val> is 0.0 and returned value is False
93 Standard_EXPORT Standard_Boolean GetRealAttribute (const Standard_CString name, Standard_Real& val) const;
95 //! Returns a real attribute from its name. 0.0 if not recorded
96 Standard_EXPORT Standard_Real RealAttribute (const Standard_CString name) const;
98 //! Adds a String value for an attribute
99 Standard_EXPORT void SetStringAttribute (const Standard_CString name, const Standard_CString val);
101 //! Returns an attribute from its name, as String
102 //! If no attribute has this name, or not a String
103 //! <val> is 0.0 and returned value is False
105 Standard_EXPORT Standard_Boolean GetStringAttribute (const Standard_CString name, Standard_CString& val) const;
107 //! Returns a String attribute from its name. "" if not recorded
108 Standard_EXPORT Standard_CString StringAttribute (const Standard_CString name) const;
110 //! Returns the exhaustive list of attributes
111 Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& AttrList() const;
113 //! Gets the list of attributes from <other>, as such, i.e.
114 //! not copied : attributes are shared, any attribute edited,
115 //! added, or removed in <other> is also in <me> and vice versa
116 //! The former list of attributes of <me> is dropped
117 Standard_EXPORT void SameAttributes (const MoniTool_AttrList& other);
119 //! Gets the list of attributes from <other>, by copying it
120 //! By default, considers all the attributes from <other>
121 //! If <fromname> is given, considers only the attributes with
122 //! name beginning by <fromname>
124 //! For each attribute, if <copied> is True (D), its value is also
125 //! copied if it is a basic type (Integer,Real,String), else it
126 //! remains shared between <other> and <me>
128 //! These new attributes are added to the existing ones in <me>,
129 //! in case of same name, they replace the existing ones
130 Standard_EXPORT void GetAttributes (const MoniTool_AttrList& other, const Standard_CString fromname = "", const Standard_Boolean copied = Standard_True);
145 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> theattrib;
156 #endif // _MoniTool_AttrList_HeaderFile