Salome HOME
CCAR: remove memory leaks in non local SALOMEDS
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties_i.cxx
index b08b9d5c4c93892d19858113074e2fb4b0ac8214..b1415aab887d7c679f53a08207e265d4f6d73707 100644 (file)
@@ -1,36 +1,48 @@
-//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//  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.
 //
+//  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_AttributeStudyProperties_i.cxx
-//  Author : Yves FRICAUD
+//  Author : Sergey RUIN
 //  Module : SALOME
-//  $Header$
-
-#include <TColStd_HSequenceOfExtendedString.hxx>
-#include <TColStd_HSequenceOfInteger.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TCollection_AsciiString.hxx>
-
+//
 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
+#include "SALOMEDS.hxx"
+using namespace std;
 
 #define CREATION_MODE_NOTDEFINED 0
 #define CREATION_MODE_SCRATCH 1
 #define CREATION_MODE_COPY 2
 
-using namespace std;
-
-void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName) {
+void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName)
+{
+  SALOMEDS::Locker lock;
   CheckLocked();
-  Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
-  aProp->SetFirstName(const_cast<char*>(theName));
+  dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->ChangeCreatorName((char*)theName);
 }
 
-char* SALOMEDS_AttributeStudyProperties_i::GetUserName() {
-  TCollection_ExtendedString S = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreatorName();
-  CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(S).ToCString());
+char* SALOMEDS_AttributeStudyProperties_i::GetUserName()
+{
+  SALOMEDS::Locker lock;
+  string S = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->GetCreatorName();
+  CORBA::String_var c_s = CORBA::string_dup(S.c_str());
   return c_s._retn();
 }
 
@@ -38,47 +50,55 @@ void SALOMEDS_AttributeStudyProperties_i::SetCreationDate(CORBA::Long theMinute,
                                                          CORBA::Long theHour,
                                                          CORBA::Long theDay,
                                                          CORBA::Long theMonth,
-                                                         CORBA::Long theYear) {
+                                                         CORBA::Long theYear)
+{
+  SALOMEDS::Locker lock;
   CheckLocked();
-  Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
+  SALOMEDSImpl_AttributeStudyProperties* aProp = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl);
   int aTmp;
   if (aProp->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
-  aProp->SetModificationDate(theMinute, theHour, theDay, theMonth, theYear);
+  string S;
+  aProp->SetModification(S, theMinute, theHour, theDay, theMonth, theYear);
 }
 
 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::GetCreationDate(CORBA::Long& theMinute,
                                                                    CORBA::Long& theHour,
                                                                    CORBA::Long& theDay,
                                                                    CORBA::Long& theMonth,
-                                                                   CORBA::Long& theYear) {
-  Standard_Integer aMinute;
-  Standard_Integer aHour;
-  Standard_Integer aDay;
-  Standard_Integer aMonth;
-  Standard_Integer aYear;
-  if (Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreationDate(aMinute, aHour, aDay,
-                                                                                   aMonth, aYear)) {
+                                                                   CORBA::Long& theYear)
+{
+  SALOMEDS::Locker lock;
+  int aMinute;
+  int aHour;
+  int aDay;
+  int aMonth;
+  int aYear;
+  if (dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->GetCreationDate(aMinute, aHour, aDay, aMonth, aYear)) {
     theMinute = aMinute;
     theHour = aHour;
     theDay = aDay;
     theMonth = aMonth;
     theYear = aYear;
-    return Standard_True;
+    return true;
   }
-  return Standard_False;
+  return false;
 }
 
-void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode) {
+void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode)
+{
+  SALOMEDS::Locker lock;
   CheckLocked();
-  Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
+  SALOMEDSImpl_AttributeStudyProperties* aProp = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl);
   if (strcmp(theMode,"from scratch")==0) aProp->SetCreationMode(CREATION_MODE_SCRATCH);
   else if (strcmp(theMode,"copy from")==0) aProp->SetCreationMode(CREATION_MODE_COPY);
   else aProp->SetCreationMode(CREATION_MODE_NOTDEFINED);
 }
 
-char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode() {
+char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode()
+{
+  SALOMEDS::Locker lock;
   CORBA::String_var c_s;
-  switch (Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreationMode()) {
+  switch (dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->GetCreationMode()) {
   case CREATION_MODE_SCRATCH: c_s = "from scratch"; break;
   case CREATION_MODE_COPY: c_s = "copy from"; break;
   default: c_s = "";
@@ -86,24 +106,34 @@ char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode() {
   return c_s._retn();
 }
 
-void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified) {
-  Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetModified(theModified);
+void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified)
+{
+  SALOMEDS::Locker lock;
+  dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->SetModified(theModified);
 }
 
-CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified() {
-  return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsModified();
+CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified()
+{
+  SALOMEDS::Locker lock;
+  return dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->IsModified();
 }
 
-CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified() {
-  return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetModified();
+CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified()
+{
+  SALOMEDS::Locker lock;
+  return dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->GetModified();
 }
 
-void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked) {
-  Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetLocked(theLocked);
+void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked)
+{
+  SALOMEDS::Locker lock;
+  dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->SetLocked(theLocked);
 }
 
-CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked() {
-  return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsLocked();
+CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked()
+{
+  SALOMEDS::Locker lock;
+  return dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl)->IsLocked();
 }
 
 void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
@@ -111,124 +141,49 @@ void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
                                                          CORBA::Long theHour,
                                                          CORBA::Long theDay,
                                                          CORBA::Long theMonth,
-                                                         CORBA::Long theYear) {
+                                                         CORBA::Long theYear)
+{
+  SALOMEDS::Locker lock;
   CheckLocked();
-  Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
-  aProp->SetUserName(const_cast<char*>(theName));
-  aProp->SetModificationDate((int)theMinute, (int)theHour, (int)theDay, (int)theMonth, (int)theYear);
+  SALOMEDSImpl_AttributeStudyProperties* aProp = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl);
+  aProp->SetModification((char*)theName, (int)theMinute, (int)theHour,
+                         (int)theDay, (int)theMonth, (int)theYear);
 }
+
 void SALOMEDS_AttributeStudyProperties_i::GetModificationsList(SALOMEDS::StringSeq_out theNames,
                                                               SALOMEDS::LongSeq_out theMinutes,
                                                               SALOMEDS::LongSeq_out theHours,
                                                               SALOMEDS::LongSeq_out theDays,
                                                               SALOMEDS::LongSeq_out theMonths,
                                                               SALOMEDS::LongSeq_out theYears,
-                                                              CORBA::Boolean theWithCreator) {
-  Handle(TColStd_HSequenceOfExtendedString) aNames;
-  Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
-  Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
-  aNames = aProp->GetUserNames();
-  aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
-  int aLength = aNames->Length()-((theWithCreator)?0:1);
+                                                              CORBA::Boolean theWithCreator)
+{
+  SALOMEDS::Locker lock;
+  vector<string> aNames;
+  vector<int> aMinutes, aHours, aDays, aMonths, aYears;
+  SALOMEDSImpl_AttributeStudyProperties* aProp = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_impl);
+  aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
+  int aLength = aNames.size();
+  int aRetLength = aLength - ((theWithCreator) ? 0 : 1);
   theNames = new SALOMEDS::StringSeq;
-//   SALOMEDS::LongSeq *maminute = new SALOMEDS::LongSeq;
-//   maminute->length(5);
   theMinutes = new SALOMEDS::LongSeq;
   theHours = new SALOMEDS::LongSeq;
   theDays = new SALOMEDS::LongSeq;
   theMonths = new SALOMEDS::LongSeq;
   theYears = new SALOMEDS::LongSeq;
-  theNames->length(aLength);
-  theMinutes->length(aLength);
-  theHours->length(aLength);
-  theDays->length(aLength);
-  theMonths->length(aLength);
-  theYears->length(aLength);
-  int a;
-  for(a = 0; a < aLength; a++) 
-    {
-      (*theNames)[a] = CORBA::string_dup(TCollection_AsciiString(aNames->Value(a + 1 + ((theWithCreator)?0:1))).ToCString());
-      (*theMinutes)[a] = aMinutes->Value(a + 1 + ((theWithCreator)?0:1));
-      (*theHours)[a] = aHours->Value(a + 1 + ((theWithCreator)?0:1));
-      (*theDays)[a] = aDays->Value(a + 1 + ((theWithCreator)?0:1));
-      (*theMonths)[a] = aMonths->Value(a + 1 + ((theWithCreator)?0:1));
-      (*theYears)[a] = aYears->Value(a + 1 + ((theWithCreator)?0:1));
-    }
-}
-
-char* SALOMEDS_AttributeStudyProperties_i::Store() {
-  Handle(TColStd_HSequenceOfExtendedString) aNames;
-  Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
-  Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
-  aNames = aProp->GetUserNames();
-  aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
-
-  int aLength, anIndex;
-  for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1;
-
-  char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
-
-  sprintf(aProperty,"%c%c", strlen(GetCreationMode())?GetCreationMode()[0]:'0', IsLocked()?'l':'u');
-
-  aLength = aNames->Length();
-  int a = 2;
-  for(anIndex = 1; anIndex  <= aLength; anIndex++) {
-    sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
-           (int)(aMinutes->Value(anIndex)),
-           (int)(aHours->Value(anIndex)),
-           (int)(aDays->Value(anIndex)),
-           (int)(aMonths->Value(anIndex)),
-           (int)(aYears->Value(anIndex)),
-           (char*)(TCollection_AsciiString(aNames->Value(anIndex)).ToCString()));
-    a = strlen(aProperty);
-    aProperty[a++] = 1;
-  }
-  aProperty[a] = 0;
-  return aProperty;
-}
-
-void SALOMEDS_AttributeStudyProperties_i::Restore(const char* value) {
-  char* aCopy = strdup(value);
-  if (aCopy[0] == 'f') SetCreationMode("from scratch");
-  else if (aCopy[0] == 'c') SetCreationMode("copy from");
-  else SetCreationMode("none");
-
-  int anIndex;
-  for(anIndex = 2; anIndex + 2 < strlen(value) ;) {
-    char str[10];
-    Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
-    str[0] = aCopy[anIndex++];
-    str[1] = aCopy[anIndex++];
-    str[2] = 0;
-    aMinute = atoi(str);
-    str[0] = aCopy[anIndex++];
-    str[1] = aCopy[anIndex++];
-    aHour =  atoi(str);
-    str[0] = aCopy[anIndex++];
-    str[1] = aCopy[anIndex++];
-    aDay =  atoi(str);
-    str[0] = aCopy[anIndex++];
-    str[1] = aCopy[anIndex++];
-    aMonth =  atoi(str);
-    str[0] = aCopy[anIndex++];
-    str[1] = aCopy[anIndex++];
-    str[2] = aCopy[anIndex++];
-    str[3] = aCopy[anIndex++];
-    str[4] = 0;
-    aYear = atoi(str);
-    
-    int aNameSize;
-    for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
-    char *aName = new char[aNameSize+1];
-    strncpy(aName, &(aCopy[anIndex]), aNameSize);
-    aName[aNameSize] = 0;
-    SetModification(aName, aMinute,aHour,aDay,aMonth,aYear);
-    delete(aName);
-    anIndex += aNameSize + 1;
-  }
-  if (aCopy[1] == 'l') {
-    SetLocked(Standard_True);
+  theNames->length(aRetLength);
+  theMinutes->length(aRetLength);
+  theHours->length(aRetLength);
+  theDays->length(aRetLength);
+  theMonths->length(aRetLength);
+  theYears->length(aRetLength);
+  int a = 0, ind = ((theWithCreator) ? 1 : 2);
+  for (; ind <= aLength; a++, ind++) {
+    (*theNames)[a] = CORBA::string_dup(aNames[ind-1].c_str());
+    (*theMinutes)[a] = aMinutes[ind-1];
+    (*theHours)[a] = aHours[ind-1];
+    (*theDays)[a] = aDays[ind-1];
+    (*theMonths)[a] = aMonths[ind-1];
+    (*theYears)[a] = aYears[ind-1];
   }
-  SetModified(0);
-  free(aCopy);
 }