From beda9e53a9befcc1eaa4d43a6ee740ef9c6b9dc8 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 7 Apr 2010 10:57:28 +0000 Subject: [PATCH] Fix bugs of GetRowUnits() / GetRowTitles() functions --- .../SALOMEDSImpl_AttributeTableOfReal.cxx | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx index cc52043b4..081dcad36 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx @@ -27,27 +27,22 @@ #include #include -using namespace std; - #define SEPARATOR '\1' -typedef map::const_iterator MI; +typedef std::map::const_iterator MI; -static std::string getUnit(std::string theString) +static std::string getUnit(const std::string& theString) { std::string aString(theString); int aPos = aString.find(SEPARATOR); - if(aPos <= 0 || aPos == aString.size() ) return std::string(); - return aString.substr(aPos+1, aString.size()); + return aPos < 0 || aPos == aString.size()-1 ? std::string() : aString.substr(aPos+1, aString.size()); } -static std::string getTitle(std::string theString) +static std::string getTitle(const std::string& theString) { std::string aString(theString); int aPos = aString.find(SEPARATOR); - if(aPos < 0) return aString; - if(aPos == 0) return std::string(); - return aString.substr(0, aPos); + return aPos < 0 ? aString :aString.substr(0, aPos); } const std::string& SALOMEDSImpl_AttributeTableOfReal::GetID() @@ -78,7 +73,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetNbColumns(const int theNbColumns) CheckLocked(); Backup(); - map aMap; + std::map aMap; aMap = myTable; myTable.clear(); @@ -94,7 +89,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetNbColumns(const int theNbColumns) myNbColumns = theNbColumns; while (myCols.size() < myNbColumns) { // append empty columns titles - myCols.push_back(string("")); + myCols.push_back(std::string("")); } SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved @@ -115,7 +110,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::GetTitle() const } void SALOMEDSImpl_AttributeTableOfReal::SetRowData(const int theRow, - const vector& theData) + const std::vector& theData) { CheckLocked(); if(theData.size() > myNbColumns) SetNbColumns(theData.size()); @@ -136,9 +131,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowData(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetRowData(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetRowData(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = (theRow-1)*myNbColumns; for(i = 1; i <= myNbColumns; i++) { if(myTable.find(aShift+i) != myTable.end()) @@ -180,7 +175,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowUnit(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const vector& theUnits) +void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const std::vector& theUnits) { if (theUnits.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theUnits.size(), i; @@ -189,15 +184,15 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const vector& theUni SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetRowUnits() +std::vector SALOMEDSImpl_AttributeTableOfReal::GetRowUnits() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theTitles) +void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const std::vector& theTitles) { if (theTitles.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theTitles.size(), i; @@ -206,9 +201,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const vector& theTi SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetRowTitles() +std::vector SALOMEDSImpl_AttributeTableOfReal::GetRowTitles() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theData) + const std::vector& theData) { CheckLocked(); if(theColumn > myNbColumns) SetNbColumns(theColumn); @@ -242,7 +237,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnData(const int theColumn, if(aLength > myNbRows) { myNbRows = aLength; while (myRows.size() < myNbRows) { // append empty row titles - myRows.push_back(string("")); + myRows.push_back(std::string("")); } } @@ -250,9 +245,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnData(const int theColumn, } -vector SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -284,7 +279,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::GetColumnTitle(const int theColum return myCols[theColumn-1]; } -void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const vector& theTitles) +void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const std::vector& theTitles) { if (theTitles.size() != myNbColumns) throw DFexception("Invalid number of columns"); int aLength = theTitles.size(), i; @@ -293,9 +288,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const vector& th SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetColumnTitles() +std::vector SALOMEDSImpl_AttributeTableOfReal::GetColumnTitles() { - vector aSeq; + std::vector aSeq; int aLength = myCols.size(), i; for(i=0; i SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = myNbColumns*(theRow-1); for(i = 1; i <= myNbColumns; i++) { @@ -419,9 +414,9 @@ vector SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow return aSeq; } -vector SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -432,9 +427,9 @@ vector SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const int the return aSeq; } -string SALOMEDSImpl_AttributeTableOfReal::Save() +std::string SALOMEDSImpl_AttributeTableOfReal::Save() { - string aString; + std::string aString; char* buffer = new char[1024]; int i, j, l; @@ -490,9 +485,9 @@ string SALOMEDSImpl_AttributeTableOfReal::Save() return aString; } -void SALOMEDSImpl_AttributeTableOfReal::Load(const string& value) +void SALOMEDSImpl_AttributeTableOfReal::Load(const std::string& value) { - vector v; + std::vector v; int i, j, l, pos, aSize = (int)value.size(); for(i = 0, pos = 0; i