Salome HOME
PR: mergefrom branch BR_V3_1_0_PR tag mergeto_trunk_02feb06
[modules/yacs.git] / src / SALOMEDS / SALOMEDS_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/
19 //
20 //  File   : SALOMEDS_AttributeSequenceOfInteger.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_AttributeSequenceOfInteger.hxx"
25 #include "SALOMEDS.hxx"
26
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <TColStd_HSequenceOfInteger.hxx>
30
31 SALOMEDS_AttributeSequenceOfInteger::SALOMEDS_AttributeSequenceOfInteger
32                   (const Handle(SALOMEDSImpl_AttributeSequenceOfInteger)& theAttr)
33 :SALOMEDS_GenericAttribute(theAttr)
34 {}
35
36 SALOMEDS_AttributeSequenceOfInteger::SALOMEDS_AttributeSequenceOfInteger
37                   (SALOMEDS::AttributeSequenceOfInteger_ptr theAttr)
38 :SALOMEDS_GenericAttribute(theAttr)
39 {}
40
41 SALOMEDS_AttributeSequenceOfInteger::~SALOMEDS_AttributeSequenceOfInteger()
42 {}
43
44 void SALOMEDS_AttributeSequenceOfInteger::Assign(const std::vector<int>& other)
45 {
46   int i, aLength = other.size();
47   if (_isLocal) {
48     CheckLocked();
49     SALOMEDS::Locker lock;
50     Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
51     for (i = 0; i < aLength; i++) aSeq->Append(other[i]);
52     Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl)->Assign(aSeq);
53   }
54   else {
55     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq();
56     aSeq->length(aLength);
57     for (i = 0; i < aLength; i++) aSeq[i] = other[i];
58     SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl)->Assign(aSeq);
59   }
60 }
61
62 std::vector<int> SALOMEDS_AttributeSequenceOfInteger::CorbaSequence()
63 {
64   std::vector<int> aVector;
65   int i, aLength;
66   if (_isLocal) {
67     SALOMEDS::Locker lock;
68     Handle(SALOMEDSImpl_AttributeSequenceOfInteger) aSeqAttr;
69     aSeqAttr = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl);
70     aLength = aSeqAttr->Length();
71     for (i = 1; i <=aLength; i++) aVector.push_back(aSeqAttr->Value(i));
72   }
73   else {
74     SALOMEDS::AttributeSequenceOfInteger_var aSeqAttr =
75       SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl);
76     aLength = aSeqAttr->Length();
77     for (i = 1; i <=aLength; i++) aVector.push_back(aSeqAttr->Value(i));
78   }
79   return aVector;
80 }
81
82 void SALOMEDS_AttributeSequenceOfInteger::Add(int value)
83 {
84   if (_isLocal) {
85     CheckLocked();
86     SALOMEDS::Locker lock;
87     Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl)->Add(value);
88   }
89   else SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl)->Add(value);
90 }
91
92 void SALOMEDS_AttributeSequenceOfInteger::Remove(int index)
93 {
94   if (_isLocal) {
95     CheckLocked();
96     SALOMEDS::Locker lock;
97     Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl)->Remove(index);
98   }
99   else SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl)->Remove(index);
100 }
101
102 void SALOMEDS_AttributeSequenceOfInteger::ChangeValue(int index, int value)
103 {
104   if (_isLocal) {
105     CheckLocked();
106     SALOMEDS::Locker lock;
107     Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl)->ChangeValue(index, value);
108   }
109   else SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl)->ChangeValue(index, value);
110 }
111
112 int SALOMEDS_AttributeSequenceOfInteger::Value(int index)
113 {
114   int aValue;
115   if (_isLocal) {
116     SALOMEDS::Locker lock;
117     aValue = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl)->Value(index);
118   }
119   else aValue = SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl)->Value(index);
120   return aValue;
121 }
122
123 int SALOMEDS_AttributeSequenceOfInteger::Length()
124 {
125   int aValue;
126   if (_isLocal) {
127     SALOMEDS::Locker lock;
128     aValue = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(_local_impl)-> Length();
129   }
130   else aValue = SALOMEDS::AttributeSequenceOfInteger::_narrow(_corba_impl)-> Length();
131   return aValue;
132 }