1 // Copyright (C) 2007-2010 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_AttributeSequenceOfReal.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_AttributeSequenceOfReal.hxx"
30 //=======================================================================
33 //=======================================================================
35 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::GetID ()
37 static std::string SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
38 return SALOMEDSImpl_AttributeSequenceOfRealID;
43 //=======================================================================
46 //=======================================================================
48 SALOMEDSImpl_AttributeSequenceOfReal* SALOMEDSImpl_AttributeSequenceOfReal::Set (const DF_Label& L)
50 SALOMEDSImpl_AttributeSequenceOfReal* A = NULL;
51 if (!(A=(SALOMEDSImpl_AttributeSequenceOfReal*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID()))) {
52 A = new SALOMEDSImpl_AttributeSequenceOfReal();
59 //=======================================================================
60 //function : constructor
62 //=======================================================================
63 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
64 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
69 //=======================================================================
72 //=======================================================================
74 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
77 //=======================================================================
80 //=======================================================================
82 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
84 return new SALOMEDSImpl_AttributeSequenceOfReal();
87 //=======================================================================
90 //=======================================================================
92 void SALOMEDSImpl_AttributeSequenceOfReal::Restore(DF_Attribute* with)
94 SALOMEDSImpl_AttributeSequenceOfReal* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(with);
96 for(int i = 0, len = anSeq->Length(); i<len; i++)
97 myValue.push_back(anSeq->myValue[i]);
101 //=======================================================================
104 //=======================================================================
106 void SALOMEDSImpl_AttributeSequenceOfReal::Paste (DF_Attribute* into)
108 dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(into)->Assign(myValue);
111 void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const std::vector<double>& other)
117 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
120 void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const int Index,const double& Value)
125 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
127 myValue[Index-1] = Value;
129 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
132 void SALOMEDSImpl_AttributeSequenceOfReal::Add(const double& Value)
136 myValue.push_back(Value);
138 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
141 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const int Index)
146 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
148 typedef std::vector<double>::iterator VI;
150 for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
157 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
160 int SALOMEDSImpl_AttributeSequenceOfReal::Length()
162 return myValue.size();
165 double SALOMEDSImpl_AttributeSequenceOfReal::Value(const int Index)
167 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
168 return myValue[Index-1];
172 std::string SALOMEDSImpl_AttributeSequenceOfReal::Save()
174 int aLength = Length();
175 char* aResult = new char[aLength * 127];
178 for (int i = 1; i <= aLength; i++) {
179 sprintf(aResult + aPosition , "%.64e ", Value(i));
180 aPosition += strlen(aResult + aPosition);
182 std::string ret(aResult);
188 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const std::string& value)
191 char* aCopy = (char*)value.c_str();
192 char* adr = strtok(aCopy, " ");
195 double r = strtod(adr, &err);
197 adr = strtok(NULL, " ");