Back to index

salome-kernel  6.5.0
SALOMEDSImpl_AttributeSequenceOfInteger.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_AttributeSequenceOfInteger.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 //
00027 #include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx"
00028 #include <string.h>
00029 
00030 //=======================================================================
00031 //function : GetID
00032 //purpose  : 
00033 //=======================================================================
00034 
00035 const std::string& SALOMEDSImpl_AttributeSequenceOfInteger::GetID () 
00036 {
00037   static std::string SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
00038   return SALOMEDSImpl_AttributeSequenceOfIntegerID;
00039 }
00040 
00041 
00042 
00043 //=======================================================================
00044 //function : Set
00045 //purpose  : 
00046 //=======================================================================
00047 
00048 SALOMEDSImpl_AttributeSequenceOfInteger* SALOMEDSImpl_AttributeSequenceOfInteger::Set (const DF_Label& L) 
00049 {
00050   SALOMEDSImpl_AttributeSequenceOfInteger* A = NULL;
00051   if (!(A = (SALOMEDSImpl_AttributeSequenceOfInteger*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID()))) {
00052     A = new  SALOMEDSImpl_AttributeSequenceOfInteger(); 
00053     L.AddAttribute(A);
00054   }
00055   return A;
00056 }
00057 
00058 
00059 //=======================================================================
00060 //function : constructor
00061 //purpose  : 
00062 //=======================================================================
00063 SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger()
00064 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger")
00065 {}
00066 
00067 //=======================================================================
00068 //function : ID
00069 //purpose  : 
00070 //=======================================================================
00071 
00072 const std::string& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
00073 
00074 
00075 //=======================================================================
00076 //function : NewEmpty
00077 //purpose  : 
00078 //=======================================================================
00079 
00080 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
00081 {  
00082   return new SALOMEDSImpl_AttributeSequenceOfInteger(); 
00083 }
00084 
00085 //=======================================================================
00086 //function : Restore
00087 //purpose  : 
00088 //=======================================================================
00089 
00090 void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(DF_Attribute* with) 
00091 {
00092   SALOMEDSImpl_AttributeSequenceOfInteger* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfInteger*>(with);
00093   myValue.clear();
00094   for(int i = 0, len = anSeq->Length(); i<len; i++)
00095     myValue.push_back(anSeq->myValue[i]);    
00096 }
00097 
00098 //=======================================================================
00099 //function : Paste
00100 //purpose  : 
00101 //=======================================================================
00102 
00103 void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (DF_Attribute* into)
00104 {
00105   dynamic_cast<SALOMEDSImpl_AttributeSequenceOfInteger*>(into)->Assign(myValue);
00106 }
00107 
00108 void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const std::vector<int>& other) 
00109 {
00110   CheckLocked();
00111   Backup();
00112 
00113   myValue = other;
00114   
00115   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00116 }
00117 
00118 void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const int Index,const int Value) 
00119 {
00120   CheckLocked();  
00121   Backup();
00122 
00123   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
00124 
00125   myValue[Index-1] = Value;
00126   
00127   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00128 }
00129 
00130 void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const int Value) 
00131 {
00132   CheckLocked();  
00133   Backup();
00134   myValue.push_back(Value);
00135   
00136   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00137 }
00138 
00139 void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const int Index) 
00140 {
00141   CheckLocked();  
00142   Backup();
00143 
00144   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
00145 
00146   typedef std::vector<int>::iterator VI;
00147   int i = 1;    
00148   for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
00149     if(i == Index) {
00150       myValue.erase(p);
00151       break;
00152     }     
00153   }
00154 
00155   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00156 }
00157 
00158 int SALOMEDSImpl_AttributeSequenceOfInteger::Length() 
00159 {
00160   return myValue.size();
00161 }
00162 int SALOMEDSImpl_AttributeSequenceOfInteger::Value(const int Index) 
00163 {
00164   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
00165 
00166   return myValue[Index-1];
00167 }
00168 
00169 
00170 
00171 std::string SALOMEDSImpl_AttributeSequenceOfInteger::Save() 
00172 {
00173   int aLength = Length();
00174   char* aResult = new char[aLength * 25];
00175   aResult[0] = 0;
00176   int aPosition = 0;
00177   for (int i = 1; i <= aLength; i++) {
00178     sprintf(aResult + aPosition , "%d ", Value(i));
00179     aPosition += strlen(aResult + aPosition);
00180   }
00181   std::string ret(aResult);
00182   delete aResult;
00183   
00184   return ret;
00185 }
00186                         
00187 void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const std::string& value) 
00188 {
00189   char* aCopy = (char*)value.c_str();
00190   char* adr = strtok(aCopy, " ");
00191   while (adr) {
00192     int l =  atol(adr);
00193     Add(l);
00194     adr = strtok(NULL, " ");
00195   }
00196 }