]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/list.inl
release: 0.0.18
[lilypond.git] / flower / list.inl
index 54df45748169f6b10180820437a5de38390ebb6f..df0687b7c8b5b28e71cfd47ad96fbbd64b7caf8e 100644 (file)
 // -*-c++-*-
+
 #ifndef LIST_INL
 #define LIST_INL
+
 template<class T>
 inline
 List<T>::List()
 {
-    top_ = bottom_ = 0;
-    size_ = 0;
+    set_empty();
 }
 
 template<class T>
-inline
-List<T>::List( const T& thing )
+inline void
+List<T>::set_empty()
 {
     top_ = bottom_ = 0;
     size_ = 0;
-    add( thing, Cursor<T>( *this, bottom_ ) );
-}
-
-template<class T>
-inline
-List<T>::~List()
-{
-    for ( Cursor<T> c( *this ); c.forward(); c++ )
-        remove( c );
-}
-
-template<class T>
-inline void
-List<T>::add( const T& thing, Cursor<T> after_me )
-{
-#if 0
-    if ( after_me.ok() )
-       after_me.pointer()->add( thing );
-    else if ( size_ )
-        bottom().pointer()->add( thing );
-    else
-        bottom_ = top_ = new Link<T>( thing );
-#endif
-    
-    if (!size_) {              // not much choice if list is empty
-        bottom_ = top_ = new Link<T>( thing );
-    } else {                   // add at aprioprate place
-       Link<T> *p =  ( after_me.ok() ) ?
-           after_me.pointer() : bottom().pointer();
-       p->add(thing);
-       if (p == bottom_)       // adjust bottom_ if necessary.
-           bottom_ = p->next();
-    }
-
-    size_++;
-}
-/** 
-
-  Procedure:
-  \begin{itemize}
-  \item if #after_me# is #ok()#, add after #after_me#, else
-  \item if list !empty simply add to bottom, else
-  \item list is empty: create first \Ref{Link} and initialize 
-  #bottom_# and #top_#.
-  \end{itemize}
-*/
-
-template<class T>
-inline void
-List<T>::insert( const T& thing, Cursor<T> before_me )
-{
-    if (!size_) {
-       bottom_ = top_ = new Link<T>( thing );
-    } else {
-       Link<T> *p = 
-           (before_me.ok())?
-           before_me.pointer() : top().pointer();
-
-       p->insert(thing);
-       if (p == top_)
-           top_ = p->previous();
-    }
-       
-    size_++;
-#if 0 // rewrite hwn 16/9              
-    if ( before_me.ok() )
-        before_me.pointer()->insert( thing );
-    else if ( size_ )
-       top().pointer()->insert( thing );
-    else
-       bottom_ = top_ = new Link<T>( thing );
-    size_++;
-#endif
 }
 
 template<class T>
 inline void
 List<T>::remove( Cursor<T> me )
 {
-    if ( me.ok() )
-       {
-       me.pointer()->remove(*this);
-       delete me.pointer();
+    if ( me.ok() ){
+       Link<T> *lp = me.pointer();     
+       lp->remove(*this);
+       delete lp;
         size_--;
-       }
+    }
 }
 
 template<class T>
@@ -110,34 +38,18 @@ List<T>::size() const
 }
 
 template<class T>
-inline
-PointerList<T>::PointerList() :
-    List<T>()
-{
-}
-
-template<class T>
-inline
-PointerList<T>::PointerList( const T& thing ) :
-    List<T>( thing )
+inline Cursor<T>
+List<T>::top()const
 {
+    return Cursor<T>( *this, top_ );
 }
 
-template<class T>
-inline
-PointerList<T>::~PointerList()
-{
-    for ( Cursor<T> c( *this ); c.forward(); c++ )
-        remove( c );
-}
 
 template<class T>
-inline void
-PointerList_print( PointerList<T> const & l  ) 
+inline Cursor<T>
+List<T>::bottom()const
 {
-    List<T>& promises_to_be_const = (List<T>&) l;
-    for ( Cursor<T> c( promises_to_be_const ); c.forward(); c++ )
-        (*c)->print();  
+    return Cursor<T>( *this, bottom_ );
 }