1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_AttributeSequenceOfInteger.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx"
30 //=======================================================================
33 //=======================================================================
35 const std::string& SALOMEDSImpl_AttributeSequenceOfInteger::GetID ()
37 static std::string SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
38 return SALOMEDSImpl_AttributeSequenceOfIntegerID;
43 //=======================================================================
46 //=======================================================================
48 SALOMEDSImpl_AttributeSequenceOfInteger* SALOMEDSImpl_AttributeSequenceOfInteger::Set (const DF_Label& L)
50 SALOMEDSImpl_AttributeSequenceOfInteger* A = NULL;
51 if (!(A = (SALOMEDSImpl_AttributeSequenceOfInteger*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID()))) {
52 A = new SALOMEDSImpl_AttributeSequenceOfInteger();
59 //=======================================================================
60 //function : constructor
62 //=======================================================================
63 SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger()
64 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger")
67 //=======================================================================
70 //=======================================================================
72 const std::string& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
75 //=======================================================================
78 //=======================================================================
80 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
82 return new SALOMEDSImpl_AttributeSequenceOfInteger();
85 //=======================================================================
88 //=======================================================================
90 void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(DF_Attribute* with)
92 SALOMEDSImpl_AttributeSequenceOfInteger* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfInteger*>(with);
94 for(int i = 0, len = anSeq->Length(); i<len; i++)
95 myValue.push_back(anSeq->myValue[i]);
98 //=======================================================================
101 //=======================================================================
103 void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (DF_Attribute* into)
105 dynamic_cast<SALOMEDSImpl_AttributeSequenceOfInteger*>(into)->Assign(myValue);
108 void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const std::vector<int>& other)
115 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
118 void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const int Index,const int Value)
123 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
125 myValue[Index-1] = Value;
127 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
130 void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const int Value)
134 myValue.push_back(Value);
136 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
139 void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const int Index)
144 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
146 typedef std::vector<int>::iterator VI;
148 for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
155 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
158 int SALOMEDSImpl_AttributeSequenceOfInteger::Length()
160 return myValue.size();
162 int SALOMEDSImpl_AttributeSequenceOfInteger::Value(const int Index)
164 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
166 return myValue[Index-1];
171 std::string SALOMEDSImpl_AttributeSequenceOfInteger::Save()
173 int aLength = Length();
174 char* aResult = new char[aLength * 25];
177 for (int i = 1; i <= aLength; i++) {
178 sprintf(aResult + aPosition , "%d ", Value(i));
179 aPosition += strlen(aResult + aPosition);
181 std::string ret(aResult);
187 void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const std::string& value)
189 char* aCopy = (char*)value.c_str();
190 char* adr = strtok(aCopy, " ");
194 adr = strtok(NULL, " ");