]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.46.jcn1
authorfred <fred>
Sat, 22 Mar 1997 00:19:59 +0000 (00:19 +0000)
committerfred <fred>
Sat, 22 Mar 1997 00:19:59 +0000 (00:19 +0000)
flower/include/string-data.icc [new file with mode: 0644]
flower/include/string-handle.icc [new file with mode: 0644]

diff --git a/flower/include/string-data.icc b/flower/include/string-data.icc
new file mode 100644 (file)
index 0000000..5a3bb39
--- /dev/null
@@ -0,0 +1,210 @@
+/* -*-C++-*-
+  String_data.inl -- implement String_data
+
+  source file of Flower lib
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef STRINGDATA_INL
+#define STRINGDATA_INL
+
+#include <assert.h>
+#include <memory.h>
+
+#include "string-data.hh"
+const int INITIALMAX=8;
+
+#include <sys/types.h>
+
+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 <? length_i_ ) + 1 );     
+       maxlen = j;
+       delete[] data_byte_p_;
+       data_byte_p_ = p;
+    }
+}
+
+INLINE void 
+String_data::tighten() 
+{ // should be dec'd const
+    maxlen = length_i_;
+    Byte *p = new Byte[maxlen + 1];        
+    memcpy( p, data_byte_p_, length_i_ + 1 );      
+    delete[] data_byte_p_;
+    data_byte_p_ = p;          
+}
+// assignment.
+INLINE void 
+String_data::set( Byte const* byte_C, int length_i ) 
+{
+    OKW();
+
+    assert( byte_C && byte_C != data_byte_p_);
+
+    length_i_ = length_i;
+    remax( length_i_ );     // copies too
+    memcpy( data_byte_p_, byte_C, length_i_ );
+    data_byte_p_[ length_i_ ] = 0;
+}
+
+INLINE
+void 
+String_data::set( char const* ch_C ) 
+{
+    set( (Byte const*)ch_C, strlen( ch_C ) );
+}
+
+
+/// concatenation.
+INLINE void 
+String_data::append( Byte const* byte_C, int length_i ) 
+{
+    OK();
+    OKW();
+    int old_i = length_i_;
+    
+    length_i_ += length_i;
+    remax( length_i_ );
+    memcpy( data_byte_p_ + old_i, byte_C, length_i );  
+    data_byte_p_[ length_i_ ] = 0;
+}
+
+INLINE
+void 
+String_data::operator += ( char const* ch_C ) 
+{
+    append( (Byte const*)ch_C, strlen( ch_C ) );
+}
+
+
+
+INLINE
+char const*
+String_data::ch_C() const
+{
+    return (char const*)data_byte_p_; 
+}
+INLINE char* 
+String_data::ch_l() 
+{ 
+    return (char*)data_byte_p_; 
+}
+
+INLINE Byte const*
+String_data::byte_C() const 
+{ 
+    return data_byte_p_; 
+}
+
+INLINE Byte* 
+String_data::byte_l() 
+{
+    OKW();
+    return data_byte_p_;
+}
+
+INLINE
+void 
+String_data::trunc(int j) 
+{
+    OKW(); 
+    assert(j >= 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.icc b/flower/include/string-handle.icc
new file mode 100644 (file)
index 0000000..63b2ab3
--- /dev/null
@@ -0,0 +1,156 @@
+/* -*-c++-*-
+   
+  stringhandle.inl -- implement String_handle
+
+  source file of Flower lib
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef STRINGHANDLE_INL
+#define STRINGHANDLE_INL
+
+#include <assert.h>
+#include <memory.h>
+
+#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() const 
+{
+    return data->byte_C();
+}
+
+INLINE char const* 
+String_handle::ch_C() const 
+{
+    return (char const*)data->byte_C();
+}
+
+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()
+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, int length_i ) 
+{
+    copy();
+    data->append( byte_C, length_i );
+}
+                          
+INLINE void 
+String_handle::set( Byte const* byte_C, int length_i ) 
+{
+    copy();
+    data->set( byte_C, 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