Back to index

salome-kernel  6.5.0
SALOMEDSImpl_AttributeSequenceOfReal.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SALOMEDSImpl_AttributeSequenceOfReal.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 //
00027 #include "SALOMEDSImpl_AttributeSequenceOfReal.hxx"
00028 #include <string.h>
00029 
00030 //=======================================================================
00031 //function : GetID
00032 //purpose  : 
00033 //=======================================================================
00034 
00035 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::GetID () 
00036 {
00037   static std::string SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
00038   return SALOMEDSImpl_AttributeSequenceOfRealID;
00039 }
00040 
00041 
00042 
00043 //=======================================================================
00044 //function : Set
00045 //purpose  : 
00046 //=======================================================================
00047 
00048 SALOMEDSImpl_AttributeSequenceOfReal* SALOMEDSImpl_AttributeSequenceOfReal::Set (const DF_Label& L) 
00049 {
00050   SALOMEDSImpl_AttributeSequenceOfReal* A = NULL;
00051   if (!(A=(SALOMEDSImpl_AttributeSequenceOfReal*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID()))) {
00052     A = new  SALOMEDSImpl_AttributeSequenceOfReal(); 
00053     L.AddAttribute(A);
00054   }
00055   return A;
00056 }
00057 
00058 
00059 //=======================================================================
00060 //function : constructor
00061 //purpose  : 
00062 //=======================================================================
00063 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
00064 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
00065 {
00066   myValue.clear();
00067 }
00068 
00069 //=======================================================================
00070 //function : ID
00071 //purpose  : 
00072 //=======================================================================
00073 
00074 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
00075 
00076 
00077 //=======================================================================
00078 //function : NewEmpty
00079 //purpose  : 
00080 //=======================================================================
00081 
00082 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
00083 {  
00084   return new SALOMEDSImpl_AttributeSequenceOfReal(); 
00085 }
00086 
00087 //=======================================================================
00088 //function : Restore
00089 //purpose  : 
00090 //=======================================================================
00091 
00092 void SALOMEDSImpl_AttributeSequenceOfReal::Restore(DF_Attribute* with) 
00093 {
00094   SALOMEDSImpl_AttributeSequenceOfReal* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(with);
00095   myValue.clear();
00096   for(int i = 0, len = anSeq->Length(); i<len; i++)
00097     myValue.push_back(anSeq->myValue[i]);    
00098   return;
00099 }
00100 
00101 //=======================================================================
00102 //function : Paste
00103 //purpose  : 
00104 //=======================================================================
00105 
00106 void SALOMEDSImpl_AttributeSequenceOfReal::Paste (DF_Attribute* into)
00107 {
00108     dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(into)->Assign(myValue);
00109 }
00110 
00111 void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const std::vector<double>& other) 
00112 {
00113   CheckLocked();  
00114   Backup();
00115   myValue = other;
00116 
00117   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00118 }
00119 
00120 void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const int Index,const double& Value) 
00121 {
00122   CheckLocked();  
00123   Backup();
00124 
00125   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
00126 
00127   myValue[Index-1] = Value;
00128   
00129   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00130 }
00131 
00132 void SALOMEDSImpl_AttributeSequenceOfReal::Add(const double& Value) 
00133 {
00134   CheckLocked();  
00135   Backup();
00136   myValue.push_back(Value);
00137   
00138   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00139 }
00140 
00141 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const int Index) 
00142 {
00143   CheckLocked();  
00144   Backup();
00145 
00146   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
00147 
00148   typedef std::vector<double>::iterator VI;
00149   int i = 1;    
00150   for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
00151     if(i == Index) {
00152       myValue.erase(p);
00153       break;
00154     }     
00155   }
00156 
00157   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved   
00158 }
00159 
00160 int SALOMEDSImpl_AttributeSequenceOfReal::Length() 
00161 {
00162   return myValue.size();
00163 }
00164 
00165 double SALOMEDSImpl_AttributeSequenceOfReal::Value(const int Index) 
00166 {
00167   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
00168   return myValue[Index-1];
00169 }
00170 
00171 
00172 std::string SALOMEDSImpl_AttributeSequenceOfReal::Save()
00173 {
00174   int aLength = Length();
00175   char* aResult = new char[aLength * 127];
00176   aResult[0] = 0;
00177   int aPosition = 0;
00178   for (int i = 1; i <= aLength; i++) {
00179     sprintf(aResult + aPosition , "%.64e ", Value(i));
00180     aPosition += strlen(aResult + aPosition);
00181   }
00182   std::string ret(aResult);
00183   delete aResult;
00184                           
00185   return ret;
00186 }
00187                             
00188 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const std::string& value)
00189 {
00190                               
00191   char* aCopy = (char*)value.c_str();
00192   char* adr = strtok(aCopy, " ");
00193   char *err = NULL; 
00194   while (adr) {
00195     double r =  strtod(adr, &err); 
00196     Add(r);
00197     adr = strtok(NULL, " ");
00198   }
00199 }