Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeSequenceOfInteger_i.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEDS_AttributeSequenceOfInteger_i.cxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SALOMEDS_AttributeSequenceOfInteger_i.hxx"
30 #include "SALOMEDS.hxx"
31
32 #include <TColStd_HSequenceOfInteger.hxx>
33
34 using namespace std;
35
36 void SALOMEDS_AttributeSequenceOfInteger_i::Assign(const SALOMEDS::LongSeq& other) 
37 {
38   SALOMEDS::Locker lock;
39
40   CheckLocked();
41   Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger;
42   for (int i = 0; i < other.length(); i++) {
43     CasCadeSeq->Append(other[i]);
44   }
45   Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->Assign(CasCadeSeq);
46 }
47  
48 SALOMEDS::LongSeq* SALOMEDS_AttributeSequenceOfInteger_i::CorbaSequence()
49 {
50   SALOMEDS::Locker lock;
51
52   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
53   Handle(SALOMEDS_SequenceOfIntegerAttribute) CasCadeSeq = Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr);
54   CorbaSeq->length(CasCadeSeq->Length());
55   for (int i = 0; i < CasCadeSeq->Length(); i++) {
56     CorbaSeq[i] = CasCadeSeq->Value(i+1);;
57   }
58   return CorbaSeq._retn();
59 }
60  
61 void SALOMEDS_AttributeSequenceOfInteger_i::Add(CORBA::Long value) 
62 {
63   SALOMEDS::Locker lock;
64
65   CheckLocked();
66   Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->Add(value);
67 }
68
69 void SALOMEDS_AttributeSequenceOfInteger_i::Remove(CORBA::Long index) 
70 {
71   SALOMEDS::Locker lock;
72
73   CheckLocked();
74   Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->Remove(index);
75 }
76  
77 void SALOMEDS_AttributeSequenceOfInteger_i::ChangeValue(CORBA::Long index, CORBA::Long value)
78 {
79   SALOMEDS::Locker lock;
80
81   CheckLocked();
82   Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->ChangeValue(index, value);
83 }
84  
85 CORBA::Long SALOMEDS_AttributeSequenceOfInteger_i::Value(CORBA::Short index) 
86 {
87   SALOMEDS::Locker lock;
88
89   return Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->Value(index);
90 }
91
92 CORBA::Long SALOMEDS_AttributeSequenceOfInteger_i::Length() 
93 {
94   SALOMEDS::Locker lock;
95
96   return Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->Length();
97 }
98
99 char* SALOMEDS_AttributeSequenceOfInteger_i::Store() {
100   SALOMEDS::Locker lock;
101
102   Handle(SALOMEDS_SequenceOfIntegerAttribute) CasCadeSeq = Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr);
103   Standard_Integer aLength = CasCadeSeq->Length();
104   char* aResult = new char[aLength * 25];
105   aResult[0] = 0;
106   Standard_Integer aPosition = 0;
107   for (int i = 1; i <= aLength; i++) {
108     sprintf(aResult + aPosition , "%d ", CasCadeSeq->Value(i));
109     aPosition += strlen(aResult + aPosition);
110   }
111   return aResult;
112 }
113
114 void SALOMEDS_AttributeSequenceOfInteger_i::Restore(const char* value) {
115   SALOMEDS::Locker lock;
116
117   Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger;
118   
119   char* aCopy = strdup(value);
120   char* adr = strtok(aCopy, " ");
121   while (adr) {
122     CORBA::Long l =  atol(adr);
123     CasCadeSeq->Append(l);
124     adr = strtok(NULL, " ");
125   }
126   free(aCopy);
127   Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(_myAttr)->Assign(CasCadeSeq);
128 }