From: Han-Wen Nienhuys & Jan Nieuwenhuizen Date: Fri, 1 Nov 1996 16:48:30 +0000 (+0100) Subject: partial: 0.0.4.hanjan X-Git-Tag: release/0.0.4~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3daac955f29e408aa2aa271a883195ddc54633f4;p=lilypond.git partial: 0.0.4.hanjan --- diff --git a/flower/plist.hh b/flower/plist.hh new file mode 100644 index 0000000000..3660968a47 --- /dev/null +++ b/flower/plist.hh @@ -0,0 +1,53 @@ +/* + list.hh -- part of flowerlib + + (c) 1996 Han-Wen Nienhuys & Jan Nieuwenhuizen +*/ + +#ifndef PLIST_HH +#define PLIST_HH + +#include "list.hh" + +/// Use for list of pointers, e.g. PointerList. +template +class PointerList : public List +{ + public: + PointerList(PointerList&) { set_empty(); } + PointerList( const T& thing ) : List( thing ) { } + PointerList() {} + /// + virtual ~PointerList(); + /** + This function deletes deletes the allocated pointers of all links. + #\Ref{~List}# is used to delete the links themselves. + */ + + protected: + virtual void remove( Cursor me ); +}; +/** + NOTE: + The copy constructor doesn't do what you'd want: + Since T might have a virtual ctor, we don't try to do a + + new T(*cursor) + + You have to copy this yourself, or use the macro PointerList__copy + + */ +#define PointerList__copy(T, to, from, op) \ + for (PCursor _pc_(from); _pc_.ok(); _pc_++)\ + to.bottom().add(_pc_->op)\ + \ + + +template +void PL_copy(PointerList &dst,PointerList const&src); + +#define PL_instantiate(a) L_instantiate(a *); template class PointerList + +#include "plist.inl" + +#endif diff --git a/flower/plist.inl b/flower/plist.inl new file mode 100644 index 0000000000..fb18c87241 --- /dev/null +++ b/flower/plist.inl @@ -0,0 +1,43 @@ +/* -*-c++-*- + plist.inl -- part of flowerlib + + (c) 1996 Han-Wen Nienhuys& Jan Nieuwenhuizen +*/ + +#ifndef PLIST_INL +#define PLIST_INL + + + +template +inline +PointerList::~PointerList() +{ + Cursor next(*this); + for ( Cursor c( *this ); c.ok(); c = next ) { + next = c; + next++; + remove( c ); // PointerList::remove deletes the real data + } +} + +template +inline void +PointerList_print( PointerList const & l ) +{ + List& promises_to_be_const = (List&) l; + for ( Cursor c( promises_to_be_const ); c.ok(); c++ ) + (*c)->print(); +} + +template +inline void +PL_copy(PointerList &to,PointerList const&src) +{ + for (PCursor pc(src); pc.ok(); pc++) { + T q = pc; + T p=new typeof(*q) (*q) ; // argh, how do i do this in ANSI-C++ + to.bottom().add(p); + } +} +#endif