Salome HOME
add method NameChanged to update title name
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeSequenceOfInteger.cxx
index ca16677028307d52ada39087f4f8173c4e45c0e2..ddb311b6a49b3e478f13fe916ea161b3d841e6d5 100644 (file)
@@ -1,24 +1,41 @@
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 //  File   : SALOMEDSImpl_AttributeSequenceOfInteger.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
+//
 #include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx"
-#include <Standard_GUID.hxx>
-
-using namespace std;
-
-IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
-IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute )
-
+#include <string.h>
+#include <stdlib.h>
 
 //=======================================================================
 //function : GetID
 //purpose  : 
 //=======================================================================
 
-const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::GetID () 
+const std::string& SALOMEDSImpl_AttributeSequenceOfInteger::GetID () 
 {
-  static Standard_GUID SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
+  static std::string SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F");
   return SALOMEDSImpl_AttributeSequenceOfIntegerID;
 }
 
@@ -29,10 +46,10 @@ const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::GetID ()
 //purpose  : 
 //=======================================================================
 
-Handle(SALOMEDSImpl_AttributeSequenceOfInteger) SALOMEDSImpl_AttributeSequenceOfInteger::Set (const TDF_Label& L) 
+SALOMEDSImpl_AttributeSequenceOfInteger* SALOMEDSImpl_AttributeSequenceOfInteger::Set (const DF_Label& L) 
 {
-  Handle(SALOMEDSImpl_AttributeSequenceOfInteger) A;
-  if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID(),A)) {
+  SALOMEDSImpl_AttributeSequenceOfInteger* A = NULL;
+  if (!(A = (SALOMEDSImpl_AttributeSequenceOfInteger*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID()))) {
     A = new  SALOMEDSImpl_AttributeSequenceOfInteger(); 
     L.AddAttribute(A);
   }
@@ -46,16 +63,14 @@ Handle(SALOMEDSImpl_AttributeSequenceOfInteger) SALOMEDSImpl_AttributeSequenceOf
 //=======================================================================
 SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger()
 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger")
-{ 
-  myValue = new TColStd_HSequenceOfInteger();
-}
+{}
 
 //=======================================================================
 //function : ID
 //purpose  : 
 //=======================================================================
 
-const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
+const std::string& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); }
 
 
 //=======================================================================
@@ -63,7 +78,7 @@ const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { retu
 //purpose  : 
 //=======================================================================
 
-Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
+DF_Attribute* SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
 {  
   return new SALOMEDSImpl_AttributeSequenceOfInteger(); 
 }
@@ -73,18 +88,12 @@ Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const
 //purpose  : 
 //=======================================================================
 
-void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(const Handle(TDF_Attribute)& with) 
+void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(DF_Attribute* with) 
 {
-  Standard_Integer i;
-  Handle(SALOMEDSImpl_AttributeSequenceOfInteger) anSeq = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(with);
-  if(!anSeq->myValue.IsNull()) {
-    myValue = new TColStd_HSequenceOfInteger();
-    Standard_Integer Len = anSeq->Length();
-    for(i = 1; i<=Len; i++) Add(anSeq->Value(i)); 
-  }
-  else
-    myValue.Nullify();
-  return;
+  SALOMEDSImpl_AttributeSequenceOfInteger* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfInteger*>(with);
+  myValue.clear();
+  for(int i = 0, len = anSeq->Length(); i<len; i++)
+    myValue.push_back(anSeq->myValue[i]);    
 }
 
 //=======================================================================
@@ -92,88 +101,97 @@ void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(const Handle(TDF_Attribute
 //purpose  : 
 //=======================================================================
 
-void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (const Handle(TDF_Attribute)& into,
-                                    const Handle(TDF_RelocationTable)& ) const
+void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (DF_Attribute* into)
 {
-  if(!myValue.IsNull()) {
-    Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast (into)->Assign(myValue);
-  }
+  dynamic_cast<SALOMEDSImpl_AttributeSequenceOfInteger*>(into)->Assign(myValue);
 }
 
-void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const Handle(TColStd_HSequenceOfInteger)& other) 
+void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const std::vector<int>& other) 
 {
   CheckLocked();
   Backup();
-  if (myValue.IsNull()) myValue = new TColStd_HSequenceOfInteger;
-  myValue->ChangeSequence() = other->Sequence();
 
+  myValue = other;
+  
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
 
-void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const Standard_Integer Index,const Standard_Integer Value) 
+void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const int Index,const int Value) 
 {
   CheckLocked();  
   Backup();
-  myValue->SetValue(Index, Value);
+
+  if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
+
+  myValue[Index-1] = Value;
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
 
-void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const Standard_Integer Value) 
+void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const int Value) 
 {
   CheckLocked();  
   Backup();
-  myValue->Append(Value);
+  myValue.push_back(Value);
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
 
-void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const Standard_Integer Index) 
+void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const int Index) 
 {
   CheckLocked();  
   Backup();
-  myValue->Remove(Index);
-  
+
+  if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
+
+  typedef std::vector<int>::iterator VI;
+  int i = 1;    
+  for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
+    if(i == Index) {
+      myValue.erase(p);
+      break;
+    }     
+  }
+
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
 
-Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Length() 
+int SALOMEDSImpl_AttributeSequenceOfInteger::Length() 
 {
-  return myValue->Length();
+  return myValue.size();
 }
-Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Value(const Standard_Integer Index) 
+int SALOMEDSImpl_AttributeSequenceOfInteger::Value(const int Index) 
 {
-  return myValue->Value(Index);
+  if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
+
+  return myValue[Index-1];
 }
 
 
 
-TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfInteger::Save() 
+std::string SALOMEDSImpl_AttributeSequenceOfInteger::Save() 
 {
-  Standard_Integer aLength = Length();
+  int aLength = Length();
   char* aResult = new char[aLength * 25];
   aResult[0] = 0;
-  Standard_Integer aPosition = 0;
+  int aPosition = 0;
   for (int i = 1; i <= aLength; i++) {
     sprintf(aResult + aPosition , "%d ", Value(i));
     aPosition += strlen(aResult + aPosition);
   }
-  TCollection_AsciiString ret(aResult);
+  std::string ret(aResult);
   delete aResult;
   
   return ret;
 }
-                       
-void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const TCollection_AsciiString& value) 
+                        
+void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const std::string& value) 
 {
-  Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger;
-                         
-  char* aCopy = value.ToCString();
+  char* aCopy = (char*)value.c_str();
   char* adr = strtok(aCopy, " ");
   while (adr) {
     int l =  atol(adr);
-    CasCadeSeq->Append(l);
+    Add(l);
     adr = strtok(NULL, " ");
   }
-  Assign(CasCadeSeq);
 }