1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
31 //=======================================================================
34 //=======================================================================
36 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::GetID ()
38 static std::string SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
39 return SALOMEDSImpl_AttributeSequenceOfRealID;
44 //=======================================================================
47 //=======================================================================
49 SALOMEDSImpl_AttributeSequenceOfReal* SALOMEDSImpl_AttributeSequenceOfReal::Set (const DF_Label& L)
51 SALOMEDSImpl_AttributeSequenceOfReal* A = NULL;
52 if (!(A=(SALOMEDSImpl_AttributeSequenceOfReal*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID()))) {
53 A = new SALOMEDSImpl_AttributeSequenceOfReal();
60 //=======================================================================
61 //function : constructor
63 //=======================================================================
64 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
65 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
70 //=======================================================================
73 //=======================================================================
75 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
78 //=======================================================================
81 //=======================================================================
83 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
85 return new SALOMEDSImpl_AttributeSequenceOfReal();
88 //=======================================================================
91 //=======================================================================
93 void SALOMEDSImpl_AttributeSequenceOfReal::Restore(DF_Attribute* with)
95 SALOMEDSImpl_AttributeSequenceOfReal* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(with);
97 for(int i = 0, len = anSeq->Length(); i<len; i++)
98 myValue.push_back(anSeq->myValue[i]);
102 //=======================================================================
105 //=======================================================================
107 void SALOMEDSImpl_AttributeSequenceOfReal::Paste (DF_Attribute* into)
109 dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(into)->Assign(myValue);
112 void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const std::vector<double>& other)
118 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
121 void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const int Index,const double& Value)
126 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
128 myValue[Index-1] = Value;
130 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
133 void SALOMEDSImpl_AttributeSequenceOfReal::Add(const double& Value)
137 myValue.push_back(Value);
139 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
142 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const int Index)
147 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
149 typedef std::vector<double>::iterator VI;
151 for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
158 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
161 int SALOMEDSImpl_AttributeSequenceOfReal::Length()
163 return myValue.size();
166 double SALOMEDSImpl_AttributeSequenceOfReal::Value(const int Index)
168 if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
169 return myValue[Index-1];
173 std::string SALOMEDSImpl_AttributeSequenceOfReal::Save()
175 int aLength = Length();
176 char* aResult = new char[aLength * 127];
179 for (int i = 1; i <= aLength; i++) {
180 sprintf(aResult + aPosition , "%.64e ", Value(i));
181 aPosition += strlen(aResult + aPosition);
183 std::string ret(aResult);
189 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const std::string& value)
192 char* aCopy = (char*)value.c_str();
193 char* adr = strtok(aCopy, " ");
196 double r = strtod(adr, &err);
198 adr = strtok(NULL, " ");