]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.7
authorfred <fred>
Fri, 15 Nov 1996 23:41:54 +0000 (23:41 +0000)
committerfred <fred>
Fri, 15 Nov 1996 23:41:54 +0000 (23:41 +0000)
flower/list.cc
flower/list.inl

index 741e4ee97c87b48830c3d703ae66c69ad80b1d0a..ce5e366cc8259baf192bd6be9d14781dbe6ecd86 100644 (file)
@@ -34,51 +34,64 @@ List<T>::OK() const
     assert(!lp);
 }
 
+
 template<class T>
-Cursor<T>
-List<T>::top()
+inline
+List<T>::~List()
 {
-#if 0 
-    // ?? waarvoor is deze if ? 
-    if ( top_ )                        // equivalent: if ( size_ )
-       {
-       Link<T>* t = top_->previous();
-       assert( t != top_ );    // silly link
-       while ( t )
-           {
-               assert(false);  // this is even more silly.
-           top_ = t;
-           t = top_->previous();
-           }
-       }
-#endif
-    
-// list empty: Cursor not ok()
-    return Cursor<T>( *this, top_ );
+    Cursor<T> next(*this);
+    for ( Cursor<T> c( *this ); c.ok(); c = next ) {
+       next = c;
+       next++;
+       remove( c );
+    }
 }
 
-
 template<class T>
-Cursor<T>
-List<T>::bottom()
+inline void
+List<T>::add( const T& thing, Cursor<T> after_me )
 {
-    /* wat is dit voor zooi? kan dit niet weg?
+    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();
+    }
 
-    (invarianten!)
-    */
-    if ( bottom_ )             // equivalent: if ( size_ )
-       {
-       Link<T>* b = bottom_->next();
-       assert( b != bottom_ ); // silly link    
-       while ( b )
-           {
-           bottom_ = b;
-           b = bottom_->next();
-           }
-       }
-                               // list empty: Cursor not ok()
-    return Cursor<T>( *this, bottom_ );
+    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_++;
+
+}
 
 #endif
index 8bdcf158772df21f6764b6fa507742870c022ca8..d71e947050b17bb55f4e4da99cc22a8142ad63f2 100644 (file)
@@ -1,6 +1,8 @@
 // -*-c++-*-
+
 #ifndef LIST_INL
 #define LIST_INL
+
 template<class T>
 inline
 List<T>::List()
@@ -23,83 +25,6 @@ List<T>::List( const T& thing )
     set_empty();
     add( thing, Cursor<T>( *this, bottom_ ) );
 }
-
-template<class T>
-inline
-List<T>::~List()
-{
-    Cursor<T> next(*this);
-    for ( Cursor<T> c( *this ); c.ok(); c = next ) {
-       next = c;
-       next++;
-       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 )
@@ -119,6 +44,20 @@ List<T>::size() const
     return size_;
 }
 
+template<class T>
+inline Cursor<T>
+List<T>::top()
+{
+    return Cursor<T>( *this, top_ );
+}
+
+
+template<class T>
+inline Cursor<T>
+List<T>::bottom()
+{
+    return Cursor<T>( *this, bottom_ );
+}
 
 
 #endif