0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / TObj / TObj_TNameContainer.cxx
1 // Created on: 2004-11-23
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // The original implementation Copyright: (C) RINA S.p.A
17
18 #include <TObj_TNameContainer.hxx>
19 #include <Standard_GUID.hxx>
20
21
22 //=======================================================================
23 //function : TObj_TNameContainer
24 //purpose  : 
25 //=======================================================================
26
27 TObj_TNameContainer::TObj_TNameContainer()
28 {
29 }
30
31 //=======================================================================
32 //function : GetID
33 //purpose  : 
34 //=======================================================================
35
36 const Standard_GUID& TObj_TNameContainer::GetID()
37 {
38   static Standard_GUID theID ("3bbefb47-e618-11d4-ba38-0060b0ee18ea");
39   return theID;
40 }
41   
42 //=======================================================================
43 //function : ID
44 //purpose  : 
45 //=======================================================================
46
47 const Standard_GUID& TObj_TNameContainer::ID() const
48 {
49   return GetID();
50 }
51
52 //=======================================================================
53 //function : Set
54 //purpose  : 
55 //=======================================================================
56
57 Handle(TObj_TNameContainer) TObj_TNameContainer::Set(const TDF_Label& theLabel)
58 {
59   Handle(TObj_TNameContainer) A;
60   if (!theLabel.FindAttribute(TObj_TNameContainer::GetID(), A)) 
61   {
62     A = new TObj_TNameContainer;
63     theLabel.AddAttribute(A);
64   }
65   return A;
66 }
67
68 //=======================================================================
69 //function : RecordName
70 //purpose  : 
71 //=======================================================================
72
73 void TObj_TNameContainer::RecordName(const Handle(TCollection_HExtendedString)& theName,
74                                          const TDF_Label& theLabel)
75 {
76   if(!IsRegistered(theName)) 
77   {
78     Backup();
79     myMap.Bind(new TCollection_HExtendedString(theName->String()),theLabel);
80   }
81 }
82
83 //=======================================================================
84 //function : RemoveName
85 //purpose  : 
86 //=======================================================================
87
88 void TObj_TNameContainer::RemoveName(const Handle(TCollection_HExtendedString)& theName)
89 {
90   if(IsRegistered(theName)) 
91   {
92     Backup();
93     myMap.UnBind(theName);
94   }
95 }
96
97 void TObj_TNameContainer::Clear()
98 {
99   Backup();
100   myMap.Clear();
101 }
102
103 //=======================================================================
104 //function : CheckName
105 //purpose  : 
106 //=======================================================================
107
108 Standard_Boolean TObj_TNameContainer::IsRegistered(const Handle(TCollection_HExtendedString)& theName) const
109 {
110   return myMap.IsBound(theName);
111 }
112   
113 //=======================================================================
114 //function : NewEmpty
115 //purpose  : 
116 //=======================================================================
117
118 Handle(TDF_Attribute) TObj_TNameContainer::NewEmpty () const
119 {  
120   return new TObj_TNameContainer();
121 }
122
123 //=======================================================================
124 //function : Restore
125 //purpose  : 
126 //=======================================================================
127
128 void TObj_TNameContainer::Restore(const Handle(TDF_Attribute)& theWith) 
129 {
130   Handle(TObj_TNameContainer) R = Handle(TObj_TNameContainer)::DownCast (theWith);
131   
132   myMap = R->Get();
133 }
134
135 //=======================================================================
136 //function : Paste
137 //purpose  : 
138 //=======================================================================
139
140 void TObj_TNameContainer::Paste (const Handle(TDF_Attribute)& theInto,
141                                      const Handle(TDF_RelocationTable)& /* RT */) const
142
143   Handle(TObj_TNameContainer) R = Handle(TObj_TNameContainer)::DownCast (theInto);
144   R->Set(myMap);
145 }
146
147 //=======================================================================
148 //function : Get
149 //purpose  : 
150 //=======================================================================
151
152 const TObj_DataMapOfNameLabel& TObj_TNameContainer::Get() const
153 {
154   return myMap;
155 }
156
157 //=======================================================================
158 //function : Set
159 //purpose  : 
160 //=======================================================================
161
162 void TObj_TNameContainer::Set(const TObj_DataMapOfNameLabel& theMap)
163 {
164   Backup();
165   myMap.Assign (theMap);
166 }