Salome HOME
launchConfigureParser.py: Setup gui log file via environment variable.
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeSequenceOfReal.cxx
index fa7caff519ad7ca6a0cf7c777f80ea14570a404f..ccda92cbb8bdab4a6b23716d3a3f392dcb9000f7 100644 (file)
@@ -1,23 +1,41 @@
+// Copyright (C) 2007-2023  CEA, EDF, 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_AttributeSequenceOfReal.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
+//
 #include "SALOMEDSImpl_AttributeSequenceOfReal.hxx"
-#include <Standard_GUID.hxx>
-
-using namespace std;
-
-IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute )
-IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute )
+#include <string.h>
+#include <stdlib.h>
 
 //=======================================================================
 //function : GetID
 //purpose  : 
 //=======================================================================
 
-const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::GetID () 
+const std::string& SALOMEDSImpl_AttributeSequenceOfReal::GetID () 
 {
-  static Standard_GUID SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
+  static std::string SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
   return SALOMEDSImpl_AttributeSequenceOfRealID;
 }
 
@@ -28,10 +46,10 @@ const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::GetID ()
 //purpose  : 
 //=======================================================================
 
-Handle(SALOMEDSImpl_AttributeSequenceOfReal) SALOMEDSImpl_AttributeSequenceOfReal::Set (const TDF_Label& L) 
+SALOMEDSImpl_AttributeSequenceOfReal* SALOMEDSImpl_AttributeSequenceOfReal::Set (const DF_Label& L) 
 {
-  Handle(SALOMEDSImpl_AttributeSequenceOfReal) A;
-  if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID(),A)) {
+  SALOMEDSImpl_AttributeSequenceOfReal* A = NULL;
+  if (!(A=(SALOMEDSImpl_AttributeSequenceOfReal*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID()))) {
     A = new  SALOMEDSImpl_AttributeSequenceOfReal(); 
     L.AddAttribute(A);
   }
@@ -46,7 +64,7 @@ Handle(SALOMEDSImpl_AttributeSequenceOfReal) SALOMEDSImpl_AttributeSequenceOfRea
 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
 {
-  myValue = new TColStd_HSequenceOfReal();
+  myValue.clear();
 }
 
 //=======================================================================
@@ -54,7 +72,7 @@ SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
 //purpose  : 
 //=======================================================================
 
-const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
+const std::string& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
 
 
 //=======================================================================
@@ -62,7 +80,7 @@ const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return
 //purpose  : 
 //=======================================================================
 
-Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
+DF_Attribute* SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
 {  
   return new SALOMEDSImpl_AttributeSequenceOfReal(); 
 }
@@ -72,17 +90,12 @@ Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
 //purpose  : 
 //=======================================================================
 
-void SALOMEDSImpl_AttributeSequenceOfReal::Restore(const Handle(TDF_Attribute)& with) 
+void SALOMEDSImpl_AttributeSequenceOfReal::Restore(DF_Attribute* with) 
 {
-  Standard_Integer i;
-  Handle(SALOMEDSImpl_AttributeSequenceOfReal) anSeq = Handle(SALOMEDSImpl_AttributeSequenceOfReal)::DownCast(with);
-  if(!anSeq->myValue.IsNull()) {
-    myValue = new TColStd_HSequenceOfReal();
-    Standard_Integer Len = anSeq->Length();
-    for(i = 1; i<=Len; i++) Add(anSeq->Value(i)); 
-  }
-  else
-    myValue.Nullify();
+  SALOMEDSImpl_AttributeSequenceOfReal* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(with);
+  myValue.clear();
+  for(int i = 0, len = anSeq->Length(); i<len; i++)
+    myValue.push_back(anSeq->myValue[i]);    
   return;
 }
 
@@ -91,89 +104,97 @@ void SALOMEDSImpl_AttributeSequenceOfReal::Restore(const Handle(TDF_Attribute)&
 //purpose  : 
 //=======================================================================
 
-void SALOMEDSImpl_AttributeSequenceOfReal::Paste (const Handle(TDF_Attribute)& into,
-                                    const Handle(TDF_RelocationTable)& ) const
+void SALOMEDSImpl_AttributeSequenceOfReal::Paste (DF_Attribute* into)
 {
-  if(!myValue.IsNull()) {
-    Handle(SALOMEDSImpl_AttributeSequenceOfReal)::DownCast (into)->Assign(myValue);
-  }
+    dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(into)->Assign(myValue);
 }
 
-void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const Handle(TColStd_HSequenceOfReal)& other) 
+void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const std::vector<double>& other) 
 {
   CheckLocked();  
   Backup();
-  if (myValue.IsNull()) myValue = new TColStd_HSequenceOfReal;
-  myValue->ChangeSequence() = other->Sequence();
+  myValue = other;
 
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
 
-void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const Standard_Integer Index,const Standard_Real Value) 
+void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const int Index,const double& Value) 
 {
   CheckLocked();  
   Backup();
-  myValue->SetValue(Index, Value);
+
+  if(Index <= 0 || Index > (int)myValue.size()) throw DFexception("Out of range"); // TODO: mismatch signed/unsigned
+
+  myValue[Index-1] = Value;
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
 
-void SALOMEDSImpl_AttributeSequenceOfReal::Add(const Standard_Real Value) 
+void SALOMEDSImpl_AttributeSequenceOfReal::Add(const double& 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_AttributeSequenceOfReal::Remove(const Standard_Integer Index) 
+void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const int Index) 
 {
   CheckLocked();  
   Backup();
-  myValue->Remove(Index);
-  
-  SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
+
+  if(Index <= 0 || Index > (int)myValue.size()) throw DFexception("Out of range"); // TODO: mismatch signed/unsigned
+
+  typedef std::vector<double>::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_AttributeSequenceOfReal::Length() 
+int SALOMEDSImpl_AttributeSequenceOfReal::Length() 
 {
-  return myValue->Length();
+  return (int)myValue.size(); //!< TODO: conversion from size_t to int, possible loss of data
 }
 
-Standard_Real SALOMEDSImpl_AttributeSequenceOfReal::Value(const Standard_Integer Index) 
+double SALOMEDSImpl_AttributeSequenceOfReal::Value(const int Index) 
 {
-  return myValue->Value(Index);
+  if(Index <= 0 || Index > (int)myValue.size()) throw DFexception("Out of range"); // TODO: mismatch signed/unsigned
+  return myValue[Index-1];
 }
 
 
-TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfReal::Save()
+std::string SALOMEDSImpl_AttributeSequenceOfReal::Save()
 {
-  Standard_Integer aLength = Length();
-  char* aResult = new char[aLength * 25];
+  int aLength = Length();
+  char* aResult = new char[aLength * 127];
   aResult[0] = 0;
-  Standard_Integer aPosition = 0;
+  size_t aPosition = 0;
   for (int i = 1; i <= aLength; i++) {
-    sprintf(aResult + aPosition , "%f ", Value(i));
+    sprintf(aResult + aPosition , "%.64e ", Value(i));
     aPosition += strlen(aResult + aPosition);
   }
-  TCollection_AsciiString ret(aResult);
+  std::string ret(aResult);
   delete aResult;
-                         
+                          
   return ret;
 }
-                           
-void SALOMEDSImpl_AttributeSequenceOfReal::Load(const TCollection_AsciiString& value)
+                            
+void SALOMEDSImpl_AttributeSequenceOfReal::Load(const std::string& value)
 {
-  Handle(TColStd_HSequenceOfReal) CasCadeSeq = new TColStd_HSequenceOfReal;
-                             
-  char* aCopy = value.ToCString();
+                              
+  char* aCopy = (char*)value.c_str();
   char* adr = strtok(aCopy, " ");
   char *err = NULL; 
   while (adr) {
-    Standard_Real r =  strtod(adr, &err); 
-    CasCadeSeq->Append(r);
+    double r =  strtod(adr, &err); 
+    Add(r);
     adr = strtok(NULL, " ");
   }
-  Assign(CasCadeSeq);
 }