From d585e74e5154f596060ee6b841af8189e8317328 Mon Sep 17 00:00:00 2001 From: msv Date: Thu, 9 Apr 2015 16:34:06 +0300 Subject: [PATCH] 0025394: Make it possible to store/retrieve the list-based attributes containing no items Attention! It is not a complete patch. First patch for Binary schema. Fix for Xml schema. Patch for the standard schema. Added new Draw commands to test ExtStringList & ReferenceList attributes. Fix of a small bug in ReferenceListDriver & improvement of Draw Get commands. Replace tabs with spaces in newly added lines. Test cases for issue CR25394 --- .../BinMDataStd_BooleanListDriver.cxx | 29 +- .../BinMDataStd_ExtStringListDriver.cxx | 26 +- .../BinMDataStd_IntegerListDriver.cxx | 11 +- .../BinMDataStd_RealListDriver.cxx | 11 +- .../BinMDataStd_ReferenceListDriver.cxx | 14 +- src/DDataStd/DDataStd_BasicCommands.cxx | 331 ++++++++++++++---- .../MDataStd_BooleanListRetrievalDriver.cxx | 15 +- .../MDataStd_BooleanListStorageDriver.cxx | 15 +- .../MDataStd_ExtStringListRetrievalDriver.cxx | 19 +- .../MDataStd_ExtStringListStorageDriver.cxx | 18 +- .../MDataStd_IntegerListRetrievalDriver.cxx | 12 +- .../MDataStd_IntegerListStorageDriver.cxx | 15 +- .../MDataStd_RealListRetrievalDriver.cxx | 15 +- .../MDataStd_RealListStorageDriver.cxx | 15 +- .../MDataStd_ReferenceListRetrievalDriver.cxx | 25 +- .../MDataStd_ReferenceListStorageDriver.cxx | 24 +- .../XmlMDataStd_BooleanListDriver.cxx | 20 +- .../XmlMDataStd_ExtStringListDriver.cxx | 5 +- .../XmlMDataStd_IntegerListDriver.cxx | 22 +- .../XmlMDataStd_RealListDriver.cxx | 23 +- .../XmlMDataStd_ReferenceListDriver.cxx | 15 +- tests/bugs/caf/bug25394_1 | 127 +++++++ tests/bugs/caf/bug25394_2 | 127 +++++++ tests/bugs/caf/bug25394_3 | 127 +++++++ 24 files changed, 838 insertions(+), 223 deletions(-) create mode 100755 tests/bugs/caf/bug25394_1 create mode 100755 tests/bugs/caf/bug25394_2 create mode 100755 tests/bugs/caf/bug25394_3 diff --git a/src/BinMDataStd/BinMDataStd_BooleanListDriver.cxx b/src/BinMDataStd/BinMDataStd_BooleanListDriver.cxx index d821e978c0..50d132a6f2 100644 --- a/src/BinMDataStd/BinMDataStd_BooleanListDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_BooleanListDriver.cxx @@ -48,14 +48,15 @@ Standard_Boolean BinMDataStd_BooleanListDriver::Paste(const BinObjMgt_Persistent Standard_Integer aIndex, aFirstInd, aLastInd; if (! (theSource >> aFirstInd >> aLastInd)) return Standard_False; + if(aLastInd == 0) return Standard_True; + const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return Standard_False; - TColStd_Array1OfByte aTargetArray(aFirstInd, aLastInd); theSource.GetByteArray (&aTargetArray(aFirstInd), aLength); - Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theTarget); + const Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theTarget); for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++) { anAtt->Append(aTargetArray.Value(aIndex) ? Standard_True : Standard_False); @@ -71,22 +72,18 @@ void BinMDataStd_BooleanListDriver::Paste(const Handle(TDF_Attribute)& theSource BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& ) const { - Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theSource); - const Standard_Integer aFirstInd = 1; - const Standard_Integer aLastInd = anAtt->Extent(); + const Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theSource); + const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; + const Standard_Integer aLastInd(anAtt->Extent()); const Standard_Integer aLength = aLastInd - aFirstInd + 1; - if (aLength <= 0) - return; + if (aLength <= 0) return; theTarget << aFirstInd << aLastInd; + if(aLastInd == 0) return; TColStd_Array1OfByte aSourceArray(aFirstInd, aLastInd); - if (aLastInd >= 1) - { - TDataStd_ListIteratorOfListOfByte itr(anAtt->List()); - for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) - { - aSourceArray.SetValue(i, itr.Value()); - } - Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(aFirstInd); - theTarget.PutByteArray(aPtr, aLength); + TDataStd_ListIteratorOfListOfByte itr(anAtt->List()); + for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) { + aSourceArray.SetValue(i, itr.Value()); } + Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(aFirstInd); + theTarget.PutByteArray(aPtr, aLength); } diff --git a/src/BinMDataStd/BinMDataStd_ExtStringListDriver.cxx b/src/BinMDataStd/BinMDataStd_ExtStringListDriver.cxx index 16790e78cf..f8b41978e2 100644 --- a/src/BinMDataStd/BinMDataStd_ExtStringListDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_ExtStringListDriver.cxx @@ -41,18 +41,20 @@ Handle(TDF_Attribute) BinMDataStd_ExtStringListDriver::NewEmpty() const //function : Paste //purpose : persistent -> transient (retrieve) //======================================================================= -Standard_Boolean BinMDataStd_ExtStringListDriver::Paste(const BinObjMgt_Persistent& theSource, - const Handle(TDF_Attribute)& theTarget, - BinObjMgt_RRelocationTable& ) const +Standard_Boolean BinMDataStd_ExtStringListDriver::Paste + (const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& ) const { Standard_Integer aFirstInd, aLastInd; if (! (theSource >> aFirstInd >> aLastInd)) return Standard_False; + if(aLastInd == 0) return Standard_True; const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return Standard_False; - - Handle(TDataStd_ExtStringList) anAtt = Handle(TDataStd_ExtStringList)::DownCast(theTarget); + const Handle(TDataStd_ExtStringList) anAtt = + Handle(TDataStd_ExtStringList)::DownCast(theTarget); for (Standard_Integer i = aFirstInd; i <= aLastInd; i ++) { TCollection_ExtendedString aStr; @@ -70,13 +72,15 @@ Standard_Boolean BinMDataStd_ExtStringListDriver::Paste(const BinObjMgt_Persiste //function : Paste //purpose : transient -> persistent (store) //======================================================================= -void BinMDataStd_ExtStringListDriver::Paste(const Handle(TDF_Attribute)& theSource, - BinObjMgt_Persistent& theTarget, - BinObjMgt_SRelocationTable& ) const +void BinMDataStd_ExtStringListDriver::Paste + (const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& ) const { - Handle(TDataStd_ExtStringList) anAtt = Handle(TDataStd_ExtStringList)::DownCast(theSource); - const Standard_Integer aFirstInd = 1; - const Standard_Integer aLastInd = anAtt->Extent(); + const Handle(TDataStd_ExtStringList) anAtt = + Handle(TDataStd_ExtStringList)::DownCast(theSource); + const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; + const Standard_Integer aLastInd(anAtt->Extent()); theTarget << aFirstInd << aLastInd; TDataStd_ListIteratorOfListOfExtendedString itr(anAtt->List()); for (; itr.More(); itr.Next()) diff --git a/src/BinMDataStd/BinMDataStd_IntegerListDriver.cxx b/src/BinMDataStd/BinMDataStd_IntegerListDriver.cxx index e8915d505f..7ec2258701 100644 --- a/src/BinMDataStd/BinMDataStd_IntegerListDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_IntegerListDriver.cxx @@ -48,6 +48,8 @@ Standard_Boolean BinMDataStd_IntegerListDriver::Paste(const BinObjMgt_Persistent Standard_Integer aIndex, aFirstInd, aLastInd; if (! (theSource >> aFirstInd >> aLastInd)) return Standard_False; + if(aLastInd == 0) return Standard_True; + const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return Standard_False; @@ -55,7 +57,7 @@ Standard_Boolean BinMDataStd_IntegerListDriver::Paste(const BinObjMgt_Persistent TColStd_Array1OfInteger aTargetArray(aFirstInd, aLastInd); theSource.GetIntArray (&aTargetArray(aFirstInd), aLength); - Handle(TDataStd_IntegerList) anAtt = Handle(TDataStd_IntegerList)::DownCast(theTarget); + const Handle(TDataStd_IntegerList) anAtt = Handle(TDataStd_IntegerList)::DownCast(theTarget); for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++) { anAtt->Append(aTargetArray.Value(aIndex)); @@ -71,13 +73,14 @@ void BinMDataStd_IntegerListDriver::Paste(const Handle(TDF_Attribute)& theSource BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& ) const { - Handle(TDataStd_IntegerList) anAtt = Handle(TDataStd_IntegerList)::DownCast(theSource); - const Standard_Integer aFirstInd = 1; - const Standard_Integer aLastInd = anAtt->Extent(); + const Handle(TDataStd_IntegerList) anAtt = Handle(TDataStd_IntegerList)::DownCast(theSource); + const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; + const Standard_Integer aLastInd(anAtt->Extent()); const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return; theTarget << aFirstInd << aLastInd; + if(aLastInd == 0) return; TColStd_Array1OfInteger aSourceArray(aFirstInd, aLastInd); if (aLastInd >= 1) { diff --git a/src/BinMDataStd/BinMDataStd_RealListDriver.cxx b/src/BinMDataStd/BinMDataStd_RealListDriver.cxx index aa2599c8dd..bfd5330027 100644 --- a/src/BinMDataStd/BinMDataStd_RealListDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_RealListDriver.cxx @@ -48,6 +48,8 @@ Standard_Boolean BinMDataStd_RealListDriver::Paste(const BinObjMgt_Persistent& Standard_Integer aIndex, aFirstInd, aLastInd; if (! (theSource >> aFirstInd >> aLastInd)) return Standard_False; + if(aLastInd == 0) return Standard_True; + const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return Standard_False; @@ -55,7 +57,7 @@ Standard_Boolean BinMDataStd_RealListDriver::Paste(const BinObjMgt_Persistent& TColStd_Array1OfReal aTargetArray(aFirstInd, aLastInd); theSource.GetRealArray (&aTargetArray(aFirstInd), aLength); - Handle(TDataStd_RealList) anAtt = Handle(TDataStd_RealList)::DownCast(theTarget); + const Handle(TDataStd_RealList) anAtt = Handle(TDataStd_RealList)::DownCast(theTarget); for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++) { anAtt->Append(aTargetArray.Value(aIndex)); @@ -71,13 +73,14 @@ void BinMDataStd_RealListDriver::Paste(const Handle(TDF_Attribute)& theSource, BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& ) const { - Handle(TDataStd_RealList) anAtt = Handle(TDataStd_RealList)::DownCast(theSource); - const Standard_Integer aFirstInd = 1; - const Standard_Integer aLastInd = anAtt->Extent(); + const Handle(TDataStd_RealList) anAtt = Handle(TDataStd_RealList)::DownCast(theSource); + const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; + const Standard_Integer aLastInd(anAtt->Extent()); const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return; theTarget << aFirstInd << aLastInd; + if(aLastInd == 0) return; TColStd_Array1OfReal aSourceArray(aFirstInd, aLastInd); if (aLastInd >= 1) { diff --git a/src/BinMDataStd/BinMDataStd_ReferenceListDriver.cxx b/src/BinMDataStd/BinMDataStd_ReferenceListDriver.cxx index 27a49ce74c..0454c2dc0f 100644 --- a/src/BinMDataStd/BinMDataStd_ReferenceListDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_ReferenceListDriver.cxx @@ -49,11 +49,13 @@ Standard_Boolean BinMDataStd_ReferenceListDriver::Paste(const BinObjMgt_Persiste Standard_Integer aFirstInd, aLastInd; if (! (theSource >> aFirstInd >> aLastInd)) return Standard_False; + if(aLastInd == 0) return Standard_True; + const Standard_Integer aLength = aLastInd - aFirstInd + 1; if (aLength <= 0) return Standard_False; - Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theTarget); + const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theTarget); for (Standard_Integer i = aFirstInd; i <= aLastInd; i++) { TCollection_AsciiString entry; @@ -76,13 +78,15 @@ void BinMDataStd_ReferenceListDriver::Paste(const Handle(TDF_Attribute)& theSour BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& ) const { - Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theSource); - if (anAtt->IsEmpty()) + const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theSource); + if (anAtt.IsNull()) return; - Standard_Integer aFirstInd = 1, aLastInd = anAtt->Extent(), i = aFirstInd; + const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; + const Standard_Integer aLastInd(anAtt->Extent()); theTarget << aFirstInd << aLastInd; + if(aLastInd == 0) return; TDF_ListIteratorOfLabelList itr(anAtt->List()); - for (; itr.More(); itr.Next(), i++) + for (Standard_Integer i = aFirstInd; itr.More(); itr.Next(), i++) { TDF_Label L = itr.Value(); if (!L.IsNull()) diff --git a/src/DDataStd/DDataStd_BasicCommands.cxx b/src/DDataStd/DDataStd_BasicCommands.cxx index 319f9ba462..91b3967449 100644 --- a/src/DDataStd/DDataStd_BasicCommands.cxx +++ b/src/DDataStd/DDataStd_BasicCommands.cxx @@ -94,6 +94,10 @@ #include #include #include +#include +#include +#include +#include //======================================================================= //function : DDataStd_SetInteger @@ -1474,6 +1478,65 @@ static Standard_Integer DDataStd_SetBooleanArrayValue (Draw_Interpretor& di, return 1; } +//======================================================================= +//function : DDataStd_SetExtStringList (DF, entry, elmt1, elmt2, ... ) +//======================================================================= +static Standard_Integer DDataStd_SetExtStringList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb > 2) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + Handle(TDataStd_ExtStringList) A = TDataStd_ExtStringList::Set(label); + for(Standard_Integer i = 3; i <= nb - 1; i++) + { + TCollection_ExtendedString aValue(arg[i]); + A->Append(aValue); + } + return 0; + } + di << "DDataStd_SetExtStringList: Error" << "\n"; + return 1; +} +// +//======================================================================= +//function : DDataStd_SetReferenceList (DF, entry, elmt1, elmt2, ... ) +//======================================================================= +static Standard_Integer DDataStd_SetReferenceList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb > 2) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + if(!label.IsNull()) { + Handle(TDataStd_ReferenceList) A = TDataStd_ReferenceList::Set(label); + for(Standard_Integer i = 3; i <= nb - 1; i++) + { + TDF_Label aValueLabel; + DDF::AddLabel(DF, arg[i], aValueLabel); + if(aValueLabel.IsNull()) continue; + A->Append(aValueLabel); + } + return 0; + } + } + di << "DDataStd_SetReferenceList: Error" << "\n"; + return 1; +} + + //======================================================================= //function : SetBooleanList (DF, entry, elmt1, elmt2, ... ) //======================================================================= @@ -1761,107 +1824,228 @@ static Standard_Integer DDataStd_ChangeByteArray (Draw_Interpretor& di, //function : GetBooleanList (DF, entry ) //======================================================================= static Standard_Integer DDataStd_GetBooleanList (Draw_Interpretor& di, - Standard_Integer, + Standard_Integer nb, const char** arg) { - Handle(TDF_Data) DF; - if (!DDF::GetDF(arg[1],DF)) + if (nb == 3) { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) return 1; - TDF_Label label; - if ( !DDF::FindLabel(DF, arg[2], label) ) - { - di << "No label for entry" << "\n"; - return 1; - } + TDF_Label label; + if ( !DDF::FindLabel(DF, arg[2], label) ) + { + di << "No label for entry" << "\n"; + return 1; + } - Handle(TDataStd_BooleanList) A; - if ( !label.FindAttribute(TDataStd_BooleanList::GetID(), A) ) - { - di << "There is no TDataStd_BooleanList at label" << "\n"; - return 1; - } + Handle(TDataStd_BooleanList) A; + if ( !label.FindAttribute(TDataStd_BooleanList::GetID(), A) ) + { + di << "There is no TDataStd_BooleanList at label" << "\n"; + return 1; + } - const TDataStd_ListOfByte& bList = A->List(); - TDataStd_ListIteratorOfListOfByte itr(bList); - for (; itr.More(); itr.Next()) - { - di << (Standard_Integer) itr.Value() << " "; + const TDataStd_ListOfByte& bList = A->List(); + Standard_Boolean isEmpty = (bList.Extent() > 0) ? Standard_False : Standard_True; + if(!isEmpty) { + TDataStd_ListIteratorOfListOfByte itr(bList); + for (; itr.More(); itr.Next()) + { + di << (Standard_Integer) itr.Value() << " "; + } + di << "\n"; + } else + di << "List is empty" << "\n"; + return 0; } - di << "\n"; - return 0; + di << "DDataStd_GetBooleanList: Error" << "\n"; + return 1; } //======================================================================= //function : GetIntegerList (DF, entry ) //======================================================================= static Standard_Integer DDataStd_GetIntegerList (Draw_Interpretor& di, - Standard_Integer, + Standard_Integer nb, const char** arg) -{ - Handle(TDF_Data) DF; - if (!DDF::GetDF(arg[1],DF)) +{ + if (nb == 3) { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) return 1; - TDF_Label label; - if ( !DDF::FindLabel(DF, arg[2], label) ) - { - di << "No label for entry" << "\n"; - return 1; - } + TDF_Label label; + if ( !DDF::FindLabel(DF, arg[2], label) ) + { + di << "No label for entry" << "\n"; + return 1; + } - Handle(TDataStd_IntegerList) A; - if ( !label.FindAttribute(TDataStd_IntegerList::GetID(), A) ) - { - di << "There is no TDataStd_IntegerList at label" << "\n"; - return 1; - } + Handle(TDataStd_IntegerList) A; + if ( !label.FindAttribute(TDataStd_IntegerList::GetID(), A) ) + { + di << "There is no TDataStd_IntegerList at label" << "\n"; + return 1; + } - const TColStd_ListOfInteger& iList = A->List(); - TColStd_ListIteratorOfListOfInteger itr(iList); - for (; itr.More(); itr.Next()) - { - di << itr.Value() << " "; + const TColStd_ListOfInteger& iList = A->List(); + Standard_Boolean isEmpty = (iList.Extent() > 0) ? Standard_False : Standard_True; + if(!isEmpty) { + TColStd_ListIteratorOfListOfInteger itr(iList); + for (; itr.More(); itr.Next()) + { + di << itr.Value() << " "; + } + di << "\n"; + } else + di << "List is empty" << "\n"; + + return 0; } - di << "\n"; - return 0; + di << "DDataStd_GetIntegerList: Error" << "\n"; + return 1; } //======================================================================= //function : GetRealList (DF, entry ) //======================================================================= static Standard_Integer DDataStd_GetRealList (Draw_Interpretor& di, - Standard_Integer, + Standard_Integer nb, const char** arg) { - Handle(TDF_Data) DF; - if (!DDF::GetDF(arg[1],DF)) + if (nb == 3) { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) return 1; - TDF_Label label; - if ( !DDF::FindLabel(DF, arg[2], label) ) - { - di << "No label for entry" << "\n"; - return 1; - } + TDF_Label label; + if ( !DDF::FindLabel(DF, arg[2], label) ) + { + di << "No label for entry" << "\n"; + return 1; + } - Handle(TDataStd_RealList) A; - if ( !label.FindAttribute(TDataStd_RealList::GetID(), A) ) - { - di << "There is no TDataStd_RealList at label" << "\n"; - return 1; - } + Handle(TDataStd_RealList) A; + if ( !label.FindAttribute(TDataStd_RealList::GetID(), A) ) + { + di << "There is no TDataStd_RealList at label" << "\n"; + return 1; + } - const TColStd_ListOfReal& iList = A->List(); - TColStd_ListIteratorOfListOfReal itr(iList); - for (; itr.More(); itr.Next()) - { - di << itr.Value() << " "; + const TColStd_ListOfReal& rList = A->List(); + Standard_Boolean isEmpty = (rList.Extent() > 0) ? Standard_False : Standard_True; + if(!isEmpty) { + TColStd_ListIteratorOfListOfReal itr(rList); + for (; itr.More(); itr.Next()) + { + di << itr.Value() << " "; + } + di << "\n"; + } else + di << "List is empty" << "\n"; + return 0; } - di << "\n"; - return 0; + di << "DDataStd_GetRealList: Error" << "\n"; + return 1; } +//======================================================================= +//function : DDataStd_GetExtStringList (DF, entry) +//======================================================================= +static Standard_Integer DDataStd_GetExtStringList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 3) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + if ( !DDF::FindLabel(DF, arg[2], label) ) + { + di << "No label for entry" << "\n"; + return 1; + } + + Handle(TDataStd_ExtStringList) A; + if ( !label.FindAttribute(TDataStd_ExtStringList::GetID(), A) ) + { + di << "There is no TDataStd_ExtStringList at label" << "\n"; + return 1; + } + + const TDataStd_ListOfExtendedString& aList = A->List(); + Standard_Boolean isEmpty = (aList.Extent() > 0) ? Standard_False : Standard_True; + if(!isEmpty) { + TDataStd_ListIteratorOfListOfExtendedString itr(aList); + for (; itr.More(); itr.Next()) + { + const TCollection_ExtendedString& aStr = itr.Value(); + di << aStr << " "; + } + di << "\n"; + } + else { + di << "List is empty" << "\n"; + } + return 0; + } + di << "DDataStd_GetExtStringList: Error" << "\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_GetReferenceList (DF, entry ) +//======================================================================= +static Standard_Integer DDataStd_GetReferenceList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 3) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + if ( !DDF::FindLabel(DF, arg[2], label) ) + { + di << "No label for entry" << "\n"; + return 1; + } + + Handle(TDataStd_ReferenceList) A; + if ( !label.FindAttribute(TDataStd_ReferenceList::GetID(), A) ) + { + di << "There is no TDataStd_ReferenceList at label" << "\n"; + return 1; + } + + const TDF_LabelList& aList = A->List(); + Standard_Boolean isEmpty = (aList.Extent() > 0) ? Standard_False : Standard_True; + if(!isEmpty) { + TDF_ListIteratorOfLabelList itr(aList); + for (; itr.More(); itr.Next()) + { + const TDF_Label& aLabel = itr.Value(); + if (!aLabel.IsNull()) { + TCollection_AsciiString entry; + TDF_Tool::Entry(aLabel, entry); + di << entry.ToCString() << " "; + } + } + di << "\n"; + } else + di << "List is empty" << "\n"; + return 0; + } + di << "DDataStd_GetReferenceList: Error" << "\n"; + return 1; +} +// //======================================================================= //function : SetIntPackedMap (DF, entry, isDelta, key1, key2, ... //======================================================================= @@ -3177,6 +3361,13 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) "SetRealList (DF, entry, elmt1, elmt2, ... )", __FILE__, DDataStd_SetRealList, g); + theCommands.Add ("SetExtStringList", + "SetExtStringList (DF, entry, elmt1, elmt2, ... )", + __FILE__, DDataStd_SetExtStringList, g); + + theCommands.Add ("SetReferenceList", + "SetReferenceList (DF, entry, elmt1, elmt2, ... )", + __FILE__, DDataStd_SetReferenceList, g); // GET @@ -3285,7 +3476,13 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) "GetRealList (DF, entry )", __FILE__, DDataStd_GetRealList, g); + theCommands.Add ("GetExtStringList", + "GetExtStringList (DF, entry)", + __FILE__, DDataStd_GetExtStringList, g); + theCommands.Add ("GetReferenceList", + "GetReferenceList (DF, entry)", + __FILE__, DDataStd_GetReferenceList, g); // ========================= UTF ===================================== const char* ggg = "UTF Commands"; diff --git a/src/MDataStd/MDataStd_BooleanListRetrievalDriver.cxx b/src/MDataStd/MDataStd_BooleanListRetrievalDriver.cxx index dbe7875513..3a9f7dfb68 100644 --- a/src/MDataStd/MDataStd_BooleanListRetrievalDriver.cxx +++ b/src/MDataStd/MDataStd_BooleanListRetrievalDriver.cxx @@ -64,12 +64,13 @@ void MDataStd_BooleanListRetrievalDriver::Paste(const Handle(PDF_Attribute)& Sou const Handle(TDF_Attribute)& Target, const Handle(MDF_RRelocationTable)& ) const { - Handle(PDataStd_BooleanList) S = Handle(PDataStd_BooleanList)::DownCast (Source); - Handle(TDataStd_BooleanList) T = Handle(TDataStd_BooleanList)::DownCast (Target); - - Standard_Integer i, lower = S->Lower(), upper = S->Upper(); - for (i = lower; i <= upper; i++) - { - T->Append(S->Value(i)); + const Handle(PDataStd_BooleanList) S = Handle(PDataStd_BooleanList)::DownCast (Source); + const Handle(TDataStd_BooleanList) T = Handle(TDataStd_BooleanList)::DownCast (Target); + if(!S.IsNull()) { + Standard_Integer i, lower = S->Lower(), upper = S->Upper(); + if(upper > 0) + for (i = lower; i <= upper; i++) { + T->Append(S->Value(i)); + } } } diff --git a/src/MDataStd/MDataStd_BooleanListStorageDriver.cxx b/src/MDataStd/MDataStd_BooleanListStorageDriver.cxx index 582818623c..63910a6d20 100644 --- a/src/MDataStd/MDataStd_BooleanListStorageDriver.cxx +++ b/src/MDataStd/MDataStd_BooleanListStorageDriver.cxx @@ -66,16 +66,19 @@ void MDataStd_BooleanListStorageDriver::Paste(const Handle(TDF_Attribute)& Sour const Handle(PDF_Attribute)& Target, const Handle(MDF_SRelocationTable)& /*RelocTable*/) const { - Handle(TDataStd_BooleanList) S = Handle(TDataStd_BooleanList)::DownCast (Source); - Handle(PDataStd_BooleanList) T = Handle(PDataStd_BooleanList)::DownCast (Target); + const Handle(TDataStd_BooleanList) S = Handle(TDataStd_BooleanList)::DownCast (Source); + const Handle(PDataStd_BooleanList) T = Handle(PDataStd_BooleanList)::DownCast (Target); - Standard_Integer lower = 1, upper = S->Extent(), i = lower; - if (upper >= lower) + Standard_Integer lower(1), upper = S->Extent(); + if(upper == 0) { + lower = 0; + T->Init(lower, upper); + } + else if (upper >= lower) { T->Init(lower, upper); TDataStd_ListIteratorOfListOfByte itr(S->List()); - for (; itr.More(); itr.Next(), i++) - { + for (Standard_Integer i = lower; itr.More(); itr.Next(), i++) { T->SetValue(i, itr.Value()); } } diff --git a/src/MDataStd/MDataStd_ExtStringListRetrievalDriver.cxx b/src/MDataStd/MDataStd_ExtStringListRetrievalDriver.cxx index dbc601f949..420601c612 100644 --- a/src/MDataStd/MDataStd_ExtStringListRetrievalDriver.cxx +++ b/src/MDataStd/MDataStd_ExtStringListRetrievalDriver.cxx @@ -66,14 +66,15 @@ void MDataStd_ExtStringListRetrievalDriver::Paste(const Handle(PDF_Attribute)& S const Handle(TDF_Attribute)& Target, const Handle(MDF_RRelocationTable)& ) const { - Handle(PDataStd_ExtStringList) S = Handle(PDataStd_ExtStringList)::DownCast (Source); - Handle(TDataStd_ExtStringList) T = Handle(TDataStd_ExtStringList)::DownCast (Target); - + const Handle(PDataStd_ExtStringList) S = Handle(PDataStd_ExtStringList)::DownCast (Source); + const Handle(TDataStd_ExtStringList) T = Handle(TDataStd_ExtStringList)::DownCast (Target); + if(S.IsNull()) return; Standard_Integer i, lower = S->Lower(), upper = S->Upper(); - for (i = lower; i <= upper; i++) - { - const Handle(PCollection_HExtendedString)& pvalue = S->Value(i); - TCollection_ExtendedString tvalue = pvalue->Convert(); - T->Append(tvalue); - } + if(upper > 0) + for (i = lower; i <= upper; i++) + { + const Handle(PCollection_HExtendedString)& pvalue = S->Value(i); + TCollection_ExtendedString tvalue = pvalue->Convert(); + T->Append(tvalue); + } } diff --git a/src/MDataStd/MDataStd_ExtStringListStorageDriver.cxx b/src/MDataStd/MDataStd_ExtStringListStorageDriver.cxx index a807aae865..982e3a34b8 100644 --- a/src/MDataStd/MDataStd_ExtStringListStorageDriver.cxx +++ b/src/MDataStd/MDataStd_ExtStringListStorageDriver.cxx @@ -67,18 +67,22 @@ void MDataStd_ExtStringListStorageDriver::Paste(const Handle(TDF_Attribute)& Sou const Handle(PDF_Attribute)& Target, const Handle(MDF_SRelocationTable)& /*RelocTable*/) const { - Handle(TDataStd_ExtStringList) S = Handle(TDataStd_ExtStringList)::DownCast (Source); - Handle(PDataStd_ExtStringList) T = Handle(PDataStd_ExtStringList)::DownCast (Target); - - Standard_Integer lower = 1, upper = S->Extent(), i = lower; - if (upper >= lower) + const Handle(TDataStd_ExtStringList) S = Handle(TDataStd_ExtStringList)::DownCast (Source); + const Handle(PDataStd_ExtStringList) T = Handle(PDataStd_ExtStringList)::DownCast (Target); + if(S.IsNull()) return; + Standard_Integer lower(1), upper = S->Extent(); + if(upper == 0) { + lower = 0; + T->Init(lower, upper); + } + else if (upper >= lower) { T->Init(lower, upper); TDataStd_ListIteratorOfListOfExtendedString itr(S->List()); - for (; itr.More(); itr.Next(), i++) + for (Standard_Integer i = lower; itr.More(); itr.Next(), i++) { const TCollection_ExtendedString& tvalue = itr.Value(); - Handle(PCollection_HExtendedString) pvalue = new PCollection_HExtendedString(tvalue); + const Handle(PCollection_HExtendedString)& pvalue = new PCollection_HExtendedString(tvalue); T->SetValue(i, pvalue); } } diff --git a/src/MDataStd/MDataStd_IntegerListRetrievalDriver.cxx b/src/MDataStd/MDataStd_IntegerListRetrievalDriver.cxx index 66d893a53b..d9b50b7645 100644 --- a/src/MDataStd/MDataStd_IntegerListRetrievalDriver.cxx +++ b/src/MDataStd/MDataStd_IntegerListRetrievalDriver.cxx @@ -64,12 +64,12 @@ void MDataStd_IntegerListRetrievalDriver::Paste(const Handle(PDF_Attribute)& Sou const Handle(TDF_Attribute)& Target, const Handle(MDF_RRelocationTable)& ) const { - Handle(PDataStd_IntegerList) S = Handle(PDataStd_IntegerList)::DownCast (Source); - Handle(TDataStd_IntegerList) T = Handle(TDataStd_IntegerList)::DownCast (Target); + const Handle(PDataStd_IntegerList) S = Handle(PDataStd_IntegerList)::DownCast (Source); + const Handle(TDataStd_IntegerList) T = Handle(TDataStd_IntegerList)::DownCast (Target); Standard_Integer i, lower = S->Lower(), upper = S->Upper(); - for (i = lower; i <= upper; i++) - { - T->Append(S->Value(i)); - } + if(upper > 0) + for (i = lower; i <= upper; i++) { + T->Append(S->Value(i)); + } } diff --git a/src/MDataStd/MDataStd_IntegerListStorageDriver.cxx b/src/MDataStd/MDataStd_IntegerListStorageDriver.cxx index 3d8445c31a..578f5d3814 100644 --- a/src/MDataStd/MDataStd_IntegerListStorageDriver.cxx +++ b/src/MDataStd/MDataStd_IntegerListStorageDriver.cxx @@ -66,16 +66,19 @@ void MDataStd_IntegerListStorageDriver::Paste(const Handle(TDF_Attribute)& Sour const Handle(PDF_Attribute)& Target, const Handle(MDF_SRelocationTable)& /*RelocTable*/) const { - Handle(TDataStd_IntegerList) S = Handle(TDataStd_IntegerList)::DownCast (Source); - Handle(PDataStd_IntegerList) T = Handle(PDataStd_IntegerList)::DownCast (Target); + const Handle(TDataStd_IntegerList) S = Handle(TDataStd_IntegerList)::DownCast (Source); + const Handle(PDataStd_IntegerList) T = Handle(PDataStd_IntegerList)::DownCast (Target); - Standard_Integer lower = 1, upper = S->Extent(), i = lower; - if (upper >= lower) + Standard_Integer lower(1), upper = S->Extent(), i = lower; + if(upper == 0) { + lower = 0; + T->Init(lower, upper); + } + else if (upper >= lower) { T->Init(lower, upper); TColStd_ListIteratorOfListOfInteger itr(S->List()); - for (; itr.More(); itr.Next(), i++) - { + for (; itr.More(); itr.Next(), i++) { T->SetValue(i, itr.Value()); } } diff --git a/src/MDataStd/MDataStd_RealListRetrievalDriver.cxx b/src/MDataStd/MDataStd_RealListRetrievalDriver.cxx index e343e756f2..e222cb07e3 100644 --- a/src/MDataStd/MDataStd_RealListRetrievalDriver.cxx +++ b/src/MDataStd/MDataStd_RealListRetrievalDriver.cxx @@ -64,12 +64,13 @@ void MDataStd_RealListRetrievalDriver::Paste(const Handle(PDF_Attribute)& Source const Handle(TDF_Attribute)& Target, const Handle(MDF_RRelocationTable)& ) const { - Handle(PDataStd_RealList) S = Handle(PDataStd_RealList)::DownCast (Source); - Handle(TDataStd_RealList) T = Handle(TDataStd_RealList)::DownCast (Target); - - Standard_Integer i, lower = S->Lower(), upper = S->Upper(); - for (i = lower; i <= upper; i++) - { - T->Append(S->Value(i)); + const Handle(PDataStd_RealList) S = Handle(PDataStd_RealList)::DownCast (Source); + const Handle(TDataStd_RealList) T = Handle(TDataStd_RealList)::DownCast (Target); + if(!S.IsNull()) { + Standard_Integer i, lower = S->Lower(), upper = S->Upper(); + if(upper > 0) + for (i = lower; i <= upper; i++) { + T->Append(S->Value(i)); + } } } diff --git a/src/MDataStd/MDataStd_RealListStorageDriver.cxx b/src/MDataStd/MDataStd_RealListStorageDriver.cxx index 5d2ad2c510..0dc94bf49e 100644 --- a/src/MDataStd/MDataStd_RealListStorageDriver.cxx +++ b/src/MDataStd/MDataStd_RealListStorageDriver.cxx @@ -66,16 +66,19 @@ void MDataStd_RealListStorageDriver::Paste(const Handle(TDF_Attribute)& Source, const Handle(PDF_Attribute)& Target, const Handle(MDF_SRelocationTable)& /*RelocTable*/) const { - Handle(TDataStd_RealList) S = Handle(TDataStd_RealList)::DownCast (Source); - Handle(PDataStd_RealList) T = Handle(PDataStd_RealList)::DownCast (Target); + const Handle(TDataStd_RealList) S = Handle(TDataStd_RealList)::DownCast (Source); + const Handle(PDataStd_RealList) T = Handle(PDataStd_RealList)::DownCast (Target); - Standard_Integer lower = 1, upper = S->Extent(), i = lower; - if (upper >= lower) + Standard_Integer lower(1), upper = S->Extent(); + if(upper == 0) { + lower = 0; + T->Init(lower, upper); + } + else if (upper >= lower) { T->Init(lower, upper); TColStd_ListIteratorOfListOfReal itr(S->List()); - for (; itr.More(); itr.Next(), i++) - { + for (Standard_Integer i = lower; itr.More(); itr.Next(), i++) { T->SetValue(i, itr.Value()); } } diff --git a/src/MDataStd/MDataStd_ReferenceListRetrievalDriver.cxx b/src/MDataStd/MDataStd_ReferenceListRetrievalDriver.cxx index dd31140826..da4b1eff86 100644 --- a/src/MDataStd/MDataStd_ReferenceListRetrievalDriver.cxx +++ b/src/MDataStd/MDataStd_ReferenceListRetrievalDriver.cxx @@ -68,22 +68,21 @@ void MDataStd_ReferenceListRetrievalDriver::Paste(const Handle(PDF_Attribute)& S const Handle(TDF_Attribute)& Target, const Handle(MDF_RRelocationTable)& ) const { - Handle(PDataStd_ReferenceList) S = Handle(PDataStd_ReferenceList)::DownCast (Source); - Handle(TDataStd_ReferenceList) T = Handle(TDataStd_ReferenceList)::DownCast (Target); - + const Handle(PDataStd_ReferenceList) S = Handle(PDataStd_ReferenceList)::DownCast (Source); + const Handle(TDataStd_ReferenceList) T = Handle(TDataStd_ReferenceList)::DownCast (Target); + if(S.IsNull()) return; Standard_Integer i, lower = S->Lower(), upper = S->Upper(); - for (i = lower; i <= upper; i++) - { - const Handle(PCollection_HExtendedString)& pvalue = S->Value(i); - if (!pvalue.IsNull()) + if(upper > 0) + for (i = lower; i <= upper; i++) { - TDF_Label L; - TCollection_AsciiString tvalue = pvalue->Convert(); - TDF_Tool::Label(T->Label().Data(), tvalue, L, Standard_True); - if (!L.IsNull()) + const Handle(PCollection_HExtendedString)& pvalue = S->Value(i); + if (!pvalue.IsNull()) { - T->Append(L); + TDF_Label L; + const TCollection_AsciiString& tvalue = pvalue->Convert(); + TDF_Tool::Label(T->Label().Data(), tvalue, L, Standard_True); + if (!L.IsNull()) + T->Append(L); } } - } } diff --git a/src/MDataStd/MDataStd_ReferenceListStorageDriver.cxx b/src/MDataStd/MDataStd_ReferenceListStorageDriver.cxx index 81670da157..c0cd6f634b 100644 --- a/src/MDataStd/MDataStd_ReferenceListStorageDriver.cxx +++ b/src/MDataStd/MDataStd_ReferenceListStorageDriver.cxx @@ -69,23 +69,27 @@ void MDataStd_ReferenceListStorageDriver::Paste(const Handle(TDF_Attribute)& So const Handle(PDF_Attribute)& Target, const Handle(MDF_SRelocationTable)& /*RelocTable*/) const { - Handle(TDataStd_ReferenceList) S = Handle(TDataStd_ReferenceList)::DownCast (Source); - Handle(PDataStd_ReferenceList) T = Handle(PDataStd_ReferenceList)::DownCast (Target); - - Standard_Integer lower = 1, upper = S->Extent(), i = lower; - if (upper >= lower) + const Handle(TDataStd_ReferenceList) S = Handle(TDataStd_ReferenceList)::DownCast (Source); + const Handle(PDataStd_ReferenceList) T = Handle(PDataStd_ReferenceList)::DownCast (Target); + if(S.IsNull()) return; + Standard_Integer lower(1), upper = S->Extent(); + if(upper == 0) { + lower = 0; + T->Init(lower, upper); + } + else if (upper >= lower) { T->Init(lower, upper); TDF_ListIteratorOfLabelList itr(S->List()); - for (; itr.More(); itr.Next(), i++) + for (Standard_Integer i = lower; itr.More(); itr.Next(), i++) { TDF_Label L = itr.Value(); if (!L.IsNull()) { - TCollection_AsciiString tvalue; - TDF_Tool::Entry(L, tvalue); - Handle(PCollection_HExtendedString) pvalue = new PCollection_HExtendedString(tvalue); - T->SetValue(i, pvalue); + TCollection_AsciiString tvalue; + TDF_Tool::Entry(L, tvalue); + const Handle(PCollection_HExtendedString)& pvalue = new PCollection_HExtendedString(tvalue); + T->SetValue(i, pvalue); } } } diff --git a/src/XmlMDataStd/XmlMDataStd_BooleanListDriver.cxx b/src/XmlMDataStd/XmlMDataStd_BooleanListDriver.cxx index 93faee9084..10c600d29b 100644 --- a/src/XmlMDataStd/XmlMDataStd_BooleanListDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_BooleanListDriver.cxx @@ -77,8 +77,9 @@ Standard_Boolean XmlMDataStd_BooleanListDriver::Paste(const XmlObjMgt_Persistent return Standard_False; } - Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theTarget); - if (aFirstInd == aLastInd) + const Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theTarget); + if(aLastInd == 0) aFirstInd = 0; + if (aFirstInd == aLastInd && aLastInd > 0) { Standard_Integer anInteger; if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger)) @@ -91,7 +92,7 @@ Standard_Boolean XmlMDataStd_BooleanListDriver::Paste(const XmlObjMgt_Persistent } aBooleanList->Append(anInteger ? Standard_True : Standard_False); } - else + else if(aLastInd >= 1) { Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString()); for (ind = aFirstInd; ind <= aLastInd; ind++) @@ -120,21 +121,22 @@ void XmlMDataStd_BooleanListDriver::Paste(const Handle(TDF_Attribute)& theSource XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& ) const { - Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theSource); + const Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theSource); Standard_Integer anU = aBooleanList->Extent(); theTarget.Element().setAttribute(::LastIndexString(), anU); - if (anU >= 1) + // Allocation of 1 char for each boolean value + a space. + NCollection_LocalArray str(2 * anU + 1); + if(anU == 0) str[0] = 0; + else if (anU >= 1) { - // Allocation of 1 char for each boolean value + a space. - Standard_Integer iChar = 0; - NCollection_LocalArray str(2 * anU + 1); + Standard_Integer iChar(0); TDataStd_ListIteratorOfListOfByte itr(aBooleanList->List()); for (; itr.More(); itr.Next()) { const Standard_Byte& byte = itr.Value(); iChar += Sprintf(&(str[iChar]), "%d ", byte); } - XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True); } + XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True); } diff --git a/src/XmlMDataStd/XmlMDataStd_ExtStringListDriver.cxx b/src/XmlMDataStd/XmlMDataStd_ExtStringListDriver.cxx index 63501a9e24..a2f0ebaaad 100644 --- a/src/XmlMDataStd/XmlMDataStd_ExtStringListDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_ExtStringListDriver.cxx @@ -79,7 +79,8 @@ Standard_Boolean XmlMDataStd_ExtStringListDriver::Paste(const XmlObjMgt_Persiste return Standard_False; } - Handle(TDataStd_ExtStringList) anExtStringList = Handle(TDataStd_ExtStringList)::DownCast(theTarget); + if(aLastInd == 0) return Standard_True; + const Handle(TDataStd_ExtStringList) anExtStringList = Handle(TDataStd_ExtStringList)::DownCast(theTarget); if (!anElement.hasChildNodes()) { @@ -114,7 +115,7 @@ void XmlMDataStd_ExtStringListDriver::Paste(const Handle(TDF_Attribute)& theSour XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& ) const { - Handle(TDataStd_ExtStringList) anExtStringList = Handle(TDataStd_ExtStringList)::DownCast(theSource); + const Handle(TDataStd_ExtStringList) anExtStringList = Handle(TDataStd_ExtStringList)::DownCast(theSource); Standard_Integer anU = anExtStringList->Extent(); XmlObjMgt_Element& anElement = theTarget; diff --git a/src/XmlMDataStd/XmlMDataStd_IntegerListDriver.cxx b/src/XmlMDataStd/XmlMDataStd_IntegerListDriver.cxx index fc5a32a34f..40e1bed203 100644 --- a/src/XmlMDataStd/XmlMDataStd_IntegerListDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_IntegerListDriver.cxx @@ -77,8 +77,9 @@ Standard_Boolean XmlMDataStd_IntegerListDriver::Paste(const XmlObjMgt_Persistent return Standard_False; } - Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theTarget); - if (aFirstInd == aLastInd) + const Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theTarget); + if(aLastInd == 0) aFirstInd = 0; + if (aFirstInd == aLastInd && aLastInd > 0) { Standard_Integer anInteger; if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger)) @@ -91,7 +92,7 @@ Standard_Boolean XmlMDataStd_IntegerListDriver::Paste(const XmlObjMgt_Persistent } anIntList->Append(anInteger); } - else + else if(aLastInd >= 1) { Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString()); for (ind = aFirstInd; ind <= aLastInd; ind++) @@ -120,24 +121,25 @@ void XmlMDataStd_IntegerListDriver::Paste(const Handle(TDF_Attribute)& theSource XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& ) const { - Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theSource); + const Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theSource); Standard_Integer anU = anIntList->Extent(); theTarget.Element().setAttribute(::LastIndexString(), anU); - if (anU >= 1) + NCollection_LocalArray str(12 * anU + 1); + if(anU == 0) + str[0] = 0; + else if (anU >= 1) { // Allocation of 12 chars for each integer including the space. // An example: -2 147 483 648 Standard_Integer iChar = 0; - NCollection_LocalArray str(12 * anU + 1); TColStd_ListIteratorOfListOfInteger itr(anIntList->List()); for (; itr.More(); itr.Next()) { const Standard_Integer& intValue = itr.Value(); iChar += Sprintf(&(str[iChar]), "%d ", intValue); - } - - // No occurrence of '&', '<' and other irregular XML characters - XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True); + } } + // No occurrence of '&', '<' and other irregular XML characters + XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True); } diff --git a/src/XmlMDataStd/XmlMDataStd_RealListDriver.cxx b/src/XmlMDataStd/XmlMDataStd_RealListDriver.cxx index 13a460ac36..f377a740cb 100644 --- a/src/XmlMDataStd/XmlMDataStd_RealListDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_RealListDriver.cxx @@ -78,13 +78,13 @@ Standard_Boolean XmlMDataStd_RealListDriver::Paste(const XmlObjMgt_Persistent& return Standard_False; } - Handle(TDataStd_RealList) aRealList = Handle(TDataStd_RealList)::DownCast(theTarget); - + const Handle(TDataStd_RealList) aRealList = Handle(TDataStd_RealList)::DownCast(theTarget); // Check the type of LDOMString const XmlObjMgt_DOMString& aString = XmlObjMgt::GetStringValue(anElement); + if(aLastInd == 0) aFirstInd = 0; if (aString.Type() == LDOMBasicString::LDOM_Integer) { - if (aFirstInd == aLastInd) + if (aFirstInd == aLastInd && aLastInd > 0) { Standard_Integer anIntValue; if (aString.GetInteger(anIntValue)) @@ -100,7 +100,7 @@ Standard_Boolean XmlMDataStd_RealListDriver::Paste(const XmlObjMgt_Persistent& return Standard_False; } } - else + else if(aLastInd >= 1) { Standard_CString aValueStr = Standard_CString(aString.GetString()); for (ind = aFirstInd; ind <= aLastInd; ind++) @@ -128,22 +128,23 @@ void XmlMDataStd_RealListDriver::Paste(const Handle(TDF_Attribute)& theSource, XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& ) const { - Handle(TDataStd_RealList) aRealList = Handle(TDataStd_RealList)::DownCast(theSource); + const Handle(TDataStd_RealList) aRealList = Handle(TDataStd_RealList)::DownCast(theSource); Standard_Integer anU = aRealList->Extent(); theTarget.Element().setAttribute(::LastIndexString(), anU); - if (anU >= 1) - { - // Allocation of 25 chars for each double value including the space: - // An example: -3.1512678732195273e+020 + // Allocation of 25 chars for each double value including the space: + // An example: -3.1512678732195273e+020 + NCollection_LocalArray str(25 * anU + 1); + if(anU == 0) str[0] = 0; + else if (anU >= 1) + { Standard_Integer iChar = 0; - NCollection_LocalArray str(25 * anU + 1); TColStd_ListIteratorOfListOfReal itr(aRealList->List()); for (; itr.More(); itr.Next()) { const Standard_Real& realValue = itr.Value(); iChar += Sprintf(&(str[iChar]), "%.17g ", realValue); } - XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True); } + XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True); } diff --git a/src/XmlMDataStd/XmlMDataStd_ReferenceListDriver.cxx b/src/XmlMDataStd/XmlMDataStd_ReferenceListDriver.cxx index c2e6fbb8fe..27c63f6249 100644 --- a/src/XmlMDataStd/XmlMDataStd_ReferenceListDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_ReferenceListDriver.cxx @@ -82,7 +82,8 @@ Standard_Boolean XmlMDataStd_ReferenceListDriver::Paste(const XmlObjMgt_Persiste return Standard_False; } - Handle(TDataStd_ReferenceList) aReferenceList = Handle(TDataStd_ReferenceList)::DownCast(theTarget); + if(aLastInd == 0) return Standard_True; + const Handle(TDataStd_ReferenceList) aReferenceList = Handle(TDataStd_ReferenceList)::DownCast(theTarget); if (!anElement.hasChildNodes()) { @@ -107,8 +108,8 @@ Standard_Boolean XmlMDataStd_ReferenceListDriver::Paste(const XmlObjMgt_Persiste if (XmlObjMgt::GetTagEntryString (aValueStr, anEntry) == Standard_False) { TCollection_ExtendedString aMessage = - TCollection_ExtendedString ("Cannot retrieve reference from \"") - + aValueStr + '\"'; + TCollection_ExtendedString ("Cannot retrieve reference from \"") + + aValueStr + '\"'; WriteMessage (aMessage); return Standard_False; } @@ -134,8 +135,8 @@ Standard_Boolean XmlMDataStd_ReferenceListDriver::Paste(const XmlObjMgt_Persiste if (XmlObjMgt::GetTagEntryString (aValueStr, anEntry) == Standard_False) { TCollection_ExtendedString aMessage = - TCollection_ExtendedString ("Cannot retrieve reference from \"") - + aValueStr + '\"'; + TCollection_ExtendedString ("Cannot retrieve reference from \"") + + aValueStr + '\"'; WriteMessage (aMessage); return Standard_False; } @@ -158,7 +159,7 @@ void XmlMDataStd_ReferenceListDriver::Paste(const Handle(TDF_Attribute)& theSour XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& ) const { - Handle(TDataStd_ReferenceList) aReferenceList = Handle(TDataStd_ReferenceList)::DownCast(theSource); + const Handle(TDataStd_ReferenceList) aReferenceList = Handle(TDataStd_ReferenceList)::DownCast(theSource); TDF_Label L = aReferenceList->Label(); if (L.IsNull()) { @@ -169,7 +170,7 @@ void XmlMDataStd_ReferenceListDriver::Paste(const Handle(TDF_Attribute)& theSour Standard_Integer anU = aReferenceList->Extent(); XmlObjMgt_Element& anElement = theTarget; anElement.setAttribute(::LastIndexString(), anU); - + if(anU == 0) return; XmlObjMgt_Document aDoc = anElement.getOwnerDocument().Doc(); TDF_ListIteratorOfLabelList itr(aReferenceList->List()); diff --git a/tests/bugs/caf/bug25394_1 b/tests/bugs/caf/bug25394_1 new file mode 100755 index 0000000000..30cfff7430 --- /dev/null +++ b/tests/bugs/caf/bug25394_1 @@ -0,0 +1,127 @@ +# =================== OCAF ====================== +# Standard attributes of List containers (std format) +# +# Testing purpose: test of set /get & save / restore +# of TDataStd_BooleanList, TDataStd_IntegerList +# TDataStd_RealList, TDataStd_ExtStringList, +# TDataStd_ReferenceList attributes +# +# =============================================== +# Test case: t1 (testing Set /Get attribute with empty list) +# 1. create BooleanList attribute with empty list +# 2. create IntegerList attribute with empty list +# 3. create RealList attribute with empty list +# 4. create ExtStringList attribute with empty list +# 5. create ReferenceList attribute with empty list +# 6. save the Document in external std file +# 7. reopen the Document +# 8. check the restored attributes at the specified labels +# =============================================== + +NewDocument D MDTV-Standard +# 1. create BooleanList attribute with empty list +set Lab1 [Label D 0:1:1] +SetBooleanList D $Lab1 +set info1 [GetBooleanList D $Lab1] +# output => "List is empty" + +# 2. create IntegerList attribute with empty list +set Lab2 [Label D 0:1:2] +SetIntegerList D $Lab2 +set info2 [GetIntegerList D $Lab2] +# output => "List is empty" + +# 3. create RealList attribute with empty list +set Lab3 [Label D 0:1:3] +SetRealList D $Lab3 +set info3 [GetRealList D $Lab3] +# output => "List is empty" + +# 4. create ExtStringList attribute with empty list +set Lab4 [Label D 0:1:4] +SetExtStringList D $Lab4 +set info4 [GetExtStringList D $Lab4] +# output => "List is empty" + +# 5. create ReferenceList attribute with empty list +set Lab5 [Label D 0:1:5] +SetReferenceList D $Lab5 +set info5 [GetReferenceList D $Lab5] +# output => "List is empty" + +# 6. save the Document in external file +SaveAs D ${imagedir}/bug26014_test1.std +Close D + +# 7. reopen the Document +Open ${imagedir}/bug26014_test1.std D + +# 8. Check the restored attributes at the specified labels +set info8 [GetBooleanList D $Lab1] +# output => "List is empty" + +set info9 [GetIntegerList D $Lab2] +# output => "List is empty" + +set info10 [GetRealList D $Lab3] +# output => "List is empty" + +set info11 [GetExtStringList D $Lab4] +# output => "List is empty" + +set info12 [GetReferenceList D $Lab5] +# output => "List is empty" + +Close D + +if { [regexp {List is empty} ${info1}] } { + puts "OK: created BooleanList attribute is good" +} else { + puts "Error: created BooleanList attribute is bad" +} +if { [regexp {List is empty} ${info2}] } { + puts "OK: created IntegerList attribute is good" +} else { + puts "Error: created IntegerList attribute is bad" +} +if { [regexp {List is empty} ${info3}] } { + puts "OK: created RealList attribute is good" +} else { + puts "Error: created RealList attribute is bad" +} +if { [regexp {List is empty} ${info4}] } { + puts "OK: created ExtStringList attribute is good" +} else { + puts "Error: created ExtStringList attribute is bad" +} +if { [regexp {List is empty} ${info5}] } { + puts "OK: created ReferenceList attribute is good" +} else { + puts "Error: created ReferenceList attribute is bad" +} + +if { [regexp {List is empty} ${info8}] } { + puts "OK: restored BooleanList attribute is good" +} else { + puts "Error: restored BooleanList attribute is bad" +} +if { [regexp {List is empty} ${info9}] } { + puts "OK: restored IntegerList attribute is good" +} else { + puts "Error: restored IntegerList attribute is bad" +} +if { [regexp {List is empty} ${info10}] } { + puts "OK: restored RealList attribute is good" +} else { + puts "Error: restored RealList attribute is bad" +} +if { [regexp {List is empty} ${info11}] } { + puts "OK: restored ExtStringList attribute is good" +} else { + puts "Error: restored ExtStringList attribute is bad" +} +if { [regexp {List is empty} ${info12}] } { + puts "OK: restored ReferenceList attribute is good" +} else { + puts "Error: restored ReferenceList attribute is bad" +} diff --git a/tests/bugs/caf/bug25394_2 b/tests/bugs/caf/bug25394_2 new file mode 100755 index 0000000000..d7c46fcdfd --- /dev/null +++ b/tests/bugs/caf/bug25394_2 @@ -0,0 +1,127 @@ +# =================== OCAF ====================== +# Standard attributes of List containers (bin format) +# +# Testing purpose: test of set /get & save / restore +# of TDataStd_BooleanList, TDataStd_IntegerList +# TDataStd_RealList, TDataStd_ExtStringList, +# TDataStd_ReferenceList attributes +# +# =============================================== +# Test case: t2 (testing Set /Get attribute with empty list) +# 1. create BooleanList attribute with empty list +# 2. create IntegerList attribute with empty list +# 3. create RealList attribute with empty list +# 4. create ExtStringList attribute with empty list +# 5. create ReferenceList attribute with empty list +# 6. save the Document in external cbf file +# 7. reopen the Document +# 8. check the restored attributes at the specified labels +# =============================================== + +NewDocument D BinOcaf +# 1. create BooleanList attribute with empty list +set Lab1 [Label D 0:1:1] +SetBooleanList D $Lab1 +set info1 [GetBooleanList D $Lab1] +# output => "List is empty" + +# 2. create IntegerList attribute with empty list +set Lab2 [Label D 0:1:2] +SetIntegerList D $Lab2 +set info2 [GetIntegerList D $Lab2] +# output => "List is empty" + +# 3. create RealList attribute with empty list +set Lab3 [Label D 0:1:3] +SetRealList D $Lab3 +set info3 [GetRealList D $Lab3] +# output => "List is empty" + +# 4. create ExtStringList attribute with empty list +set Lab4 [Label D 0:1:4] +SetExtStringList D $Lab4 +set info4 [GetExtStringList D $Lab4] +# output => "List is empty" + +# 5. create ReferenceList attribute with empty list +set Lab5 [Label D 0:1:5] +SetReferenceList D $Lab5 +set info5 [GetReferenceList D $Lab5] +# output => "List is empty" + +# 6. save the Document in external file +SaveAs D ${imagedir}/bug26014_test2.cbf +Close D + +# 7. reopen the Document +Open ${imagedir}/bug26014_test2.cbf D + +# 8. Check the restored attributes at the specified labels +set info8 [GetBooleanList D $Lab1] +# output => "List is empty" + +set info9 [GetIntegerList D $Lab2] +# output => "List is empty" + +set info10 [GetRealList D $Lab3] +# output => "List is empty" + +set info11 [GetExtStringList D $Lab4] +# output => "List is empty" + +set info12 [GetReferenceList D $Lab5] +# output => "List is empty" + +Close D + +if { [regexp {List is empty} ${info1}] } { + puts "OK: created BooleanList attribute is good" +} else { + puts "Error: created BooleanList attribute is bad" +} +if { [regexp {List is empty} ${info2}] } { + puts "OK: created IntegerList attribute is good" +} else { + puts "Error: created IntegerList attribute is bad" +} +if { [regexp {List is empty} ${info3}] } { + puts "OK: created RealList attribute is good" +} else { + puts "Error: created RealList attribute is bad" +} +if { [regexp {List is empty} ${info4}] } { + puts "OK: created ExtStringList attribute is good" +} else { + puts "Error: created ExtStringList attribute is bad" +} +if { [regexp {List is empty} ${info5}] } { + puts "OK: created ReferenceList attribute is good" +} else { + puts "Error: created ReferenceList attribute is bad" +} + +if { [regexp {List is empty} ${info8}] } { + puts "OK: restored BooleanList attribute is good" +} else { + puts "Error: restored BooleanList attribute is bad" +} +if { [regexp {List is empty} ${info9}] } { + puts "OK: restored IntegerList attribute is good" +} else { + puts "Error: restored IntegerList attribute is bad" +} +if { [regexp {List is empty} ${info10}] } { + puts "OK: restored RealList attribute is good" +} else { + puts "Error: restored RealList attribute is bad" +} +if { [regexp {List is empty} ${info11}] } { + puts "OK: restored ExtStringList attribute is good" +} else { + puts "Error: restored ExtStringList attribute is bad" +} +if { [regexp {List is empty} ${info12}] } { + puts "OK: restored ReferenceList attribute is good" +} else { + puts "Error: restored ReferenceList attribute is bad" +} diff --git a/tests/bugs/caf/bug25394_3 b/tests/bugs/caf/bug25394_3 new file mode 100755 index 0000000000..d36c25e9c0 --- /dev/null +++ b/tests/bugs/caf/bug25394_3 @@ -0,0 +1,127 @@ +# =================== OCAF ====================== +# Standard attributes of List containers (xml format) +# +# Testing purpose: test of set /get & save / restore +# of TDataStd_BooleanList, TDataStd_IntegerList +# TDataStd_RealList, TDataStd_ExtStringList, +# TDataStd_ReferenceList attributes +# +# =============================================== +# Test case: t2 (testing Set /Get attribute with empty list) +# 1. create BooleanList attribute with empty list +# 2. create IntegerList attribute with empty list +# 3. create RealList attribute with empty list +# 4. create ExtStringList attribute with empty list +# 5. create ReferenceList attribute with empty list +# 6. save the Document in external xml file +# 7. reopen the Document +# 8. check the restored attributes at the specified labels +# =============================================== + +NewDocument D XmlOcaf +# 1. create BooleanList attribute with empty list +set Lab1 [Label D 0:1:1] +SetBooleanList D $Lab1 +set info1 [GetBooleanList D $Lab1] +# output => "List is empty" + +# 2. create IntegerList attribute with empty list +set Lab2 [Label D 0:1:2] +SetIntegerList D $Lab2 +set info2 [GetIntegerList D $Lab2] +# output => "List is empty" + +# 3. create RealList attribute with empty list +set Lab3 [Label D 0:1:3] +SetRealList D $Lab3 +set info3 [GetRealList D $Lab3] +# output => "List is empty" + +# 4. create ExtStringList attribute with empty list +set Lab4 [Label D 0:1:4] +SetExtStringList D $Lab4 +set info4 [GetExtStringList D $Lab4] +# output => "List is empty" + +# 5. create ReferenceList attribute with empty list +set Lab5 [Label D 0:1:5] +SetReferenceList D $Lab5 +set info5 [GetReferenceList D $Lab5] +# output => "List is empty" + +# 6. save the Document in external file +SaveAs D ${imagedir}/bug26014_test3.xml +Close D + +# 7. reopen the Document +Open ${imagedir}/bug26014_test3.xml D + +# 8. Check the restored attributes at the specified labels +set info8 [GetBooleanList D $Lab1] +# output => "List is empty" + +set info9 [GetIntegerList D $Lab2] +# output => "List is empty" + +set info10 [GetRealList D $Lab3] +# output => "List is empty" + +set info11 [GetExtStringList D $Lab4] +# output => "List is empty" + +set info12 [GetReferenceList D $Lab5] +# output => "List is empty" + +Close D + +if { [regexp {List is empty} ${info1}] } { + puts "OK: created BooleanList attribute is good" +} else { + puts "Error: created BooleanList attribute is bad" +} +if { [regexp {List is empty} ${info2}] } { + puts "OK: created IntegerList attribute is good" +} else { + puts "Error: created IntegerList attribute is bad" +} +if { [regexp {List is empty} ${info3}] } { + puts "OK: created RealList attribute is good" +} else { + puts "Error: created RealList attribute is bad" +} +if { [regexp {List is empty} ${info4}] } { + puts "OK: created ExtStringList attribute is good" +} else { + puts "Error: created ExtStringList attribute is bad" +} +if { [regexp {List is empty} ${info5}] } { + puts "OK: created ReferenceList attribute is good" +} else { + puts "Error: created ReferenceList attribute is bad" +} + +if { [regexp {List is empty} ${info8}] } { + puts "OK: restored BooleanList attribute is good" +} else { + puts "Error: restored BooleanList attribute is bad" +} +if { [regexp {List is empty} ${info9}] } { + puts "OK: restored IntegerList attribute is good" +} else { + puts "Error: restored IntegerList attribute is bad" +} +if { [regexp {List is empty} ${info10}] } { + puts "OK: restored RealList attribute is good" +} else { + puts "Error: restored RealList attribute is bad" +} +if { [regexp {List is empty} ${info11}] } { + puts "OK: restored ExtStringList attribute is good" +} else { + puts "Error: restored ExtStringList attribute is bad" +} +if { [regexp {List is empty} ${info12}] } { + puts "OK: restored ReferenceList attribute is good" +} else { + puts "Error: restored ReferenceList attribute is bad" +}