Salome HOME
CCAR: remove memory leaks in non local SALOMEDS
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfString.cxx
index a999892a4f9c530c3fa3ace5f64fbba3a8f4fd51..227ebd4f46832e5aa006eaa3cbd9685901e42001 100644 (file)
@@ -1,38 +1,37 @@
-// Copyright (C) 2005  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.
-// 
-// 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.
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/
+//  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.
+//
+//  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   : SALOMEDS_AttributeTableOfString.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
+//
 #include "SALOMEDS_AttributeTableOfString.hxx"
 #include "SALOMEDS.hxx"
 
 #include <string>
-#include <TCollection_AsciiString.hxx> 
-#include <TCollection_ExtendedString.hxx>
-#include <TColStd_HSequenceOfInteger.hxx>
-#include <TColStd_HSequenceOfReal.hxx>
-#include <TColStd_HSequenceOfExtendedString.hxx>
+
+using namespace std;
  
 SALOMEDS_AttributeTableOfString::SALOMEDS_AttributeTableOfString
-                  (const Handle(SALOMEDSImpl_AttributeTableOfString)& theAttr)
+                  (SALOMEDSImpl_AttributeTableOfString* theAttr)
 :SALOMEDS_GenericAttribute(theAttr)
 {}
 
@@ -50,7 +49,7 @@ void SALOMEDS_AttributeTableOfString::SetTitle(const std::string& theTitle)
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetTitle((char*)theTitle.c_str());
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetTitle(theTitle);
   }
   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
 }
@@ -60,8 +59,7 @@ std::string SALOMEDS_AttributeTableOfString::GetTitle()
   std::string aStr;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aStr = TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfString)::
-                                   DownCast(_local_impl)->GetTitle()).ToCString();
+    aStr = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetTitle();
   }
   else aStr = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetTitle();
   return aStr;
@@ -72,8 +70,7 @@ void SALOMEDS_AttributeTableOfString::SetRowTitle(int theIndex, const std::strin
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString)::
-      DownCast(_local_impl)->SetRowTitle(theIndex, (char*)theTitle.c_str());
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowTitle(theIndex, theTitle);
   }
   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
 }
@@ -84,9 +81,7 @@ void SALOMEDS_AttributeTableOfString::SetRowTitles(const std::vector<std::string
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
-    for (i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
-    Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetRowTitles(aSeq);
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowTitles(theTitles);
   }
   else {
     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
@@ -102,10 +97,7 @@ std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRowTitles()
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aSeq;
-    aSeq = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetRowTitles();
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
+    aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetRowTitles();
   }
   else {
     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowTitles();
@@ -120,8 +112,7 @@ void SALOMEDS_AttributeTableOfString::SetColumnTitle(int theIndex, const std::st
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString)::
-      DownCast(_local_impl)->SetColumnTitle(theIndex, (char*)theTitle.c_str());
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetColumnTitle(theIndex, theTitle);
   }
   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
 }
@@ -132,9 +123,7 @@ void SALOMEDS_AttributeTableOfString::SetColumnTitles(const std::vector<std::str
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
-    for (i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
-    Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetColumnTitles(aSeq);
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetColumnTitles(theTitles);
   }
   else {
     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
@@ -150,10 +139,7 @@ std::vector<std::string> SALOMEDS_AttributeTableOfString::GetColumnTitles()
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aSeq;
-    aSeq = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetColumnTitles();
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
+    aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetColumnTitles();
   }
   else {
     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumnTitles();
@@ -168,8 +154,7 @@ void SALOMEDS_AttributeTableOfString::SetRowUnit(int theIndex, const std::string
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString)::
-      DownCast(_local_impl)->SetRowUnit(theIndex, (char*)theUnit.c_str());
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowUnit(theIndex, theUnit);
   }
   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
 }
@@ -180,9 +165,7 @@ void SALOMEDS_AttributeTableOfString::SetRowUnits(const std::vector<std::string>
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
-    for (i = 0; i < aLength; i++) aSeq->Append((char*)theUnits[i].c_str());
-    Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetRowUnits(aSeq);
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowUnits(theUnits);
   }
   else {
     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
@@ -198,10 +181,7 @@ std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRowUnits()
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aSeq;
-    aSeq = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetRowUnits();
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
+    aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetRowUnits();
   }
   else {
     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowUnits();
@@ -216,7 +196,7 @@ int SALOMEDS_AttributeTableOfString::GetNbRows()
   int aNb;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aNb = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetNbRows();
+    aNb = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetNbRows();
   }
   else aNb = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetNbRows();
   return aNb;
@@ -227,7 +207,7 @@ int SALOMEDS_AttributeTableOfString::GetNbColumns()
   int aNb;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aNb = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetNbColumns();
+    aNb = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetNbColumns();
   }
   else aNb = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetNbColumns();
   return aNb;
@@ -239,12 +219,9 @@ void SALOMEDS_AttributeTableOfString::AddRow(const std::vector<std::string>& the
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
-    aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
-    Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
-    for (int i = 0; i < aLength; i++) aRow->Append((char*)theData[i].c_str());
+    SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
     try {
-      aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
+      aTable->SetRowData(aTable->GetNbRows() + 1, theData);
     }   
     catch(...) {
       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
@@ -264,12 +241,9 @@ void SALOMEDS_AttributeTableOfString::SetRow(int theRow, const std::vector<std::
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
-    aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
-    Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
-    for (int i = 0; i < aLength; i++) aRow->Append((char*)theData[i].c_str());
+    SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
     try {
-      aTable->SetRowData(theRow, aRow);
+      aTable->SetRowData(theRow, theData);
     }   
     catch(...) {
       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
@@ -289,13 +263,11 @@ std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRow(int theRow)
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aRow; 
-    aRow = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetRowData(theRow);
-    aLength = aRow->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aRow->Value(i)).ToCString());
+    aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetRowData(theRow);
   }
   else {
     SALOMEDS::StringSeq_var aRow = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRow(theRow);
+    aLength = aRow->length();
     for (i = 0; i < aLength; i++) aVector.push_back((char*)aRow[i].in());
   }
 
@@ -308,12 +280,9 @@ void SALOMEDS_AttributeTableOfString::AddColumn(const std::vector<std::string>&
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
-    aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
-    Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
-    for (int i = 0; i < aLength; i++) aColumn->Append((char*)theData[i].c_str());
+    SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
     try {
-      aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
+      aTable->SetColumnData(aTable->GetNbColumns() + 1, theData);
     }   
     catch(...) {
       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
@@ -333,12 +302,9 @@ void SALOMEDS_AttributeTableOfString::SetColumn(int theColumn, const std::vector
   if (_isLocal) {
     CheckLocked();
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
-    aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
-    Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
-    for (int i = 0; i < aLength; i++) aColumn->Append((char*)theData[i].c_str());
+    SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
     try {
-      aTable->SetRowData(theColumn, aColumn);
+      aTable->SetColumnData(theColumn, theData);
     }   
     catch(...) {
       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
@@ -348,7 +314,7 @@ void SALOMEDS_AttributeTableOfString::SetColumn(int theColumn, const std::vector
     SALOMEDS::StringSeq_var aColumn = new SALOMEDS::StringSeq();
     aColumn->length(aLength);
     for (i = 0; i < aLength; i++) aColumn[i] = (char*)theData[i].c_str();
-    SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRow(theColumn, aColumn);
+    SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumn(theColumn, aColumn);
   }
 }
 
@@ -358,16 +324,12 @@ std::vector<std::string> SALOMEDS_AttributeTableOfString::GetColumn(int theColum
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfExtendedString) aColumn; 
-    aColumn = Handle(SALOMEDSImpl_AttributeTableOfString)::
-      DownCast(_local_impl)->GetColumnData(theColumn);
-    aLength = aColumn->Length();
-    for (i = 1; i <= aLength; i++)
-      aVector.push_back(TCollection_AsciiString(aColumn->Value(i)).ToCString());
+    aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetColumnData(theColumn);
   }
   else {
     SALOMEDS::StringSeq_var aColumn =
       SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumn(theColumn);
+    aLength = aColumn->length();  
     for (i = 0; i < aLength; i++) aVector.push_back(aColumn[i].in());
   }
   return aVector;
@@ -379,8 +341,7 @@ void SALOMEDS_AttributeTableOfString::PutValue(const std::string& theValue, int
     CheckLocked();
     SALOMEDS::Locker lock;
     try {
-      Handle(SALOMEDSImpl_AttributeTableOfString)::
-        DownCast(_local_impl)->PutValue((char*)theValue.c_str(), theRow, theColumn);
+      dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->PutValue(theValue, theRow, theColumn);
     }   
     catch(...) {
       throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
@@ -396,7 +357,7 @@ bool SALOMEDS_AttributeTableOfString::HasValue(int theRow, int theColumn)
   bool ret;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    ret = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->HasValue(theRow, theColumn);
+    ret = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->HasValue(theRow, theColumn);
   }
   else ret = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->HasValue(theRow, theColumn);
   return ret;
@@ -408,8 +369,7 @@ std::string SALOMEDS_AttributeTableOfString::GetValue(int theRow, int theColumn)
   if (_isLocal) {
     SALOMEDS::Locker lock;
     try {
-      aValue = TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfString)::
-                                       DownCast(_local_impl)->GetValue(theRow, theColumn)).ToCString();
+      aValue = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetValue(theRow, theColumn);
     }   
     catch(...) {
       throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
@@ -427,14 +387,12 @@ std::vector<int> SALOMEDS_AttributeTableOfString::GetRowSetIndices(int theRow)
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(TColStd_HSequenceOfInteger) aSet; 
-    aSet = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetSetRowIndices(theRow);
-    aLength = aSet->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(aSet->Value(i));
+    aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetSetRowIndices(theRow);
   }
   else {
     SALOMEDS::LongSeq_var aSet =
       SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowSetIndices(theRow);
+    aLength = aSet->length();
     for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]);
   }
   return aVector;
@@ -444,7 +402,7 @@ void SALOMEDS_AttributeTableOfString::SetNbColumns(int theNbColumns)
 {
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetNbColumns(theNbColumns);
+    dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetNbColumns(theNbColumns);
   }
   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetNbColumns(theNbColumns);
 }