From d81a6b6fc86f77f66ed67fbdbf63087fada15a48 Mon Sep 17 00:00:00 2001 From: fred Date: Sat, 8 Mar 1997 19:00:51 +0000 Subject: [PATCH] lilypond-0.0.43 --- flower/include/cursor.inl | 113 +++++++++++++++++ flower/include/link.inl | 102 +++++++++++++++ flower/include/list.inl | 56 +++++++++ flower/include/plist.inl | 21 ++++ flower/include/string-data.inl | 210 +++++++++++++++++++++++++++++++ flower/include/string-handle.inl | 156 +++++++++++++++++++++++ 6 files changed, 658 insertions(+) create mode 100644 flower/include/cursor.inl create mode 100644 flower/include/link.inl create mode 100644 flower/include/list.inl create mode 100644 flower/include/plist.inl create mode 100644 flower/include/string-data.inl create mode 100644 flower/include/string-handle.inl diff --git a/flower/include/cursor.inl b/flower/include/cursor.inl new file mode 100644 index 0000000000..54d3703e60 --- /dev/null +++ b/flower/include/cursor.inl @@ -0,0 +1,113 @@ + // cursor.inl -*-c++-*- +#ifndef CURSOR_INL +#define CURSOR_INL +#include + + +template +inline +Cursor::Cursor( const List& list, Link* pointer ) : + list_((List&) list ) +{ + if ( list.size() ) + pointer_ = pointer ? pointer : list.top_; + else + pointer_ = pointer; +} + +template +inline +Cursor::Cursor( const Cursor& cursor ) : + list_( cursor.list_ ) +{ + pointer_ = cursor.pointer_; +} + +template +inline T& +Cursor::thing() +{ + assert( pointer_ ); + return pointer_->thing(); +} + +template +Cursor +Cursor::operator =( const Cursor& c ) +{ + assert( &list_ == &c.list_ ); + pointer_ = c.pointer_; + return *this; +} + +template +inline void +Cursor::add( const T& th ) +{ + list_.add( th, *this ); +} + +template +inline void +Cursor::insert( const T& th ) +{ + list_.insert( th, *this ); +} + +template +inline List& +Cursor::list() const +{ + return list_; +} + +template +inline Link* +Cursor::pointer() +{ + return pointer_; +} + +template +inline bool +Cursor::backward() +{ + return ( pointer_ != 0 ); +} + +template +inline bool +Cursor::forward() +{ + return ( pointer_ != 0 ); +} + +template +inline bool +Cursor::ok() +{ + return ( pointer_ != 0 ); +} + + +template +inline Cursor +Cursor::operator ++( int ) +{ + Cursor r (*this); + assert( pointer_ ); + pointer_ = pointer_->next(); + return r; +} + +template +inline Cursor +Cursor::operator --( int ) +{ + Cursor r (*this); + assert( pointer_ ); + pointer_ = pointer_->previous(); + return r; +} + +#endif diff --git a/flower/include/link.inl b/flower/include/link.inl new file mode 100644 index 0000000000..3926d6bc2a --- /dev/null +++ b/flower/include/link.inl @@ -0,0 +1,102 @@ +// link.inl -*-c++-*- +#ifndef LINK_INL +#define LINK_INL +#include +template +inline +void +Link::OK() const +{ +#ifndef NDEBUG + if (previous_) { + assert(previous_->next_ == this); + } + if (next_) { + assert(next_->previous_ == this); + } +#endif +} + +template +inline +Link::Link( const T& thing ) : + thing_( thing ) +{ + previous_ = next_ = 0; +} + +template +inline +Link::Link( Link* previous, Link* next, const T& thing ) : + thing_( thing ) +{ + previous_ = previous; + next_ = next; +} + +template +inline +Link* +Link::next() +{ + return next_; +} + +template +inline +Link* +Link::previous() +{ + return previous_; +} + +template +inline +void +Link::add( const T& thing ) +{ + + Link* l = new Link( this, next_, thing ); + if ( next_ ) + next_->previous_ = l; + next_ = l; +} + +template +inline void +Link::insert( const T& thing ) +{ + // Link* l = new Link( next_, this, thing ); + // bugfix hwn 16/9/96 + Link* l = new Link( previous_, this, thing ); + if ( previous_ ) + previous_->next_ = l; + previous_ = l; +} + +/* + don't forget to adjust #l#'s top_ and bottom_. + */ +template +inline void +Link::remove(List &l) +{ + if ( previous_ ) + previous_->next_ = next_; + else + l.top_ = next_; + + if ( next_ ) + next_->previous_ = previous_; + else + l.bottom_ = previous_; +} + +template +inline +T& +Link::thing() +{ + return thing_; +} +#endif diff --git a/flower/include/list.inl b/flower/include/list.inl new file mode 100644 index 0000000000..df0687b7c8 --- /dev/null +++ b/flower/include/list.inl @@ -0,0 +1,56 @@ +// -*-c++-*- + +#ifndef LIST_INL +#define LIST_INL + +template +inline +List::List() +{ + set_empty(); +} + +template +inline void +List::set_empty() +{ + top_ = bottom_ = 0; + size_ = 0; +} + +template +inline void +List::remove( Cursor me ) +{ + if ( me.ok() ){ + Link *lp = me.pointer(); + lp->remove(*this); + delete lp; + size_--; + } +} + +template +inline int +List::size() const +{ + return size_; +} + +template +inline Cursor +List::top()const +{ + return Cursor( *this, top_ ); +} + + +template +inline Cursor +List::bottom()const +{ + return Cursor( *this, bottom_ ); +} + + +#endif diff --git a/flower/include/plist.inl b/flower/include/plist.inl new file mode 100644 index 0000000000..82be364334 --- /dev/null +++ b/flower/include/plist.inl @@ -0,0 +1,21 @@ +/* -*-c++-*- + plist.inl -- part of flowerlib + + (c) 1996 Han-Wen Nienhuys& Jan Nieuwenhuizen +*/ + +#ifndef PLIST_INL +#define PLIST_INL + +template +void +PL_copy(IPointerList &to, IPointerList const&src) +{ + for (PCursor pc(src); pc.ok(); pc++) { + T *q = pc; + T *p=new T(*q) ; + to.bottom().add(p); + } +} + +#endif diff --git a/flower/include/string-data.inl b/flower/include/string-data.inl new file mode 100644 index 0000000000..d2b925d0ce --- /dev/null +++ b/flower/include/string-data.inl @@ -0,0 +1,210 @@ +/* -*-C++-*- + String_data.inl -- implement String_data + + source file of Flower lib + + (c) 1997 Han-Wen Nienhuys +*/ + +#ifndef STRINGDATA_INL +#define STRINGDATA_INL + +#include +#include + +#include "string-data.hh" +const int INITIALMAX=8; + +#include + +INLINE void +String_data::OKW() +{ + assert (references == 1); +} + +INLINE void +String_data::OK() +{ + assert(maxlen >= length_i_); + assert(bool(data_byte_p_)); + assert(references >= 1); +} + + +INLINE +String_data::String_data() +{ + references=0; + maxlen = INITIALMAX; + data_byte_p_ = new Byte[maxlen + 1]; + data_byte_p_[0] = 0; + length_i_ = 0; +} + +INLINE +String_data::String_data(String_data const &src) +{ + references=0; + maxlen = length_i_ = src.length_i_; + data_byte_p_ = new Byte[maxlen+1]; // should calc GNU 8byte overhead. + memcpy( data_byte_p_, src.data_byte_p_, length_i_ + 1 ); +} + +INLINE +String_data::~String_data() +{ + assert(references == 0); + delete[] data_byte_p_; +} + +INLINE void +String_data::setmax(int j) +{ + OKW(); + if (j > maxlen) { + delete data_byte_p_; + maxlen = j; + data_byte_p_ = new Byte[maxlen + 1]; + + data_byte_p_[0] = 0; + length_i_ = 0; + } +} + +/* this is all quite hairy: + update of length_i_ + update of maxlen + alloc of buffer + copying of buffer + needs blondification: + split tasks + define change authority +*/ +INLINE void +String_data::remax(int j) +{ + OKW(); + if (j > maxlen) { + Byte *p = new Byte[j + 1]; + memcpy( p, data_byte_p_, ( maxlen = 0 && j <= length_i_); + data_byte_p_[j] = 0; + length_i_ = j; +} + +INLINE bool +String_data::is_binary_bo()const +{ +// return !memchr(data_byte_p_, length_i_, 0); + return ( (int)strlen( (char const*)data_byte_p_ ) != length_i_ ); +} + +INLINE Byte& +String_data::operator [](int j) +{ + assert(j >= 0 && j <= length_i_); + return data_byte_p_[j] ; +} + +INLINE Byte +String_data::operator [](int j) const +{ + assert(j >= 0 && j <= length_i_); + return data_byte_p_[j]; +} + + + + +#endif // __STRING_UTIL_CC // diff --git a/flower/include/string-handle.inl b/flower/include/string-handle.inl new file mode 100644 index 0000000000..1f1d44ab13 --- /dev/null +++ b/flower/include/string-handle.inl @@ -0,0 +1,156 @@ +/* -*-c++-*- + + stringhandle.inl -- implement String_handle + + source file of Flower lib + + (c) 1997 Han-Wen Nienhuys +*/ + +#ifndef STRINGHANDLE_INL +#define STRINGHANDLE_INL + +#include +#include + +#include "string-data.hh" +#include "string-handle.hh" + +INLINE void +String_handle::down() +{ + if (!(--data->references)) delete data; data = 0; +} + +/// increase ref count +INLINE void +String_handle::up(String_data *d) +{ + data=d; data->references ++; +} + +INLINE void +String_handle::copy() +{ + if (data->references !=1){ + String_data *newdata = new String_data(*data); + down(); + up(newdata); + } +} + +INLINE +String_handle::String_handle() +{ + up(new String_data); +} + +INLINE +String_handle::~String_handle() +{ + down(); +} + +INLINE +String_handle::String_handle(String_handle const & src) +{ + up(src.data); +} + +INLINE Byte* +String_handle::byte_l() +{ + copy(); + return data->byte_l(); +} + +INLINE char* +String_handle::ch_l() +{ + copy(); + return (char*)data->byte_l(); +} + +INLINE Byte +const* String_handle::byte_c_l() const +{ + return data->byte_c_l(); +} + +INLINE char const* +String_handle::ch_c_l() const +{ + return (char const*)data->byte_c_l(); +} + +INLINE void +String_handle::operator =(String_handle const &src) +{ + if (this == &src) + return; + down(); + up(src.data); +} + +INLINE void +String_handle::operator += (char const *s) +{ + copy(); + *data += s; +} + + +INLINE Byte +String_handle::operator[](int j) const +{ + return (*data)[j]; +} + +// !NOT SAFE! +// don't use this for loops. Use byte_c_l() +INLINE Byte & +String_handle::operator[](int j) +{ + copy(); // hmm. Not efficient + return data->byte_l()[j]; +} + +INLINE void +String_handle::append( Byte const* byte_c_l, int length_i ) +{ + copy(); + data->append( byte_c_l, length_i ); +} + +INLINE void +String_handle::set( Byte const* byte_c_l, int length_i ) +{ + copy(); + data->set( byte_c_l, length_i ); +} + +INLINE void +String_handle::operator = (char const *p) +{ + copy(); + data->set( p ); +} + +INLINE void +String_handle::trunc(int j) +{ + copy(); data->trunc(j); +} + +INLINE int +String_handle::length_i() const +{ + return data->length_i_; +} + +INLINE bool +String_handle::is_binary_bo() const { + return data->is_binary_bo(); +} + +#endif -- 2.39.5