diff --git a/src/DDataStd/DDataStd_BasicCommands.cxx b/src/DDataStd/DDataStd_BasicCommands.cxx index f4dc8f8a8e..65ea9970ec 100644 --- a/src/DDataStd/DDataStd_BasicCommands.cxx +++ b/src/DDataStd/DDataStd_BasicCommands.cxx @@ -1623,6 +1623,487 @@ static Standard_Integer DDataStd_SetRealList (Draw_Interpretor& di, return 1; } +//======================================================================= +//function : DDataStd_InsertBeforeExtStringList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertBeforeExtStringList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + 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; + if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + TCollection_ExtendedString value = arg[4]; + + if (A->InsertBefore(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertBeforeExtStringList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertAfterExtStringList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertAfterExtStringList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + 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; + if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + TCollection_ExtendedString value = arg[4]; + + if (A->InsertAfter(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertAfterExtStringList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_RemoveExtStringList (DF, entry, index ) +//======================================================================= +static Standard_Integer DDataStd_RemoveExtStringList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 4) + { + 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; + if (!label.FindAttribute(TDataStd_ExtStringList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + if (A->Remove(index)) + return 0; + else + return 1; + } + di << "DDataStd_RemoveExtStringList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertBeforeBooleanList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertBeforeBooleanList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_BooleanList) A; + if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + Standard_Boolean value = (Standard_Boolean) Draw::Atoi(arg[4]); + + if (A->InsertBefore(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertBeforeBooleanList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertAfterBooleanList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertAfterBooleanList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_BooleanList) A; + if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + Standard_Boolean value = (Standard_Boolean) Draw::Atoi(arg[4]); + + if (A->InsertAfter(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertAfterBooleanList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_RemoveBooleanList (DF, entry, index ) +//======================================================================= +static Standard_Integer DDataStd_RemoveBooleanList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 4) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_BooleanList) A; + if (!label.FindAttribute(TDataStd_BooleanList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + if (A->Remove(index)) + return 0; + else + return 1; + } + di << "DDataStd_RemoveBooleanList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertBeforeIntegerList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertBeforeIntegerList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_IntegerList) A; + if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + Standard_Integer value = (Standard_Integer) Draw::Atoi(arg[4]); + + if (A->InsertBeforeByIndex(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertBeforeIntegerList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertAfterIntegerList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertAfterIntegerList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_IntegerList) A; + if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + Standard_Integer value = (Standard_Integer) Draw::Atoi(arg[4]); + + if (A->InsertAfterByIndex(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertAfterIntegerList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_RemoveIntegerList (DF, entry, index ) +//======================================================================= +static Standard_Integer DDataStd_RemoveIntegerList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 4) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_IntegerList) A; + if (!label.FindAttribute(TDataStd_IntegerList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + if (A->RemoveByIndex(index)) + return 0; + else + return 1; + } + di << "DDataStd_RemoveIntegerList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertBeforeRealList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertBeforeRealList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_RealList) A; + if (!label.FindAttribute(TDataStd_RealList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + Standard_Real value = (Standard_Real) Draw::Atof(arg[4]); + + if (A->InsertBeforeByIndex(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertBeforeRealList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertAfterRealList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertAfterRealList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_RealList) A; + if (!label.FindAttribute(TDataStd_RealList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + Standard_Real value = (Standard_Real) Draw::Atof(arg[4]); + + if (A->InsertAfterByIndex(index, value)) + return 0; + else + return 1; + } + di << "DDataStd_InsertAfterRealList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_RemoveRealList (DF, entry, index ) +//======================================================================= +static Standard_Integer DDataStd_RemoveRealList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 4) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_RealList) A; + if (!label.FindAttribute(TDataStd_RealList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + if (A->RemoveByIndex(index)) + return 0; + else + return 1; + } + di << "DDataStd_RemoveRealList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertBeforeReferenceList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertBeforeReferenceList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_ReferenceList) A; + if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + TDF_Label refLabel; + if (!DDF::AddLabel(DF, arg[4], refLabel)) + return 1; + + if (A->InsertBefore(index, refLabel)) + return 0; + else + return 1; + } + di << "DDataStd_InsertBeforeReferenceList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_InsertAfterReferenceList (DF, entry, index, value ) +//======================================================================= +static Standard_Integer DDataStd_InsertAfterReferenceList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 5) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_ReferenceList) A; + if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + TDF_Label refLabel; + if (!DDF::AddLabel(DF, arg[4], refLabel)) + return 1; + + if (A->InsertAfter(index, refLabel)) + return 0; + else + return 1; + } + di << "DDataStd_InsertAfterReferenceList: Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_RemoveReferenceList (DF, entry, index ) +//======================================================================= +static Standard_Integer DDataStd_RemoveReferenceList (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 4) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Handle(TDataStd_ReferenceList) A; + if (!label.FindAttribute(TDataStd_ReferenceList::GetID(), A)) + return 1; + + Standard_Integer index = Draw::Atoi(arg[3]); + + if (A->Remove(index)) + return 0; + else + return 1; + } + di << "DDataStd_RemoveReferenceList: Error\n"; + return 1; +} + //======================================================================= //function : GetByteArray (DF, entry ) //======================================================================= @@ -3369,6 +3850,66 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) "SetReferenceList (DF, entry, elmt1, elmt2, ... )", __FILE__, DDataStd_SetReferenceList, g); + theCommands.Add ("InsertBeforeExtStringList", + "InsertBeforeExtStringList (DF, entry, index, value )", + __FILE__, DDataStd_InsertBeforeExtStringList, g); + + theCommands.Add ("InsertAfterExtStringList", + "InsertAfterExtStringList (DF, entry, index, value )", + __FILE__, DDataStd_InsertAfterExtStringList, g); + + theCommands.Add ("RemoveExtStringList", + "RemoveExtStringList (DF, entry, index )", + __FILE__, DDataStd_RemoveExtStringList, g); + + theCommands.Add ("InsertBeforeBooleanList", + "InsertBeforeBooleanList (DF, entry, index, value )", + __FILE__, DDataStd_InsertBeforeBooleanList, g); + + theCommands.Add ("InsertAfterBooleanList", + "InsertAfterBooleanList (DF, entry, index, value )", + __FILE__, DDataStd_InsertAfterBooleanList, g); + + theCommands.Add ("RemoveBooleanList", + "RemoveBooleanList (DF, entry, index )", + __FILE__, DDataStd_RemoveBooleanList, g); + + theCommands.Add ("InsertBeforeIntegerList", + "InsertBeforeIntegerList (DF, entry, index, value )", + __FILE__, DDataStd_InsertBeforeIntegerList, g); + + theCommands.Add ("InsertAfterIntegerList", + "InsertAfterIntegerList (DF, entry, index, value )", + __FILE__, DDataStd_InsertAfterIntegerList, g); + + theCommands.Add ("RemoveIntegerList", + "RemoveIntegerList (DF, entry, index )", + __FILE__, DDataStd_RemoveIntegerList, g); + + theCommands.Add ("InsertBeforeRealList", + "InsertBeforeRealList (DF, entry, index, value )", + __FILE__, DDataStd_InsertBeforeRealList, g); + + theCommands.Add ("InsertAfterRealList", + "InsertAfterRealList (DF, entry, index, value )", + __FILE__, DDataStd_InsertAfterRealList, g); + + theCommands.Add ("RemoveRealList", + "RemoveRealList (DF, entry, index )", + __FILE__, DDataStd_RemoveRealList, g); + + theCommands.Add ("InsertBeforeReferenceList", + "InsertBeforeReferenceList (DF, entry, index, value )", + __FILE__, DDataStd_InsertBeforeReferenceList, g); + + theCommands.Add ("InsertAfterReferenceList", + "InsertAfterReferenceList (DF, entry, index, value )", + __FILE__, DDataStd_InsertAfterReferenceList, g); + + theCommands.Add ("RemoveReferenceList", + "RemoveReferenceList (DF, entry, index )", + __FILE__, DDataStd_RemoveReferenceList, g); + // GET theCommands.Add ("GetAsciiString", diff --git a/src/TDataStd/TDataStd_BooleanList.cxx b/src/TDataStd/TDataStd_BooleanList.cxx index 21d9812c82..b91480f8f7 100644 --- a/src/TDataStd/TDataStd_BooleanList.cxx +++ b/src/TDataStd/TDataStd_BooleanList.cxx @@ -133,6 +133,74 @@ const TDataStd_ListOfByte& TDataStd_BooleanList::List() const return myList; } +//======================================================================= +//function : InsertBefore +//purpose : Inserts the before the position. +//======================================================================= +Standard_Boolean TDataStd_BooleanList::InsertBefore(const Standard_Integer index, + const Standard_Boolean before_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDataStd_ListIteratorOfListOfByte itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertBefore(before_value ? 1 : 0, itr); + found = Standard_True; + break; + } + } + return found; +} + +//======================================================================= +//function : InsertAfter +//purpose : Inserts the after the position. +//======================================================================= +Standard_Boolean TDataStd_BooleanList::InsertAfter(const Standard_Integer index, + const Standard_Boolean after_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDataStd_ListIteratorOfListOfByte itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertAfter(after_value ? 1 : 0, itr); + found = Standard_True; + break; + } + } + return found; +} + +//======================================================================= +//function : Remove +//purpose : Removes the at the position. +//======================================================================= +Standard_Boolean TDataStd_BooleanList::Remove(const Standard_Integer index) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDataStd_ListIteratorOfListOfByte itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.Remove(itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : ID //purpose : diff --git a/src/TDataStd/TDataStd_BooleanList.hxx b/src/TDataStd/TDataStd_BooleanList.hxx index 0fcb69949e..8bac5e454c 100644 --- a/src/TDataStd/TDataStd_BooleanList.hxx +++ b/src/TDataStd/TDataStd_BooleanList.hxx @@ -68,6 +68,17 @@ public: //! 0 - means FALSE. Standard_EXPORT const TDataStd_ListOfByte& List() const; + //! Inserts the before the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertBefore (const Standard_Integer index, const Standard_Boolean before_value); + + //! Inserts the after the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertAfter (const Standard_Integer index, const Standard_Boolean after_value); + + //! Removes a value at position. + Standard_EXPORT Standard_Boolean Remove (const Standard_Integer index); + Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; Standard_EXPORT void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE; diff --git a/src/TDataStd/TDataStd_ExtStringList.cxx b/src/TDataStd/TDataStd_ExtStringList.cxx index 7b66911553..fc4bc3e826 100644 --- a/src/TDataStd/TDataStd_ExtStringList.cxx +++ b/src/TDataStd/TDataStd_ExtStringList.cxx @@ -117,6 +117,29 @@ Standard_Boolean TDataStd_ExtStringList::InsertBefore(const TCollection_Extended return Standard_False; } +//======================================================================= +//function : InsertBefore +//purpose : Inserts the before the position. +//======================================================================= +Standard_Boolean TDataStd_ExtStringList::InsertBefore(const Standard_Integer index, + const TCollection_ExtendedString& before_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDataStd_ListIteratorOfListOfExtendedString itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertBefore(before_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : InsertAfter //purpose : @@ -137,6 +160,29 @@ Standard_Boolean TDataStd_ExtStringList::InsertAfter(const TCollection_ExtendedS return Standard_False; } +//======================================================================= +//function : InsertAfter +//purpose : Inserts the after the position. +//======================================================================= +Standard_Boolean TDataStd_ExtStringList::InsertAfter(const Standard_Integer index, + const TCollection_ExtendedString& after_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDataStd_ListIteratorOfListOfExtendedString itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertAfter(after_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Remove //purpose : @@ -156,6 +202,28 @@ Standard_Boolean TDataStd_ExtStringList::Remove(const TCollection_ExtendedString return Standard_False; } +//======================================================================= +//function : Remove +//purpose : Removes a value at position. +//======================================================================= +Standard_Boolean TDataStd_ExtStringList::Remove(const Standard_Integer index) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDataStd_ListIteratorOfListOfExtendedString itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (index == i) + { + Backup(); + myList.Remove(itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Clear //purpose : diff --git a/src/TDataStd/TDataStd_ExtStringList.hxx b/src/TDataStd/TDataStd_ExtStringList.hxx index 19fde2bd80..cd9b69a5f1 100644 --- a/src/TDataStd/TDataStd_ExtStringList.hxx +++ b/src/TDataStd/TDataStd_ExtStringList.hxx @@ -62,12 +62,23 @@ public: //! Inserts the before the first meet of . Standard_EXPORT Standard_Boolean InsertBefore (const TCollection_ExtendedString& value, const TCollection_ExtendedString& before_value); + //! Inserts the before the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertBefore (const Standard_Integer index, const TCollection_ExtendedString& before_value); + //! Inserts the after the first meet of . Standard_EXPORT Standard_Boolean InsertAfter (const TCollection_ExtendedString& value, const TCollection_ExtendedString& after_value); + //! Inserts the after the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertAfter (const Standard_Integer index, const TCollection_ExtendedString& after_value); + //! Removes the first meet of the . Standard_EXPORT Standard_Boolean Remove (const TCollection_ExtendedString& value); + //! Removes a value at position. + Standard_EXPORT Standard_Boolean Remove (const Standard_Integer index); + Standard_EXPORT void Clear(); Standard_EXPORT const TCollection_ExtendedString& First() const; diff --git a/src/TDataStd/TDataStd_IntegerList.cxx b/src/TDataStd/TDataStd_IntegerList.cxx index 88972eb087..82bf36e448 100644 --- a/src/TDataStd/TDataStd_IntegerList.cxx +++ b/src/TDataStd/TDataStd_IntegerList.cxx @@ -116,6 +116,27 @@ Standard_Boolean TDataStd_IntegerList::InsertBefore(const Standard_Integer value return Standard_False; } +// Inserts the before the position. +// The indices start with 1 .. Extent(). +Standard_Boolean TDataStd_IntegerList::InsertBeforeByIndex (const Standard_Integer index, + const Standard_Integer before_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TColStd_ListIteratorOfListOfInteger itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertBefore(before_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : InsertAfter //purpose : @@ -135,6 +156,27 @@ Standard_Boolean TDataStd_IntegerList::InsertAfter(const Standard_Integer value, } return Standard_False; } + +// Inserts the after the position. +// The indices start with 1 .. Extent(). +Standard_Boolean TDataStd_IntegerList::InsertAfterByIndex (const Standard_Integer index, + const Standard_Integer after_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TColStd_ListIteratorOfListOfInteger itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertAfter(after_value, itr); + found = Standard_True; + break; + } + } + return found; +} //======================================================================= //function : Remove @@ -155,6 +197,28 @@ Standard_Boolean TDataStd_IntegerList::Remove(const Standard_Integer value) return Standard_False; } +//======================================================================= +//function : Remove +//purpose : Removes the at the position. +//======================================================================= +Standard_Boolean TDataStd_IntegerList::RemoveByIndex (const Standard_Integer index) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TColStd_ListIteratorOfListOfInteger itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.Remove(itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Clear //purpose : diff --git a/src/TDataStd/TDataStd_IntegerList.hxx b/src/TDataStd/TDataStd_IntegerList.hxx index 7befe2a809..f8b9306929 100644 --- a/src/TDataStd/TDataStd_IntegerList.hxx +++ b/src/TDataStd/TDataStd_IntegerList.hxx @@ -61,12 +61,23 @@ public: //! Inserts the before the first meet of . Standard_EXPORT Standard_Boolean InsertBefore (const Standard_Integer value, const Standard_Integer before_value); + //! Inserts the before the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertBeforeByIndex (const Standard_Integer index, const Standard_Integer before_value); + //! Inserts the after the first meet of . Standard_EXPORT Standard_Boolean InsertAfter (const Standard_Integer value, const Standard_Integer after_value); + //! Inserts the after the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertAfterByIndex (const Standard_Integer index, const Standard_Integer after_value); + //! Removes the first meet of the . Standard_EXPORT Standard_Boolean Remove (const Standard_Integer value); + //! Removes a value at position. + Standard_EXPORT Standard_Boolean RemoveByIndex (const Standard_Integer index); + Standard_EXPORT void Clear(); Standard_EXPORT Standard_Integer First() const; diff --git a/src/TDataStd/TDataStd_RealList.cxx b/src/TDataStd/TDataStd_RealList.cxx index bb9e5510c0..70c7952cca 100644 --- a/src/TDataStd/TDataStd_RealList.cxx +++ b/src/TDataStd/TDataStd_RealList.cxx @@ -116,6 +116,27 @@ Standard_Boolean TDataStd_RealList::InsertBefore(const Standard_Real value, return Standard_False; } +// Inserts the before the position. +// The indices start with 1 .. Extent(). +Standard_Boolean TDataStd_RealList::InsertBeforeByIndex (const Standard_Integer index, + const Standard_Real before_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TColStd_ListIteratorOfListOfReal itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertBefore(before_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : InsertAfter //purpose : @@ -136,6 +157,27 @@ Standard_Boolean TDataStd_RealList::InsertAfter(const Standard_Real value, return Standard_False; } +// Inserts the after the position. +// The indices start with 1 .. Extent(). +Standard_Boolean TDataStd_RealList::InsertAfterByIndex (const Standard_Integer index, + const Standard_Real after_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TColStd_ListIteratorOfListOfReal itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertAfter(after_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Remove //purpose : @@ -155,6 +197,28 @@ Standard_Boolean TDataStd_RealList::Remove(const Standard_Real value) return Standard_False; } +//======================================================================= +//function : Remove +//purpose : Removes a value at the position. +//======================================================================= +Standard_Boolean TDataStd_RealList::RemoveByIndex (const Standard_Integer index) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TColStd_ListIteratorOfListOfReal itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.Remove(itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Clear //purpose : diff --git a/src/TDataStd/TDataStd_RealList.hxx b/src/TDataStd/TDataStd_RealList.hxx index a577afbf3a..17c693ecfe 100644 --- a/src/TDataStd/TDataStd_RealList.hxx +++ b/src/TDataStd/TDataStd_RealList.hxx @@ -62,12 +62,23 @@ public: //! Inserts the before the first meet of . Standard_EXPORT Standard_Boolean InsertBefore (const Standard_Real value, const Standard_Real before_value); + //! Inserts the before the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertBeforeByIndex (const Standard_Integer index, const Standard_Real before_value); + //! Inserts the after the first meet of . Standard_EXPORT Standard_Boolean InsertAfter (const Standard_Real value, const Standard_Real after_value); + //! Inserts the after the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertAfterByIndex (const Standard_Integer index, const Standard_Real after_value); + //! Removes the first meet of the . Standard_EXPORT Standard_Boolean Remove (const Standard_Real value); + //! Removes a value at position. + Standard_EXPORT Standard_Boolean RemoveByIndex (const Standard_Integer index); + Standard_EXPORT void Clear(); Standard_EXPORT Standard_Real First() const; diff --git a/src/TDataStd/TDataStd_ReferenceList.cxx b/src/TDataStd/TDataStd_ReferenceList.cxx index 45b4291d67..8dd2f34bd1 100644 --- a/src/TDataStd/TDataStd_ReferenceList.cxx +++ b/src/TDataStd/TDataStd_ReferenceList.cxx @@ -117,6 +117,27 @@ Standard_Boolean TDataStd_ReferenceList::InsertBefore(const TDF_Label& value, return Standard_False; } +// Inserts the label before the position. +// The indices start with 1 .. Extent(). +Standard_Boolean TDataStd_ReferenceList::InsertBefore (const Standard_Integer index, + const TDF_Label& before_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDF_ListIteratorOfLabelList itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertBefore(before_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : InsertAfter //purpose : @@ -137,6 +158,27 @@ Standard_Boolean TDataStd_ReferenceList::InsertAfter(const TDF_Label& value, return Standard_False; } +// Inserts the label after the position. +// The indices start with 1 .. Extent(). +Standard_Boolean TDataStd_ReferenceList::InsertAfter (const Standard_Integer index, + const TDF_Label& after_value) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDF_ListIteratorOfLabelList itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.InsertAfter(after_value, itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Remove //purpose : @@ -156,6 +198,28 @@ Standard_Boolean TDataStd_ReferenceList::Remove(const TDF_Label& value) return Standard_False; } +//======================================================================= +//function : Remove +//purpose : Removes a label at the position. +//======================================================================= +Standard_Boolean TDataStd_ReferenceList::Remove (const Standard_Integer index) +{ + Standard_Integer i(1); + Standard_Boolean found(Standard_False); + TDF_ListIteratorOfLabelList itr(myList); + for (; itr.More(); itr.Next(), ++i) + { + if (i == index) + { + Backup(); + myList.Remove(itr); + found = Standard_True; + break; + } + } + return found; +} + //======================================================================= //function : Clear //purpose : diff --git a/src/TDataStd/TDataStd_ReferenceList.hxx b/src/TDataStd/TDataStd_ReferenceList.hxx index 8cb98737f0..c65cd075f8 100644 --- a/src/TDataStd/TDataStd_ReferenceList.hxx +++ b/src/TDataStd/TDataStd_ReferenceList.hxx @@ -62,12 +62,23 @@ public: //! Inserts the before the first meet of . Standard_EXPORT Standard_Boolean InsertBefore (const TDF_Label& value, const TDF_Label& before_value); + //! Inserts the label before the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertBefore (const Standard_Integer index, const TDF_Label& before_value); + //! Inserts the after the first meet of . Standard_EXPORT Standard_Boolean InsertAfter (const TDF_Label& value, const TDF_Label& after_value); + //! Inserts the label after the position. + //! The indices start with 1 .. Extent(). + Standard_EXPORT Standard_Boolean InsertAfter (const Standard_Integer index, const TDF_Label& after_value); + //! Removes the first meet of the . Standard_EXPORT Standard_Boolean Remove (const TDF_Label& value); + //! Removes a label at "index" position. + Standard_EXPORT Standard_Boolean Remove (const Standard_Integer index); + Standard_EXPORT void Clear(); Standard_EXPORT const TDF_Label& First() const; diff --git a/tests/bugs/caf/bug23465 b/tests/bugs/caf/bug23465 new file mode 100644 index 0000000000..63c99e3a87 --- /dev/null +++ b/tests/bugs/caf/bug23465 @@ -0,0 +1,119 @@ +# =================== OCAF ====================== +# Standard attributes of List containers (xml format) +# +# Testing purpose: test of InsertBefore / InsertAfter / Remove +# of TDataStd_BooleanList, TDataStd_IntegerList +# TDataStd_RealList, TDataStd_ExtStringList, +# TDataStd_ReferenceList attributes +# +# =============================================== +# Test case: +# 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. insert before a value +# 7. insert after a value +# 8. remove a value +# 9. check the values +# =============================================== + +NewDocument D XmlOcaf +# 1. create BooleanList attribute +set Lab1 [Label D 0:1:1] +SetBooleanList D $Lab1 0 0 1 0 +set info1 [GetBooleanList D $Lab1] +# output => "0 0 1 0" + +# 2. create IntegerList attribute +set Lab2 [Label D 0:1:2] +SetIntegerList D $Lab2 0 0 1 0 +set info2 [GetIntegerList D $Lab2] +# output => "0 0 1 0" + +# 3. create RealList attribute +set Lab3 [Label D 0:1:3] +SetRealList D $Lab3 0 0 1 0 +set info3 [GetRealList D $Lab3] +# output => "0 0 1 0" + +# 4. create ExtStringList attribute +set Lab4 [Label D 0:1:4] +SetExtStringList D $Lab4 0 0 1 0 +set info4 [GetExtStringList D $Lab4] +# output => "0 0 1 0" + +# 5. create ReferenceList attribute +set Lab5 [Label D 0:1:5] +SetReferenceList D $Lab5 $Lab1 $Lab2 $Lab4 +set info5 [GetReferenceList D $Lab5] +# output => "0:1:1 0:1:2 0:1:4" + +# 6. insert before a value +InsertBeforeBooleanList D $Lab1 3 1 +InsertBeforeIntegerList D $Lab2 3 1 +InsertBeforeRealList D $Lab3 3 1 +InsertBeforeExtStringList D $Lab4 3 1 +InsertBeforeReferenceList D $Lab5 3 0:1:3 +# output => "0 0 1 1 0" +# output => "0:1:1 0:1:2 0:1:3 0:1:4" + +# 7. insert after a value +InsertAfterBooleanList D $Lab1 4 1 +InsertAfterIntegerList D $Lab2 4 1 +InsertAfterRealList D $Lab3 4 1 +InsertAfterExtStringList D $Lab4 4 1 +InsertAfterReferenceList D $Lab5 4 0:1:5 +# output => "0 0 1 1 1 0" +# output => "0:1:1 0:1:2 0:1:3 0:1:4 0:1:5" + +# 8. remove a value +RemoveBooleanList D $Lab1 6 +RemoveIntegerList D $Lab2 6 +RemoveRealList D $Lab3 6 +RemoveExtStringList D $Lab4 6 +RemoveReferenceList D $Lab5 1 +# output => "0 0 1 1 1" +# output => "0:1:2 0:1:3 0:1:4 0:1:5" + +# 8. Check the values +set info6 [GetBooleanList D $Lab1] +set info7 [GetIntegerList D $Lab2] +set info8 [GetRealList D $Lab3] +set info9 [GetExtStringList D $Lab4] +set info10 [GetReferenceList D $Lab5] +# output => "0 0 1 1 1" +# output => "0:1:2 0:1:3 0:1:4 0:1:5" + +Close D + +if { [regexp {0 0 1 1 1} ${info6}] } { + puts "OK: inserted and removed values for BooleanList attribute are good" +} else { + puts "Error: inserted and removed values for BooleanList attribute are bad" +} + +if { [regexp {0 0 1 1 1} ${info7}] } { + puts "OK: inserted and removed values for IntegerList attribute are good" +} else { + puts "Error: inserted and removed values for IntegerList attribute are bad" +} + +if { [regexp {0 0 1 1 1} ${info8}] } { + puts "OK: inserted and removed values for RealList attribute are good" +} else { + puts "Error: inserted and removed values for RealList attribute are bad" +} + +if { [regexp {0 0 1 1 1} ${info9}] } { + puts "OK: inserted and removed values for ExtStringList attribute are good" +} else { + puts "Error: inserted and removed values for ExtStringList attribute are bad" +} + +if { [regexp {0:1:2 0:1:3 0:1:4 0:1:5} ${info10}] } { + puts "OK: inserted and removed values for ReferenceList attribute are good" +} else { + puts "Error: inserted and removed values for ReferenceList attribute are bad" +}