diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h index 60c2bd226fc0de40b4d60818b31cdc4875c9c4a5..0bc1f61d0a237d96f0aad9ab8f2ed613f0bc61dd 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h @@ -210,7 +210,7 @@ ext::smart_ptr < FormalRegExpElement < SymbolType > > UnboundedRegExpAlternation ext::smart_ptr < FormalRegExpElement < SymbolType > > res = getElements ( ) [ getElements ( ).size ( ) - 1 ].asFormal ( ); - for ( unsigned i = getElements ( ).size ( ) - 1; i >= 1; i-- ) + for ( size_t i = getElements ( ).size ( ) - 1; i >= 1; i-- ) res = ext::smart_ptr < FormalRegExpElement < SymbolType > > ( new FormalRegExpAlternation < SymbolType > ( std::move ( * getElements ( ) [ i - 1 ].asFormal ( ) ), std::move ( * res ) ) ); return res; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h index 06b71fce74ac27cb445c50ececcbfff2c99f89fb..654dec8095ab4cb2fc61a5c4b549a787b49ccc11 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h @@ -210,7 +210,7 @@ ext::smart_ptr < FormalRegExpElement < SymbolType > > UnboundedRegExpConcatenati ext::smart_ptr < FormalRegExpElement < SymbolType > > res = getElements ( )[ getElements ( ).size ( ) - 1 ].asFormal ( ); - for ( unsigned i = getElements ( ).size ( ) - 1; i >= 1; i-- ) + for ( size_t i = getElements ( ).size ( ) - 1; i >= 1; i-- ) res = ext::smart_ptr < FormalRegExpElement < SymbolType > > ( new FormalRegExpConcatenation < SymbolType > ( std::move ( * getElements ( )[ i - 1 ].asFormal ( ) ), std::move ( * res ) ) ); return res; diff --git a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h index addff58506203b9725b8ae64539ef99d016c35ec..91020ed2aaca244a1d4ee29a13b38fd2e1f0fe92 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h +++ b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h @@ -111,14 +111,14 @@ public: * * \return child node */ - const FormalRTEElement < SymbolType, RankType > & getElement ( unsigned index ) const; + const FormalRTEElement < SymbolType, RankType > & getElement ( size_t index ) const; /** * Getter of child node on n-th position * * \return child node */ - FormalRTEElement < SymbolType, RankType > & getElement ( unsigned index ); + FormalRTEElement < SymbolType, RankType > & getElement ( size_t index ); /** * Setter of the n-th child @@ -126,7 +126,7 @@ public: * \param index the index of child to change * \param element the iterated tree */ - void setElement ( unsigned index, const FormalRTEElement < SymbolType, RankType > & element ); + void setElement ( size_t index, const FormalRTEElement < SymbolType, RankType > & element ); /** * Setter of the n-th child @@ -134,7 +134,7 @@ public: * \param index the index of child to change * \param element the iterated tree */ - void setElement ( unsigned index, FormalRTEElement < SymbolType, RankType > && element ); + void setElement ( size_t index, FormalRTEElement < SymbolType, RankType > && element ); /** * @copydoc base::CommonBase < FormalRTEElement < SymbolType, RankType > >::compare ( const FormalRTEElement < SymbolType, RankType > & ) const @@ -204,22 +204,22 @@ const ext::ptr_vector < FormalRTEElement < SymbolType, RankType > > & FormalRTES } template < class SymbolType, class RankType > -const FormalRTEElement < SymbolType, RankType > & FormalRTESymbolAlphabet < SymbolType, RankType >::getElement ( unsigned index ) const { +const FormalRTEElement < SymbolType, RankType > & FormalRTESymbolAlphabet < SymbolType, RankType >::getElement ( size_t index ) const { return this->getChild ( index ); } template < class SymbolType, class RankType > -FormalRTEElement < SymbolType, RankType > & FormalRTESymbolAlphabet < SymbolType, RankType >::getElement ( unsigned index ) { +FormalRTEElement < SymbolType, RankType > & FormalRTESymbolAlphabet < SymbolType, RankType >::getElement ( size_t index ) { return this->getChild ( index ); } template < class SymbolType, class RankType > -void FormalRTESymbolAlphabet < SymbolType, RankType >::setElement ( unsigned index, const FormalRTEElement < SymbolType, RankType > & element ) { +void FormalRTESymbolAlphabet < SymbolType, RankType >::setElement ( size_t index, const FormalRTEElement < SymbolType, RankType > & element ) { setElement ( index, ext::move_copy ( element ) ); } template < class SymbolType, class RankType > -void FormalRTESymbolAlphabet < SymbolType, RankType >::setElement ( unsigned index, FormalRTEElement < SymbolType, RankType > && elementParam ) { +void FormalRTESymbolAlphabet < SymbolType, RankType >::setElement ( size_t index, FormalRTEElement < SymbolType, RankType > && elementParam ) { this->setChild ( std::move ( elementParam ), index ); } diff --git a/alib2std/src/extensions/container/tree_base.hpp b/alib2std/src/extensions/container/tree_base.hpp index 27afbb866b1ce9f9ce5c3dbc57ff5ee75d39a7b1..7f648c3c93cb99f27fbd40e457d786c7ace86960 100644 --- a/alib2std/src/extensions/container/tree_base.hpp +++ b/alib2std/src/extensions/container/tree_base.hpp @@ -246,7 +246,7 @@ public: * * \return child node at given index */ - template < int N > + template < size_t N > const Data & getChild ( ) const { return std::get < N > ( m_children ); } @@ -259,7 +259,7 @@ public: * * \return child node at given index */ - template < int N > + template < size_t N > Data & getChild ( ) { return std::get < N > ( m_children ); } @@ -283,7 +283,7 @@ public: * * \return child node at given index */ - template < int N > + template < size_t N > void setChild ( const Data & d ) { m_children.set ( m_children.cbegin ( ) + N, d ); std::get < N > ( m_children )->parent = static_cast < Cast * > ( this ); @@ -297,7 +297,7 @@ public: * * \return child node at given index */ - template < int N > + template < size_t N > void setChild ( Data && d ) { m_children.set ( m_children.cbegin ( ) + N, std::move ( d ) ); std::get < N > ( m_children )->parent = static_cast < Cast * > ( this ); @@ -857,7 +857,7 @@ public: * * \return reference to the child at given index */ - Data & getChild ( int index ) { + Data & getChild ( size_t index ) { return m_children [ index ]; } @@ -869,7 +869,7 @@ public: * * \return reference to the child at given index */ - const Data & getChild ( int index ) const { + const Data & getChild ( size_t index ) const { return m_children [ index ]; } @@ -880,7 +880,8 @@ public: * \param d the new child node * \param it the position where to change the child */ - void setChild ( Data && d, typename ext::ptr_vector < Data >::const_iterator it ) { + template < class PositionIterator > + void setChild ( Data && d, PositionIterator it ) { m_children.set ( it, std::move ( d ) )->parent = static_cast < Cast * > ( this ); } @@ -891,7 +892,8 @@ public: * \param d the new child node * \param it the position where to change the child */ - void setChild ( const Data & d, typename ext::ptr_vector < Data >::const_iterator it ) { + template < class PositionIterator > + void setChild ( const Data & d, PositionIterator it ) { m_children.set ( it, d )->parent = static_cast < Cast * > ( this ); } @@ -902,7 +904,7 @@ public: * \param d the new child node * \param index the position where to change the child */ - void setChild ( const Data & d, int index ) { + void setChild ( const Data & d, size_t index ) { setChild ( d, m_children.begin ( ) + index ); } @@ -913,7 +915,7 @@ public: * \param d the new child node * \param index the position where to change the child */ - void setChild ( Data && d, int index ) { + void setChild ( Data && d, size_t index ) { setChild ( std::move ( d ), m_children.begin ( ) + index ); } @@ -1096,7 +1098,7 @@ public: * * \return reference to the child at given index */ - Data & getChild ( int index ) { + Data & getChild ( size_t index ) { return m_children [ index ]; } @@ -1108,7 +1110,7 @@ public: * * \return reference to the child at given index */ - const Data & getChild ( int index ) const { + const Data & getChild ( size_t index ) const { return m_children [ index ]; } @@ -1119,8 +1121,9 @@ public: * \param d the new child node * \param it the position where to change the child */ - void setChild ( Data && d, typename ext::ptr_vector < Data >::const_iterator it ) { - m_children.set ( it, std::move ( d ) )->parent = static_cast < Cast * > ( this ); + template < class PositionIterator > + void setChild ( const Data & d, PositionIterator it ) { + m_children.set ( it, d )->parent = static_cast < Cast * > ( this ); } /** @@ -1130,8 +1133,9 @@ public: * \param d the new child node * \param it the position where to change the child */ - void setChild ( const Data & d, typename ext::ptr_vector < Data >::const_iterator it ) { - m_children.set ( it, d )->parent = static_cast < Cast * > ( this ); + template < class PositionIterator > + void setChild ( Data && d, PositionIterator it ) { + m_children.set ( it, std::move ( d ) )->parent = static_cast < Cast * > ( this ); } /** @@ -1141,7 +1145,7 @@ public: * \param d the new child node * \param index the position where to change the child */ - void setChild ( const Data & d, int index ) { + void setChild ( const Data & d, size_t index ) { setChild ( d, m_children.begin ( ) + index ); } @@ -1152,10 +1156,53 @@ public: * \param d the new child node * \param index the position where to change the child */ - void setChild ( Data && d, int index ) { + void setChild ( Data && d, size_t index ) { setChild ( std::move ( d ), m_children.begin ( ) + index ); } + /** + * \brief + * Inserts a new child at position specified by iterator. + * + * \param it the position where to insert + * \param d the new child to insert + * + * \return the updated iterator to the inserted child + */ + typename ext::ptr_vector < Data >::reverse_iterator insert ( typename ext::ptr_vector < Data >::reverse_iterator it, const Data & d ) { + return insert ( typename ext::ptr_vector < Data >::const_reverse_iterator ( it ), d ); + } + + /** + * \brief + * Inserts a new child at position specified by iterator. + * + * \param it the position where to insert + * \param d the new child to insert + * + * \return the updated iterator to the inserted child + */ + typename ext::ptr_vector < Data >::reverse_iterator insert ( typename ext::ptr_vector < Data >::const_reverse_iterator it, const Data & d ) { + typename ext::ptr_vector < Data >::reverse_iterator iter = m_children.insert ( it, d ); + + iter->parent = static_cast < Cast * > ( this ); + + return iter; + } + + /** + * \brief + * Inserts a new child at position specified by iterator. + * + * \param it the position where to insert + * \param d the new child to insert + * + * \return the updated iterator to the inserted child + */ + typename ext::ptr_vector < Data >::iterator insert ( typename ext::ptr_vector < Data >::iterator it, const Data & d ) { + return insert ( typename ext::ptr_vector < Data >::const_iterator ( it ), d ); + } + /** * \brief * Inserts a new child at position specified by iterator. @@ -1173,6 +1220,49 @@ public: return iter; } + /** + * \brief + * Inserts a new child at position specified by iterator. + * + * \param it the position where to insert + * \param d the new child to insert + * + * \return the updated iterator to the inserted child + */ + typename ext::ptr_vector < Data >::reverse_iterator insert ( typename ext::ptr_vector < Data >::reverse_iterator it, Data && d ) { + return insert ( typename ext::ptr_vector < Data >::const_reverse_iterator ( it ), std::move ( d ) ); + } + + /** + * \brief + * Inserts a new child at position specified by iterator. + * + * \param it the position where to insert + * \param d the new child to insert + * + * \return the updated iterator to the inserted child + */ + typename ext::ptr_vector < Data >::reverse_iterator insert ( typename ext::ptr_vector < Data >::const_reverse_iterator it, Data && d ) { + typename ext::ptr_vector < Data >::reverse_iterator iter = m_children.insert ( it, std::move ( d ) ); + + iter->parent = static_cast < Cast * > ( this ); + + return iter; + } + + /** + * \brief + * Inserts a new child at position specified by iterator. + * + * \param it the position where to insert + * \param d the new child to insert + * + * \return the updated iterator to the inserted child + */ + typename ext::ptr_vector < Data >::iterator insert ( typename ext::ptr_vector < Data >::iterator it, Data && d ) { + return insert ( typename ext::ptr_vector < Data >::const_iterator ( it ), std::move ( d ) ); + } + /** * \brief * Inserts a new child at position specified by iterator. @@ -1190,6 +1280,48 @@ public: return iter; } + /** + * \brief + * Inserts a new children from a given range at position specified by iterator. + * + * \tparam InputIterator tye type of iterators specifying the range of new children + * + * \param it the position where to insert + * \param first the begining of the children range + * \param last the end of the children range + * + * \return the updated iterator to the inserted child + */ + template < class InputIterator > + typename ext::ptr_vector < Data >::reverse_iterator insert ( typename ext::ptr_vector < Data >::const_reverse_iterator it, InputIterator first, InputIterator last ) { + size_t size = std::distance ( first, last ); + + typename ext::ptr_vector < Data >::reverse_iterator iter = m_children.insert ( it, first, last ); + + for ( size_t i = 0; i < size; ++ i ) { + ( iter + i )->parent = static_cast < Cast * > ( this ); + } + + return iter; + } + + /** + * \brief + * Inserts a new children from a given range at position specified by iterator. + * + * \tparam InputIterator tye type of iterators specifying the range of new children + * + * \param it the position where to insert + * \param first the begining of the children range + * \param last the end of the children range + * + * \return the updated iterator to the inserted child + */ + template < class InputIterator > + typename ext::ptr_vector < Data >::reverse_iterator insert ( typename ext::ptr_vector < Data >::reverse_iterator it, InputIterator first, InputIterator last ) { + return insert ( typename ext::ptr_vector < Data >::const_reverse_iterator ( it ), first, last ); + } + /** * \brief * Inserts a new children from a given range at position specified by iterator. @@ -1215,6 +1347,59 @@ public: return iter; } + /** + * \brief + * Inserts a new children from a given range at position specified by iterator. + * + * \tparam InputIterator tye type of iterators specifying the range of new children + * + * \param it the position where to insert + * \param first the begining of the children range + * \param last the end of the children range + * + * \return the updated iterator to the inserted child + */ + template < class InputIterator > + typename ext::ptr_vector < Data >::iterator insert ( typename ext::ptr_vector < Data >::iterator it, InputIterator first, InputIterator last ) { + return insert ( typename ext::ptr_vector < Data >::const_iterator ( it ), first, last ); + } + + /** + * \brief + * Erases a child specified by an iterator. + * + * \param it the position where to insert + * + * \return the updated iterator to node after the erased one + */ + typename ext::ptr_vector < Data >::reverse_iterator erase ( typename ext::ptr_vector < Data >::reverse_iterator it ) { + return m_children.erase ( typename ext::ptr_vector < Data >::const_reverse_iterator ( it ) ); + } + + /** + * \brief + * Erases a child specified by an iterator. + * + * \param it the position where to insert + * + * \return the updated iterator to node after the erased one + */ + typename ext::ptr_vector < Data >::reverse_iterator erase ( typename ext::ptr_vector < Data >::const_reverse_iterator it ) { + return m_children.erase ( it ); + } + + /** + * \brief + * Erases a child specified by an iterator. + * + * \param it the position where to insert + * + * \return the updated iterator to node after the erased one + */ + typename ext::ptr_vector < Data >::iterator erase ( typename ext::ptr_vector < Data >::iterator it ) { + return erase ( typename ext::ptr_vector < Data >::const_iterator ( it ) ); + } + /** * \brief * Erases a child specified by an iterator. @@ -1227,6 +1412,45 @@ public: return m_children.erase ( it ); } + /** + * \brief + * Erases a range of children specified by an iterator. + * + * \param first the position where to insert + * \param last the position where to insert + * + * \return the updated iterator to node after the last erased one + */ + typename ext::ptr_vector < Data >::reverse_iterator erase ( typename ext::ptr_vector < Data >::reverse_iterator first, typename ext::ptr_vector < Data >::reverse_iterator last ) { + return m_children.erase ( typename ext::ptr_vector < Data >::const_reverse_iterator ( first ), typename ext::ptr_vector < Data >::const_reverse_iterator ( last ) ); + } + + /** + * \brief + * Erases a range of children specified by an iterator. + * + * \param first the position where to insert + * \param last the position where to insert + * + * \return the updated iterator to node after the last erased one + */ + typename ext::ptr_vector < Data >::reverse_iterator erase ( typename ext::ptr_vector < Data >::const_reverse_iterator first, typename ext::ptr_vector < Data >::const_reverse_iterator last ) { + return m_children.erase ( first, last ); + } + + /** + * \brief + * Erases a range of children specified by an iterator. + * + * \param first the position where to insert + * \param last the position where to insert + * + * \return the updated iterator to node after the last erased one + */ + typename ext::ptr_vector < Data >::iterator erase ( typename ext::ptr_vector < Data >::iterator first, typename ext::ptr_vector < Data >::iterator last ) { + return m_children.erase ( typename ext::ptr_vector < Data >::const_iterator ( first ), typename ext::ptr_vector < Data >::const_iterator ( last ) ); + } + /** * \brief * Erases a range of children specified by an iterator.