5aefc683cb8b1124abca059c018547b60fb7f657
[occt.git] / src / TDataStd / TDataStd_Integer.cxx
1 // Created on: 1997-03-06
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TDataStd_Integer.hxx>
18
19 #include <Standard_Dump.hxx>
20 #include <Standard_GUID.hxx>
21 #include <Standard_Type.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_Reference.hxx>
25 #include <TDF_RelocationTable.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Integer,TDF_Attribute)
28
29 //=======================================================================
30 //function : GetID
31 //purpose  : 
32 //=======================================================================
33 const Standard_GUID& TDataStd_Integer::GetID() 
34
35   static Standard_GUID TDataStd_IntegerID ("2a96b606-ec8b-11d0-bee7-080009dc3333");
36   return TDataStd_IntegerID; 
37 }
38
39 //=======================================================================
40 //function : SetAttr
41 //purpose  : Implements Set functionality
42 //=======================================================================
43 static Handle(TDataStd_Integer) SetAttr(const TDF_Label&     label,
44                                         const Standard_Integer  V,
45                                         const Standard_GUID& theGuid)
46 {
47   Handle(TDataStd_Integer) A;
48   if (!label.FindAttribute(theGuid, A)) {
49     A = new TDataStd_Integer ();
50     A->SetID(theGuid);
51     label.AddAttribute(A);
52   }
53   A->Set (V); 
54   return A;
55 }
56
57 //=======================================================================
58 //function : Set
59 //purpose  : 
60 //=======================================================================
61
62 Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label&        L,
63                                                 const Standard_Integer  V) 
64
65 {
66   return SetAttr(L, V, GetID());
67 }
68
69 //=======================================================================
70 //function : Set
71 //purpose  : Set user defined attribute
72 //=======================================================================
73
74 Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label&    L,
75                                                 const Standard_GUID& theGuid,
76                                                 const Standard_Integer V) 
77 {
78   return SetAttr(L, V, theGuid);
79 }
80 //=======================================================================
81 //function : TDataStd_Integer
82 //purpose  : Empty Constructor
83 //=======================================================================
84
85 TDataStd_Integer::TDataStd_Integer ()
86      : myValue (-1), myID(GetID())
87  { }
88
89
90 //=======================================================================
91 //function : Set
92 //purpose  : 
93 //=======================================================================
94
95 void TDataStd_Integer::Set(const Standard_Integer v) 
96 {
97   // OCC2932 correction
98   if(myValue == v) return;
99
100   Backup();
101   myValue = v;
102 }
103
104
105 //=======================================================================
106 //function : Get
107 //purpose  : 
108 //=======================================================================
109
110 Standard_Integer TDataStd_Integer::Get () const { return myValue; }
111
112
113 //=======================================================================
114 //function : IsCaptured
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Boolean TDataStd_Integer::IsCaptured() const
119 {
120   Handle(TDF_Reference) R;
121   return (Label().FindAttribute(TDF_Reference::GetID(),R));
122 }
123
124 //=======================================================================
125 //function : ID
126 //purpose  : 
127 //=======================================================================
128
129 const Standard_GUID& TDataStd_Integer::ID () const { return myID; }
130
131 //=======================================================================
132 //function : SetID
133 //purpose  :
134 //=======================================================================
135
136 void TDataStd_Integer::SetID( const Standard_GUID&  theGuid)
137 {  
138   if(myID == theGuid) return;
139
140   Backup();
141   myID = theGuid;
142 }
143
144 //=======================================================================
145 //function : SetID
146 //purpose  : sets default ID
147 //=======================================================================
148 void TDataStd_Integer::SetID()
149 {
150   Backup();
151   myID = GetID();
152 }
153
154 //=======================================================================
155 //function : NewEmpty
156 //purpose  : 
157 //=======================================================================
158
159 Handle(TDF_Attribute) TDataStd_Integer::NewEmpty () const
160 {
161   return new TDataStd_Integer();
162 }
163
164 //=======================================================================
165 //function : Restore
166 //purpose  : 
167 //=======================================================================
168
169 void TDataStd_Integer::Restore(const Handle(TDF_Attribute)& With) 
170 {
171   Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (With);
172   myValue = anInt->Get();
173   myID = anInt->ID();
174 }
175
176 //=======================================================================
177 //function : Paste
178 //purpose  : 
179 //=======================================================================
180
181 void TDataStd_Integer::Paste (const Handle(TDF_Attribute)& Into,
182                               const Handle(TDF_RelocationTable)& /*RT*/) const
183 {
184   Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (Into);
185   anInt->Set(myValue);
186   anInt->SetID(myID);
187 }
188
189 //=======================================================================
190 //function : Dump
191 //purpose  : 
192 //=======================================================================
193
194 Standard_OStream& TDataStd_Integer::Dump (Standard_OStream& anOS) const
195 {  
196   anOS << "Integer:: "<< this <<" : ";
197   anOS << myValue; 
198   Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
199   myID.ToCString(sguid);
200   anOS << sguid;
201 //
202   anOS <<"\nAttribute fields: ";
203   TDF_Attribute::Dump(anOS);
204   return anOS;
205 }
206
207 //=======================================================================
208 //function : DumpJson
209 //purpose  : 
210 //=======================================================================
211 void TDataStd_Integer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
212 {
213   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
214
215   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
216
217   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValue)
218   OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)
219 }