Salome HOME
Fix bug in test on 24 cores CPU test
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeTableOfReal.cxx
index 477449df2b0808963c712e0859e1b565463ebd3b..ab0fee33093113bdb54f3d0da716e28dbf6ee14b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -6,7 +6,7 @@
 // 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.
+// 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
@@ -35,15 +35,15 @@ typedef std::map<int, double>::const_iterator MI;
 static std::string getUnit(const std::string& theString)
 {
   std::string aString(theString);
-  int aPos = aString.find(SEPARATOR);
-  return aPos < 0 || aPos == aString.size()-1 ? std::string() : aString.substr(aPos+1, aString.size());
+  size_t aPos = aString.find(SEPARATOR);
+  return aPos >= aString.size()-1 ? std::string() : aString.substr(aPos+1);
 }
 
 static std::string getTitle(const std::string& theString)
 {
   std::string aString(theString);
-  int aPos = aString.find(SEPARATOR);
-  return aPos < 0 ? aString :aString.substr(0, aPos);
+  size_t aPos = aString.find(SEPARATOR);
+  return aPos == std::string::npos ? aString : aString.substr(0, aPos);
 }
 
 const std::string& SALOMEDSImpl_AttributeTableOfReal::GetID() 
@@ -89,7 +89,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetNbColumns(const int theNbColumns)
 
   myNbColumns = theNbColumns;
 
-  while (myCols.size() < myNbColumns) { // append empty columns titles
+  while ((int)myCols.size() < myNbColumns) { // append empty columns titles
     myCols.push_back(std::string(""));
   }
   
@@ -114,17 +114,17 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowData(const int theRow,
                                                    const std::vector<double>& theData) 
 {
   CheckLocked();  
-  if(theData.size() > myNbColumns) SetNbColumns(theData.size());
+  if((int)theData.size() > myNbColumns) SetNbColumns((int)theData.size()); //!< TODO: conversion from size_t to const int, possible loss of data
 
   Backup();
 
-  while (myRows.size() < theRow) { // append new row titles
+  while ((int)myRows.size() < theRow) { // append new row titles
     myRows.push_back(std::string(""));
   }
 
-  int i, aShift = (theRow-1)*myNbColumns, aLength = theData.size();
+  size_t i, aShift = (theRow-1)*myNbColumns, aLength = theData.size();
   for(i = 1; i <= aLength; i++) {
-    myTable[aShift + i] = theData[i-1];
+    myTable[(int)(aShift + i)] = theData[i-1]; //!< TODO: conversion from size_t to int
   }
 
   if(theRow > myNbRows) myNbRows = theRow;
@@ -177,9 +177,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowUnit(const int theRow,
 
 void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const std::vector<std::string>& theUnits)
 {
-  if (theUnits.size() != GetNbRows()) throw DFexception("Invalid number of rows");
-  int aLength = theUnits.size(), i;
-  for(i = 1; i <= aLength; i++) SetRowUnit(i, theUnits[i-1]);
+  if ((int)theUnits.size() != GetNbRows()) throw DFexception("Invalid number of rows");
+  size_t aLength = theUnits.size(), i;
+  for(i = 1; i <= aLength; i++) SetRowUnit((int)i, theUnits[i-1]); //!< TODO: conversion from size_t to int
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
@@ -187,16 +187,16 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const std::vector<std::strin
 std::vector<std::string> SALOMEDSImpl_AttributeTableOfReal::GetRowUnits()
 {
   std::vector<std::string> aSeq;
-  int aLength = myRows.size(), i;
+  size_t aLength = myRows.size(), i;
   for(i=0; i<aLength; i++) aSeq.push_back(getUnit(myRows[i]));
   return aSeq;
 }
 
 void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const std::vector<std::string>& theTitles)
 {
-  if (theTitles.size() != GetNbRows()) throw DFexception("Invalid number of rows");
-  int aLength = theTitles.size(), i;
-  for(i = 1; i <= aLength; i++) SetRowTitle(i, theTitles[i-1]);
+  if ((int)theTitles.size() != GetNbRows()) throw DFexception("Invalid number of rows");
+  size_t aLength = theTitles.size(), i;
+  for(i = 1; i <= aLength; i++) SetRowTitle((int)i, theTitles[i-1]); //!< TODO: conversion from size_t to int
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
@@ -204,7 +204,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const std::vector<std::stri
 std::vector<std::string> SALOMEDSImpl_AttributeTableOfReal::GetRowTitles()
 {
   std::vector<std::string> aSeq;
-  int aLength = myRows.size(), i;
+  size_t aLength = myRows.size(), i;
   for(i=0; i<aLength; i++) aSeq.push_back(getTitle(myRows[i]));
   return aSeq;
 }
@@ -228,14 +228,14 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnData(const int theColumn,
 
   Backup();
 
-  int i, aLength = theData.size();
+  size_t i, aLength = theData.size();
   for(i = 1; i <= aLength; i++) {
-    myTable[myNbColumns*(i-1)+theColumn] = theData[i-1];
+    myTable[myNbColumns*((int)i-1)+theColumn] = theData[i-1]; //!< TODO: conversion from size_t to int
   }
 
-  if(aLength > myNbRows) {
-    myNbRows = aLength;
-    while (myRows.size() < myNbRows) { // append empty row titles
+  if((int)aLength > myNbRows) {
+    myNbRows = (int)aLength; //!< TODO: conversion from size_t to int
+    while ((int)myRows.size() < myNbRows) { // append empty row titles
       myRows.push_back(std::string(""));
     }
   }
@@ -264,7 +264,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitle(const int theColumn,
 {
   CheckLocked();  
   Backup();
-  while(myCols.size() < theColumn) myCols.push_back(std::string(""));
+  while((int)myCols.size() < theColumn) myCols.push_back(std::string(""));
   myCols[theColumn-1] = theTitle;
 
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
@@ -273,14 +273,14 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitle(const int theColumn,
 std::string SALOMEDSImpl_AttributeTableOfReal::GetColumnTitle(const int theColumn) const 
 {
   if(myCols.empty()) return "";
-  if(myCols.size() < theColumn) return "";
+  if((int)myCols.size() < theColumn) return "";
   return myCols[theColumn-1];
 }
 
 void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const std::vector<std::string>& theTitles)
 {
-  if (theTitles.size() != myNbColumns) throw DFexception("Invalid number of columns");
-  int aLength = theTitles.size(), i;
+  if ((int)theTitles.size() != myNbColumns) throw DFexception("Invalid number of columns");
+  size_t aLength = theTitles.size(), i;
   for(i = 0; i < aLength; i++)  myCols[i] = theTitles[i];
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
@@ -289,7 +289,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const std::vector<std::s
 std::vector<std::string> SALOMEDSImpl_AttributeTableOfReal::GetColumnTitles()
 {
   std::vector<std::string> aSeq;
-  int aLength = myCols.size(), i;
+  size_t aLength = myCols.size(), i;
   for(i=0; i<aLength; i++) aSeq.push_back(myCols[i]);
   return aSeq;
 }
@@ -316,7 +316,7 @@ void SALOMEDSImpl_AttributeTableOfReal::PutValue(const double& theValue,
   myTable[anIndex] =  theValue;
 
   if(theRow > myNbRows) {
-    while (myRows.size() < theRow) { // append empty row titles
+    while ((int)myRows.size() < theRow) { // append empty row titles
       myRows.push_back(std::string(""));
     }
     myNbRows = theRow;
@@ -446,7 +446,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::Save()
   int i, j, l;
 
   //Title
-  l = myTitle.size();
+  l = (int)myTitle.size();
   sprintf(buffer, "%d\n", l);
   aString+=buffer;
   for(i=0; i<l; i++) {
@@ -460,7 +460,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::Save()
 
   //Row titles
   for(i=0; i<myNbRows; i++) {
-    l = myRows[i].size();
+    l = (int)myRows[i].size();
     sprintf(buffer, "%d\n", l);
     aString+=buffer;
     for(j=0; j<l; j++) {
@@ -475,7 +475,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::Save()
 
   //Columns titles
   for(i=0; i<myNbColumns; i++) {
-    l = myCols[i].size();
+    l = (int)myCols[i].size();
     sprintf(buffer, "%d\n", l);
     aString+=buffer;
     for(j=0; j<l; j++) {
@@ -485,7 +485,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::Save()
   }
 
   //Store the table values
-  l = myTable.size();
+  l = (int)myTable.size();
   sprintf(buffer, "%d\n", l);
   aString+=buffer;
   for(MI p = myTable.begin(); p != myTable.end(); p++) {
@@ -586,12 +586,12 @@ std::vector<int> SALOMEDSImpl_AttributeTableOfReal::SortRow(const int theRow, So
     }
     result = indices;
 
-    for ( int col = 0; col < indices.size(); col++ ) {
+    for ( int col = 0; col < (int)indices.size(); col++ ) {
       int idx = indices[col];
       if ( col+1 == idx ) continue;
       SwapCells(theRow, col+1, theRow, idx);
       int idx1 = 0;
-      for ( int i = col+1; i < indices.size() && idx1 == 0; i++)
+      for ( int i = col+1; i < (int)indices.size() && idx1 == 0; i++)
        if ( indices[i] == col+1 ) idx1 = i;
       indices[idx1] = idx;
     }
@@ -626,12 +626,12 @@ std::vector<int> SALOMEDSImpl_AttributeTableOfReal::SortColumn(const int theColu
     }
     result = indices;
 
-    for ( int row = 0; row < indices.size(); row++ ) {
+    for ( int row = 0; row < (int)indices.size(); row++ ) {
       int idx = indices[row];
       if ( row+1 == idx ) continue;
       SwapCells(row+1, theColumn, idx, theColumn);
       int idx1 = 0;
-      for ( int i = row+1; i < indices.size() && idx1 == 0; i++)
+      for ( int i = row+1; i < (int)indices.size() && idx1 == 0; i++)
        if ( indices[i] == row+1 ) idx1 = i;
       indices[idx1] = idx;
     }
@@ -666,12 +666,12 @@ std::vector<int> SALOMEDSImpl_AttributeTableOfReal::SortByRow(const int theRow,
     }
     result = indices;
 
-    for ( int col = 0; col < indices.size(); col++ ) {
+    for ( int col = 0; col < (int)indices.size(); col++ ) {
       int idx = indices[col];
       if ( col+1 == idx ) continue;
       SwapColumns(col+1, idx);
       int idx1 = 0;
-      for ( int i = col+1; i < indices.size() && idx1 == 0; i++)
+      for ( int i = col+1; i < (int)indices.size() && idx1 == 0; i++)
        if ( indices[i] == col+1 ) idx1 = i;
       indices[idx1] = idx;
     }
@@ -706,12 +706,12 @@ std::vector<int> SALOMEDSImpl_AttributeTableOfReal::SortByColumn(const int theCo
     }
     result = indices;
 
-    for ( int row = 0; row < indices.size(); row++ ) {
+    for ( int row = 0; row < (int)indices.size(); row++ ) {
       int idx = indices[row];
       if ( row+1 == idx ) continue;
       SwapRows(row+1, idx);
       int idx1 = 0;
-      for ( int i = row+1; i < indices.size() && idx1 == 0; i++)
+      for ( int i = row+1; i < (int)indices.size() && idx1 == 0; i++)
        if ( indices[i] == row+1 ) idx1 = i;
       indices[idx1] = idx;
     }