1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_AttributeSequenceOfReal.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDSImpl_AttributeSequenceOfReal.hxx"
28 //=======================================================================
31 //=======================================================================
33 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::GetID ()
35 static std::string SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
36 return SALOMEDSImpl_AttributeSequenceOfRealID;
41 //=======================================================================
44 //=======================================================================
46 SALOMEDSImpl_AttributeSequenceOfReal* SALOMEDSImpl_AttributeSequenceOfReal::Set (const DF_Label& L)
48 SALOMEDSImpl_AttributeSequenceOfReal* A = NULL;
49 if (!(A=(SALOMEDSImpl_AttributeSequenceOfReal*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID()))) {
50 A = new SALOMEDSImpl_AttributeSequenceOfReal();
57 //=======================================================================
58 //function : constructor
60 //=======================================================================
61 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
62 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
67 //=======================================================================
70 //=======================================================================
72 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
75 //=======================================================================
78 //=======================================================================
80 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
82 return new SALOMEDSImpl_AttributeSequenceOfReal();
85 //=======================================================================
88 //=======================================================================
90 void SALOMEDSImpl_AttributeSequenceOfReal::Restore(DF_Attribute* with)
92 SALOMEDSImpl_AttributeSequenceOfReal* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(with);
94 for(int i = 0, len = anSeq->Length(); i<len; i++)
95 myValue.push_back(anSeq->myValue[i]);
99 //=======================================================================
102 //=======================================================================
104 void SALOMEDSImpl_AttributeSequenceOfReal::Paste (DF_Attribute* into)
106 dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(into)->Assign(myValue);
109 void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const vector<double>& other)
115 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
118 void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const int Index,const double& 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_AttributeSequenceOfReal::Add(const double& Value)
134 myValue.push_back(Value);
136 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
139 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const int Index)
144 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
146 typedef vector<double>::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_AttributeSequenceOfReal::Length()
160 return myValue.size();
163 double SALOMEDSImpl_AttributeSequenceOfReal::Value(const int Index)
165 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
166 return myValue[Index-1];
170 string SALOMEDSImpl_AttributeSequenceOfReal::Save()
172 int aLength = Length();
173 char* aResult = new char[aLength * 127];
176 for (int i = 1; i <= aLength; i++) {
177 sprintf(aResult + aPosition , "%.64e ", Value(i));
178 aPosition += strlen(aResult + aPosition);
186 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const string& value)
189 char* aCopy = (char*)value.c_str();
190 char* adr = strtok(aCopy, " ");
193 double r = strtod(adr, &err);
195 adr = strtok(NULL, " ");