Salome HOME
To avoid compilation pb on RedHat 8.0.
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeSequenceOfInteger.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_AttributeSequenceOfInteger.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx"
25 #include <Standard_GUID.hxx>
26
27 using namespace std;
28
29 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
30 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
31
32
33 //=======================================================================
34 //function : GetID
35 //purpose  : 
36 //=======================================================================
37
38 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::GetID () 
39 {
40   static Standard_GUID SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
41   return SALOMEDSImpl_AttributeSequenceOfIntegerID;
42 }
43
44
45
46 //=======================================================================
47 //function : Set
48 //purpose  : 
49 //=======================================================================
50
51 Handle(SALOMEDSImpl_AttributeSequenceOfInteger) SALOMEDSImpl_AttributeSequenceOfInteger::Set (const TDF_Label& L) 
52 {
53   Handle(SALOMEDSImpl_AttributeSequenceOfInteger) A;
54   if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID(),A)) {
55     A = new  SALOMEDSImpl_AttributeSequenceOfInteger(); 
56     L.AddAttribute(A);
57   }
58   return A;
59 }
60
61
62 //=======================================================================
63 //function : constructor
64 //purpose  : 
65 //=======================================================================
66 SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger()
67 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger")
68
69   myValue = new TColStd_HSequenceOfInteger();
70 }
71
72 //=======================================================================
73 //function : ID
74 //purpose  : 
75 //=======================================================================
76
77 const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
78
79
80 //=======================================================================
81 //function : NewEmpty
82 //purpose  : 
83 //=======================================================================
84
85 Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
86 {  
87   return new SALOMEDSImpl_AttributeSequenceOfInteger(); 
88 }
89
90 //=======================================================================
91 //function : Restore
92 //purpose  : 
93 //=======================================================================
94
95 void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(const Handle(TDF_Attribute)& with) 
96 {
97   Standard_Integer i;
98   Handle(SALOMEDSImpl_AttributeSequenceOfInteger) anSeq = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(with);
99   if(!anSeq->myValue.IsNull()) {
100     myValue = new TColStd_HSequenceOfInteger();
101     Standard_Integer Len = anSeq->Length();
102     for(i = 1; i<=Len; i++) Add(anSeq->Value(i)); 
103   }
104   else
105     myValue.Nullify();
106   return;
107 }
108
109 //=======================================================================
110 //function : Paste
111 //purpose  : 
112 //=======================================================================
113
114 void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (const Handle(TDF_Attribute)& into,
115                                     const Handle(TDF_RelocationTable)& ) const
116 {
117   if(!myValue.IsNull()) {
118     Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast (into)->Assign(myValue);
119   }
120 }
121
122 void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const Handle(TColStd_HSequenceOfInteger)& other) 
123 {
124   CheckLocked();
125   Backup();
126   if (myValue.IsNull()) myValue = new TColStd_HSequenceOfInteger;
127   myValue->ChangeSequence() = other->Sequence();
128
129   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
130 }
131
132 void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const Standard_Integer Index,const Standard_Integer Value) 
133 {
134   CheckLocked();  
135   Backup();
136
137   if(Index <= 0 || Index > myValue->Length()) Standard_Failure::Raise("Out of range");
138
139   myValue->SetValue(Index, Value);
140   
141   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
142 }
143
144 void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const Standard_Integer Value) 
145 {
146   CheckLocked();  
147   Backup();
148   myValue->Append(Value);
149   
150   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
151 }
152
153 void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const Standard_Integer Index) 
154 {
155   CheckLocked();  
156   Backup();
157
158   if(Index <= 0 || Index > myValue->Length()) Standard_Failure::Raise("Out of range");
159
160   myValue->Remove(Index);
161   
162   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
163 }
164
165 Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Length() 
166 {
167   return myValue->Length();
168 }
169 Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Value(const Standard_Integer Index) 
170 {
171   if(Index <= 0 || Index > myValue->Length()) Standard_Failure::Raise("Out of range");
172
173   return myValue->Value(Index);
174 }
175
176
177
178 TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfInteger::Save() 
179 {
180   Standard_Integer aLength = Length();
181   char* aResult = new char[aLength * 25];
182   aResult[0] = 0;
183   Standard_Integer aPosition = 0;
184   for (int i = 1; i <= aLength; i++) {
185     sprintf(aResult + aPosition , "%d ", Value(i));
186     aPosition += strlen(aResult + aPosition);
187   }
188   TCollection_AsciiString ret(aResult);
189   delete aResult;
190   
191   return ret;
192 }
193                         
194 void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const TCollection_AsciiString& value) 
195 {
196   Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger;
197                           
198   char* aCopy = value.ToCString();
199   char* adr = strtok(aCopy, " ");
200   while (adr) {
201     int l =  atol(adr);
202     CasCadeSeq->Append(l);
203     adr = strtok(NULL, " ");
204   }
205   Assign(CasCadeSeq);
206 }