+pl 28
+ - String::bool ()
+ - GNU indentation.
+
pl 27
- naming: macros are MACROS
MAJOR_VERSION = 1
MINOR_VERSION = 1
-PATCH_LEVEL = 27
+PATCH_LEVEL = 28
# use to send patches, always empty for released version:
MY_PATCH_LEVEL = # include separator: "-1" or ".a"
#
*/
template<class K, class V>
struct Assoc_ent_ {
- bool free;
- K key;
- V val;
+ bool free;
+ K key;
+ V val;
};
*/
template<class K, class V>
struct Assoc {
- Array< Assoc_ent_<K,V> > arr;
+ Array< Assoc_ent_<K,V> > arr;
- /* ************** */
+ /* ************** */
- int find (K key) const {
- for (int i = 0; i < arr.size(); i++) {
- if (!arr[i].free && key == arr[i].key)
- return i;
- }
- return -1;
+ int find (K key) const {
+ for (int i = 0; i < arr.size(); i++) {
+ if (!arr[i].free && key == arr[i].key)
+ return i;
}
- int find_creat (K key) {
- int free = -1;
- for (int i = 0; i < arr.size(); i++) {
- if (key == arr[i].key) {
- return i;
- } else if (arr[i].free) {
- free = i;
- }
- }
- if (free >= 0){
- arr[free].free = false;
- arr[free].key = key;
- return free;
- }
-
- Assoc_ent_<K,V> ae;
- ae.free = false;
- ae.key = key;
- arr.push (ae);
- return arr.size() -1;
- }
-public:
- bool elt_b (K key) const {
- return find (key) >= 0;
- }
- void del (K key) {
- assert (elt_b (key));
- int i= find (key);
- arr[i].free = true;
- }
- void
- add (K key, V val) {
- int i = find_creat (key);
- arr[i].val = val;
+ return -1;
+ }
+ int find_creat (K key) {
+ int free = -1;
+ for (int i = 0; i < arr.size(); i++) {
+ if (key == arr[i].key) {
+ return i;
+ } else if (arr[i].free) {
+ free = i;
+ }
}
- V& elem (K key) {
- return arr[find_creat (key)].val;
- }
- V& operator[](K key) {
- return elem (key);
- }
- V const & operator[](K key) const {
- return elem (key);
- }
- V const & elem (K key) const {
- assert (elt_b (key));
- return arr[find (key)].val;
+ if (free >= 0){
+ arr[free].free = false;
+ arr[free].key = key;
+ return free;
}
+
+ Assoc_ent_<K,V> ae;
+ ae.free = false;
+ ae.key = key;
+ arr.push (ae);
+ return arr.size() -1;
+ }
+public:
+ bool elt_b (K key) const {
+ return find (key) >= 0;
+ }
+ void del (K key) {
+ assert (elt_b (key));
+ int i= find (key);
+ arr[i].free = true;
+ }
+ void
+ add (K key, V val) {
+ int i = find_creat (key);
+ arr[i].val = val;
+ }
+ V& elem (K key) {
+ return arr[find_creat (key)].val;
+ }
+ V& operator[](K key) {
+ return elem (key);
+ }
+ V const & operator[](K key) const {
+ return elem (key);
+ }
+ V const & elem (K key) const {
+ assert (elt_b (key));
+ return arr[find (key)].val;
+ }
};
#endif
*/
struct Choleski_decomposition {
- /// lower triangle of Choleski decomposition
- Matrix L;
+ /// lower triangle of Choleski decomposition
+ Matrix L;
- /// diagonal
- Vector D;
+ /// diagonal
+ Vector D;
- /** Create decomposition of P.
+ /** Create decomposition of P.
PRE
P needs to be symmetric positive definite
*/
- Choleski_decomposition (Matrix const &P);
+ Choleski_decomposition (Matrix const &P);
- /**
+ /**
solve Px = rhs
*/
- Vector solve (Vector rhs) const;
- void solve (Vector &dest, Vector const &rhs) const;
- Vector operator * (Vector rhs) const { return solve (rhs); }
+ Vector solve (Vector rhs) const;
+ void solve (Vector &dest, Vector const &rhs) const;
+ Vector operator * (Vector rhs) const { return solve (rhs); }
/**
return the inverse of the matrix P.
*/
- Matrix inverse() const;
- /**
+ Matrix inverse() const;
+ /**
return P, calc'ed from L and D
*/
- Matrix original() const;
+ Matrix original() const;
private:
- void full_matrix_solve (Vector &,Vector const&) const;
- void band_matrix_solve (Vector &, Vector const&) const;
- void full_matrix_decompose (Matrix const & P);
- void band_matrix_decompose (Matrix const &P);
+ void full_matrix_solve (Vector &,Vector const&) const;
+ void band_matrix_solve (Vector &, Vector const&) const;
+ void full_matrix_decompose (Matrix const & P);
+ void band_matrix_decompose (Matrix const &P);
};
#endif
template<class T>
class Cursor
{
- public:
- /** create cursor, set at top. The const part isn't true, actually, #list#
- surely isn't const, but I get tired of the warning messages. */
- Cursor (const List<T>& list, Link<T>* pointer = 0);
- /**
- Create an invalid cursor (pointing to nothing, associated with no list.)
- */
- Cursor();
- Cursor (const Cursor<T>& cursor);
-
- T& thing();
-
- /// return current T
- T& operator *() { return thing(); }
- operator T() { return thing(); }
- Cursor<T> operator =( const Cursor<T>& c);
-
- /// make cursor with #no# items back
- Cursor<T> operator -( int no) const;
-
- /// make cursor with #no# items further
- Cursor<T> operator +( int no) const;
- int operator -(Cursor<T> op) const;
- Cursor<T> operator -=(int);
- Cursor<T> operator +=(int);
- /// move one down
- void next();
- /// move one up.
- void previous();
- /// return current and move one down
- Cursor<T> operator ++( int);
+public:
+ /** create cursor, set at top. The const part isn't true, actually, #list#
+ surely isn't const, but I get tired of the warning messages. */
+ Cursor (const List<T>& list, Link<T>* pointer = 0);
+ /**
+ Create an invalid cursor (pointing to nothing, associated with no list.)
+ */
+ Cursor();
+ Cursor (const Cursor<T>& cursor);
+
+ T& thing();
+
+ /// return current T
+ T& operator *() { return thing(); }
+ operator T() { return thing(); }
+ Cursor<T> operator =( const Cursor<T>& c);
+
+ /// make cursor with #no# items back
+ Cursor<T> operator -( int no) const;
+
+ /// make cursor with #no# items further
+ Cursor<T> operator +( int no) const;
+ int operator -(Cursor<T> op) const;
+ Cursor<T> operator -=(int);
+ Cursor<T> operator +=(int);
+ /// move one down
+ void next();
+ /// move one up.
+ void previous();
+ /// return current and move one down
+ Cursor<T> operator ++( int);
- /// return current and move one up
- Cursor<T> operator --( int);
+ /// return current and move one up
+ Cursor<T> operator --( int);
- /// point to link?
- bool ok() const;
+ /// point to link?
+ bool ok() const;
- /// ++ items left?
- bool forward() const;
+ /// ++ items left?
+ bool forward() const;
- /// -- items left?
- bool backward() const;
+ /// -- items left?
+ bool backward() const;
- /** put (copy) after me in List.
- analogously to editor. ok() interpreted as at end
- of line.
+ /** put (copy) after me in List.
+ analogously to editor. ok() interpreted as at end
+ of line.
- PRE: !ok, POST: added to bottom()
+ PRE: !ok, POST: added to bottom()
- PRE: ok, POST: added after me
+ PRE: ok, POST: added after me
- cursor points to same object, cursor.next() is newly added
- object.
- */
- void add (T const & thing);
+ cursor points to same object, cursor.next() is newly added
+ object.
+ */
+ void add (T const & thing);
- /** put (copy) before me in List.
- analogously to editor. ok() interpreted as at begin of
- line.
+ /** put (copy) before me in List.
+ analogously to editor. ok() interpreted as at begin of
+ line.
- PRE: !ok, POST: add to top()
+ PRE: !ok, POST: add to top()
- PRE: ok, POST: add before me
+ PRE: ok, POST: add before me
- cursor points to same object, cursor.previous()
- is newly inserted object.
- */
+ cursor points to same object, cursor.previous()
+ is newly inserted object.
+ */
- void insert (T const & thing);
- ///
- void backspace();
+ void insert (T const & thing);
+ ///
+ void backspace();
- ///
- void del();
+ ///
+ void del();
- /// access the list this came from
- List<T>& list() const ;
- Link<T>* pointer();
- static int compare (Cursor<T> a,Cursor<T>b) { return a-b; }
+ /// access the list this came from
+ List<T>& list() const ;
+ Link<T>* pointer();
+ static int compare (Cursor<T> a,Cursor<T>b) { return a-b; }
private:
- List<T>& list_;
- Link<T>* pointer_;
+ List<T>& list_;
+ Link<T>* pointer_;
};
class Data_file : private Text_stream
{
- public:
- bool rawmode;
+public:
+ bool rawmode;
- Text_stream::line;
- Text_stream::eof;
- Text_stream::get_name;
+ Text_stream::line;
+ Text_stream::eof;
+ Text_stream::get_name;
- char data_get();
- void data_unget (char c) {
- unget (c);
- }
+ char data_get();
+ void data_unget (char c) {
+ unget (c);
+ }
- /// read line, eat #\n#
- String get_line();
+ /// read line, eat #\n#
+ String get_line();
- /// read a word till next space, leave space. Also does quotes
- String get_word();
-
- /// gobble horizontal white stuff.
- void gobble_white();
-
- /// gobble empty stuff before first field.
- void gobble_leading_white();
- Data_file (String s) : Text_stream (s) {
- //*mlog << "(" << s << flush;
- rawmode= false;
- }
-
- ~Data_file() {
- // *mlog << ")"<<flush;
- }
-
- warning (String s) {
- message ("warning: " + s);
- }
- error (String s){
- message (s);
- exit (1);
- }
+ /// read a word till next space, leave space. Also does quotes
+ String get_word();
+
+ /// gobble horizontal white stuff.
+ void gobble_white();
+
+ /// gobble empty stuff before first field.
+ void gobble_leading_white();
+ Data_file (String s) : Text_stream (s) {
+ //*mlog << "(" << s << flush;
+ rawmode= false;
+ }
+
+ ~Data_file() {
+ // *mlog << ")"<<flush;
+ }
+
+ warning (String s) {
+ message ("warning: " + s);
+ }
+ error (String s){
+ message (s);
+ exit (1);
+ }
};
#endif // DATAFILE_HH
*/
class Diagonal_storage : public Matrix_storage {
- Full_storage band_;
+ Full_storage band_;
public:
- void set_band_size (int b);
- int band_size_i() const;
+ void set_band_size (int b);
+ int band_size_i() const;
- void assert_valid (int i, int j) const;
- bool band_elt_b (int,int) const;
- void resize_dim (int);
+ void assert_valid (int i, int j) const;
+ bool band_elt_b (int,int) const;
+ void resize_dim (int);
- virtual void resize_rows (int d) { resize_dim (d); }
- virtual void resize_cols (int d) { resize_dim (d); }
- virtual int dim() const;
+ virtual void resize_rows (int d) { resize_dim (d); }
+ virtual void resize_cols (int d) { resize_dim (d); }
+ virtual int dim() const;
- virtual int rows() const ;
- virtual int cols() const ;
+ virtual int rows() const ;
+ virtual int cols() const ;
- virtual void resize (int i, int j);
- virtual void resize (int i);
+ virtual void resize (int i, int j);
+ virtual void resize (int i);
- virtual Real& elem (int i,int j);
- virtual Real elem (int i, int j) const;
- Diagonal_storage (Matrix_storage* , int band_i);
- Diagonal_storage();
- void OK() const;
+ virtual Real& elem (int i,int j);
+ virtual Real elem (int i, int j) const;
+ Diagonal_storage (Matrix_storage* , int band_i);
+ Diagonal_storage();
+ void OK() const;
- virtual void insert_row (int k);
- virtual void delete_row (int k);
- virtual void delete_column (int k);
+ virtual void insert_row (int k);
+ virtual void delete_row (int k);
+ virtual void delete_column (int k);
- ~Diagonal_storage();
- virtual bool mult_ok (int i, int j) const;
- virtual void mult_next (int &i, int &j) const ;
- virtual bool trans_ok (int i, int j) const;
- virtual void trans_next (int &i, int &j) const;
- DECLARE_VIRTUAL_COPY_CONS(Diagonal_storage, Matrix_storage);
- DECLARE_MY_RUNTIME_TYPEINFO;
- virtual bool try_right_multiply (Matrix_storage * dest, Matrix_storage const *) const;
+ ~Diagonal_storage();
+ virtual bool mult_ok (int i, int j) const;
+ virtual void mult_next (int &i, int &j) const ;
+ virtual bool trans_ok (int i, int j) const;
+ virtual void trans_next (int &i, int &j) const;
+ DECLARE_VIRTUAL_COPY_CONS(Diagonal_storage, Matrix_storage);
+ DECLARE_MY_RUNTIME_TYPEINFO;
+ virtual bool try_right_multiply (Matrix_storage * dest, Matrix_storage const *) const;
};
#endif // DIAGONAL_STORAGE_HH
Class to handle two-sided connections between nodes (the Dependencies)
*/
class Directed_graph_node {
- Link_array<Directed_graph_node>edge_out_l_arr_;
- /// targets
- Link_array<Directed_graph_node> edge_in_l_arr_;
+ Link_array<Directed_graph_node>edge_out_l_arr_;
+ /// targets
+ Link_array<Directed_graph_node> edge_in_l_arr_;
public:
- /** remove i-th edge_out (and exactly one ref to me in the edge_out)
- */
- void remove_edge_out_idx (int i);
- void copy_edges_out (Directed_graph_node const&);
- bool linked_b() const;
- void unlink();
- void junk_links();
- void add (Directed_graph_node*);
- void remove_edge_in (Directed_graph_node *);
- void remove_edge_out (Directed_graph_node*);
- bool contains_b (Directed_graph_node const*) const;
-
- Directed_graph_node (Directed_graph_node const &);
- void OK() const;
- Directed_graph_node();
-
- ~Directed_graph_node();
+ /** remove i-th edge_out (and exactly one ref to me in the edge_out)
+ */
+ void remove_edge_out_idx (int i);
+ void copy_edges_out (Directed_graph_node const&);
+ bool linked_b() const;
+ void unlink();
+ void junk_links();
+ void add (Directed_graph_node*);
+ void remove_edge_in (Directed_graph_node *);
+ void remove_edge_out (Directed_graph_node*);
+ bool contains_b (Directed_graph_node const*) const;
+
+ Directed_graph_node (Directed_graph_node const &);
+ void OK() const;
+ Directed_graph_node();
+
+ ~Directed_graph_node();
- /**
- ensure that no edge_out exists doubly.
- */
- void uniq();
- Link_array<Directed_graph_node> const& get_out_edge_arr() const;
- Link_array<Directed_graph_node> const& get_in_edge_arr() const;
+ /**
+ ensure that no edge_out exists doubly.
+ */
+ void uniq();
+ Link_array<Directed_graph_node> const& get_out_edge_arr() const;
+ Link_array<Directed_graph_node> const& get_in_edge_arr() const;
};
#endif // DEPENDENCY_HH
/// simplest matrix storage. refer to its baseclass for the doco.
class Full_storage : public Matrix_storage
{
- /// height, width
- int height_i_,width_i_;
- /// maxima.
- int max_height_i_, max_width_i_;
+ /// height, width
+ int height_i_,width_i_;
+ /// maxima.
+ int max_height_i_, max_width_i_;
/// the storage
- Real** els_p_p_;
+ Real** els_p_p_;
- void
- init() ;
+ void
+ init() ;
- bool valid (int i, int j) const ;
+ bool valid (int i, int j) const ;
- void resize_rows (int);
- void resize_cols (int);
+ void resize_rows (int);
+ void resize_cols (int);
public:
- virtual int rows() const;
- virtual int cols() const ;
+ virtual int rows() const;
+ virtual int cols() const ;
- virtual void resize (int i, int j);
- virtual void resize (int i);
- virtual Real& elem (int i,int j);
- virtual Real elem (int i, int j) const ;
- int dim() const;
- Full_storage (Matrix_storage*);
- Full_storage();
- Full_storage (int i, int j);
- Full_storage (Full_storage const&);
- Full_storage (int i);
- void OK() const;
- void operator=(Full_storage const &);
+ virtual void resize (int i, int j);
+ virtual void resize (int i);
+ virtual Real& elem (int i,int j);
+ virtual Real elem (int i, int j) const ;
+ int dim() const;
+ Full_storage (Matrix_storage*);
+ Full_storage();
+ Full_storage (int i, int j);
+ Full_storage (Full_storage const&);
+ Full_storage (int i);
+ void OK() const;
+ void operator=(Full_storage const &);
- virtual void insert_row (int k);
- virtual void delete_row (int k);
- virtual void delete_column (int k);
+ virtual void insert_row (int k);
+ virtual void delete_row (int k);
+ virtual void delete_column (int k);
- ~Full_storage();
- virtual bool mult_ok (int i, int j) const;
- virtual void mult_next (int &i, int &j) const ;
- virtual bool trans_ok (int i, int j) const;
- virtual void trans_next (int &i, int &j) const;
- DECLARE_VIRTUAL_COPY_CONS(Full_storage,Matrix_storage);
- DECLARE_MY_RUNTIME_TYPEINFO;
- virtual bool try_right_multiply (Matrix_storage * dest, Matrix_storage const *) const;
+ ~Full_storage();
+ virtual bool mult_ok (int i, int j) const;
+ virtual void mult_next (int &i, int &j) const ;
+ virtual bool trans_ok (int i, int j) const;
+ virtual void trans_next (int &i, int &j) const;
+ DECLARE_VIRTUAL_COPY_CONS(Full_storage,Matrix_storage);
+ DECLARE_MY_RUNTIME_TYPEINFO;
+ virtual bool try_right_multiply (Matrix_storage * dest, Matrix_storage const *) const;
};
#endif // FULL_STORAGE_HH
Full_storage::valid (int i, int j) const
{
return (i>=0 && i < height_i_)
- && (j < width_i_ && j >=0);
+ && (j < width_i_ && j >=0);
}
*/
template<class T>
struct Interval_t {
- T left, right;
+ T left, right;
- /* ************** */
+ /* ************** */
- static T infinity() ;
+ static T infinity() ;
- T center() { return (left + right) / T(2);}
- void translate (T t) {
- left += t;
- right += t;
+ T center() { return (left + right) / T(2);}
+ void translate (T t) {
+ left += t;
+ right += t;
+ }
+ T& idx (int j) {
+ if (j==-1)
+ return left;
+ else if (j==1)
+ return right;
+ else
+ assert (false);
+ return left;
+ }
+ T& operator[](int j) {
+ return idx (j);
+ }
+ T operator[](int j) const {
+ return ((Interval_t<T> *)this)->idx (j);
+ }
+ T &max() { return right;}
+ T max() const { return right;}
+ T min() const{ return left; }
+ T &min(){ return left; }
+ /**
+ PRE
+ *this and h are comparable
+ */
+ void unite (Interval_t<T> h);
+ void intersect (Interval_t<T> h);
+
+ T length() const;
+ void set_empty() ;
+ bool empty_b() const { return left > right; }
+ bool contains_b (Interval_t<T> const&) const;
+ Interval_t() {
+ set_empty();
+ }
+ Interval_t (T m, T M) {
+ left =m;
+ right = M;
+ }
+ Interval_t<T> &operator += (T r) {
+ left += r;
+ right +=r;
+ return *this;
+ }
+ Interval_t<T> &operator *=(T r) {
+ left *= r;
+ right *= r;
+ if (r < T(0)) {
+ T t = left;
+ left = right;
+ right = t;
}
- T& idx (int j) {
- if (j==-1)
- return left;
- else if (j==1)
- return right;
- else
- assert (false);
- return left;
- }
- T& operator[](int j) {
- return idx (j);
- }
- T operator[](int j) const {
- return ((Interval_t<T> *)this)->idx (j);
- }
- T &max() { return right;}
- T max() const { return right;}
- T min() const{ return left; }
- T &min(){ return left; }
- /**
- PRE
- *this and h are comparable
- */
- void unite (Interval_t<T> h);
- void intersect (Interval_t<T> h);
-
- T length() const;
- void set_empty() ;
- bool empty_b() const { return left > right; }
- bool contains_b (Interval_t<T> const&) const;
- Interval_t() {
- set_empty();
- }
- Interval_t (T m, T M) {
- left =m;
- right = M;
- }
- Interval_t<T> &operator += (T r) {
- left += r;
- right +=r;
- return *this;
- }
- Interval_t<T> &operator *=(T r) {
- left *= r;
- right *= r;
- if (r < T(0)) {
- T t = left;
- left = right;
- right = t;
- }
- return *this;
- }
- String str() const;
- bool elt_b (T r);
+ return *this;
+ }
+ String str() const;
+ bool elt_b (T r);
};
inline Interval_t<T>
intersection (Interval_t<T> a, Interval_t<T> const&b)
{
- a.intersect (b);
- return a;
+ a.intersect (b);
+ return a;
}
inline
Interval_t<T> operator +(T a,Interval_t<T> i)
{
- i += a;
- return i;
+ i += a;
+ return i;
}
template<class T>
inline
Interval_t<T> operator +(Interval_t<T> i,T a){
- return a+i;
+ return a+i;
}
template<class T>
inline
Interval_t<T> operator *(T a,Interval_t<T> i)
{
- i *= a;
- return i;
+ i *= a;
+ return i;
}
template<class T>
inline
Interval_t<T> operator *(Interval_t<T> i,T a){
- return a*i;
+ return a*i;
}
typedef Interval_t<Real> Interval;
a struct this for initialising the commandline options.
*/
struct Long_option_init {
- bool take_arg;
- char const * longname;
- char shortname;
+ bool take_arg;
+ char const * longname;
+ char shortname;
- void printon (ostream &errorout) const ;
+ void printon (ostream &errorout) const ;
};
*/
class Getopt_long {
- /// the option info.
- const Long_option_init *option_a_;
- int table_len_i_;
+ /// the option info.
+ const Long_option_init *option_a_;
+ int table_len_i_;
- /// if doing short option, arg_value_ch_a_a_[optind][optindind] is processed next.
- int argument_index_i_;
+ /// if doing short option, arg_value_ch_a_a_[optind][optindind] is processed next.
+ int argument_index_i_;
- /// the option found
- const Long_option_init *found_option_l_;
+ /// the option found
+ const Long_option_init *found_option_l_;
public:
- /** errorcodes: no error, argument expected, no argument expected,
- unknown option, illegal argument (eg. int expected). */
- enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
- E_ILLEGALARG } ;
+ /** errorcodes: no error, argument expected, no argument expected,
+ unknown option, illegal argument (eg. int expected). */
+ enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
+ E_ILLEGALARG } ;
- /// argument. Set to 0 if not present
- char const * optional_argument_ch_C_;
+ /// argument. Set to 0 if not present
+ char const * optional_argument_ch_C_;
- /// current error status
- Errorcod error_;
+ /// current error status
+ Errorcod error_;
- /// arg_value_ch_a_a_[array_index_i_] will be processed next.
- int array_index_i_;
+ /// arg_value_ch_a_a_[array_index_i_] will be processed next.
+ int array_index_i_;
- /// the arguments
- char **arg_value_ch_a_a_;
+ /// the arguments
+ char **arg_value_ch_a_a_;
- /// the arg. count
- int argument_count_i_;
+ /// the arg. count
+ int argument_count_i_;
- ostream *error_ostream_l_;
+ ostream *error_ostream_l_;
public:
- /// get ready for processing next error.
- void next();
- const Long_option_init *parselong();
- const Long_option_init *parseshort();
- void OK() const;
- bool ok() const;
+ /// get ready for processing next error.
+ void next();
+ const Long_option_init *parselong();
+ const Long_option_init *parseshort();
+ void OK() const;
+ bool ok() const;
- /// report an error and abort
- void report (Errorcod c);
+ /// report an error and abort
+ void report (Errorcod c);
- /// return an integer (with err. detect)
- long argument_to_i();
+ /// return an integer (with err. detect)
+ long argument_to_i();
- /**
- What to do with errors.
- report messages on #*os#, and abort.
- if #os# is null, then do not report nor abort, just set #error#
- */
+ /**
+ What to do with errors.
+ report messages on #*os#, and abort.
+ if #os# is null, then do not report nor abort, just set #error#
+ */
- void seterror (ostream *os);
+ void seterror (ostream *os);
- /// construct: pass arguments and option info.
- Getopt_long (int c, char **v, Long_option_init *lo);
+ /// construct: pass arguments and option info.
+ Getopt_long (int c, char **v, Long_option_init *lo);
- /** get the next option.
- @return pointer to next option found.
- 0 if error occurred, or next argument is no option.
- */
- const Long_option_init *operator()();
+ /** get the next option.
+ @return pointer to next option found.
+ 0 if error occurred, or next argument is no option.
+ */
+ const Long_option_init *operator()();
- char const *current_arg();
- char const * get_next_arg();
+ char const *current_arg();
+ char const * get_next_arg();
};
#endif
template<class T>
class List
{
- public:
- List (List const&src);
+public:
+ List (List const&src);
- /// construct empty list
- List();
- virtual ~List();
+ /// construct empty list
+ List();
+ virtual ~List();
- int size() const;
+ int size() const;
- Cursor<T> bottom() const; // const sucks.
- Cursor<T> top() const;
+ Cursor<T> bottom() const; // const sucks.
+ Cursor<T> top() const;
- void OK() const; // check list
- void junk_links();
+ void OK() const; // check list
+ void junk_links();
- protected:
- friend class Cursor<T>;
- friend class Link<T>;
+protected:
+ friend class Cursor<T>;
+ friend class Link<T>;
- void concatenate (List<T> const &s);
+ void concatenate (List<T> const &s);
- /** make *this empty.
+ /** make *this empty.
- POST:
- size == 0
+ POST:
+ size == 0
- WARNING:
- contents lost, and not deleted.
- */
- void set_empty();
+ WARNING:
+ contents lost, and not deleted.
+ */
+ void set_empty();
- void add (T const & thing, Cursor<T> &after_me);
+ void add (T const & thing, Cursor<T> &after_me);
- /// put thing before #before_me#
- void insert (T const & thing, Cursor<T> &before_me);
+ /// put thing before #before_me#
+ void insert (T const & thing, Cursor<T> &before_me);
- /** Remove link pointed to by me. Destructor of contents called
- (nop for pointers)
+ /** Remove link pointed to by me. Destructor of contents called
+ (nop for pointers)
- POST
- none;
+ POST
+ none;
- WARNING: do not use #me# after calling
- */
- void remove (Cursor<T> me);
+ WARNING: do not use #me# after calling
+ */
+ void remove (Cursor<T> me);
- /* ************** */
+ /* ************** */
- int size_;
- Link<T>* top_;
- Link<T>* bottom_;
+ int size_;
+ Link<T>* top_;
+ Link<T>* bottom_;
};
#include "list.icc"
{
if ( me.ok())
{
- Link<T> *lp = me.pointer();
- lp->remove (*this);
- delete lp;
+ Link<T> *lp = me.pointer();
+ lp->remove (*this);
+ delete lp;
size_--;
}
}
class Matrix {
- friend Matrix operator *(Matrix const &m1, Matrix const &m2);
+ friend Matrix operator *(Matrix const &m1, Matrix const &m2);
protected:
- Matrix_storage *dat;
- void set (Matrix_storage*);
- Matrix (Matrix_storage*);
+ Matrix_storage *dat;
+ void set (Matrix_storage*);
+ Matrix (Matrix_storage*);
public:
- void OK() const { dat->OK(); }
- int cols() const { return dat->cols (); }
- int rows() const { return dat->rows (); }
+ void OK() const { dat->OK(); }
+ int cols() const { return dat->cols (); }
+ int rows() const { return dat->rows (); }
- /** return the size of a matrix.
- PRE
- the matrix needs to be square.
+ /** return the size of a matrix.
+ PRE
+ the matrix needs to be square.
*/
- int dim() const;
+ int dim() const;
- /**
- the band size of the matrix.
- @ret
-
- 0 <= band_i() <= dim
- */
- int band_i() const;
- bool band_b() const;
- void set_full() const;
- void try_set_band() const;
- ~Matrix() { delete dat; }
-
- /// set entries to r
- void fill (Real r);
-
- /// set diagonal to d
- void set_diag (Real d);
-
- void set_diag (Vector d);
- /// set unit matrix
- void unit() { set_diag (1.0); }
-
- void operator+=(Matrix const &m);
- void operator-=(Matrix const &m);
- void operator*=(Real a);
- void operator/=(Real a) { (*this) *= 1/a; }
+ /**
+ the band size of the matrix.
+ @ret
+
+ 0 <= band_i() <= dim
+ */
+ int band_i() const;
+ bool band_b() const;
+ void set_full() const;
+ void try_set_band() const;
+ ~Matrix() { delete dat; }
+
+ /// set entries to r
+ void fill (Real r);
+
+ /// set diagonal to d
+ void set_diag (Real d);
+
+ void set_diag (Vector d);
+ /// set unit matrix
+ void unit() { set_diag (1.0); }
+
+ void operator+=(Matrix const &m);
+ void operator-=(Matrix const &m);
+ void operator*=(Real a);
+ void operator/=(Real a) { (*this) *= 1/a; }
- /** add a row.
- add a row to the matrix before row k
+ /** add a row.
+ add a row to the matrix before row k
- PRE
- v.dim() == cols ()
- 0 <= k <= rows()
+ PRE
+ v.dim() == cols ()
+ 0 <= k <= rows()
*/
- void insert_row (Vector v,int k);
- /** .
- delete a row from this matrix.
+ void insert_row (Vector v,int k);
+ /** .
+ delete a row from this matrix.
- PRE
- 0 <= k < rows();
+ PRE
+ 0 <= k < rows();
*/
- void delete_row (int k) { dat->delete_row (k); }
- void delete_column (int k) { dat->delete_column (k); }
+ void delete_row (int k) { dat->delete_row (k); }
+ void delete_column (int k) { dat->delete_column (k); }
- /**
- square n matrix, initialised to null
+ /**
+ square n matrix, initialised to null
*/
- Matrix (int n);
+ Matrix (int n);
- /**
- n x m matrix, init to 0
+ /**
+ n x m matrix, init to 0
*/
- Matrix (int n, int m);
- Matrix (Matrix const &m);
+ Matrix (int n, int m);
+ Matrix (Matrix const &m);
- /// dyadic product: v * w.transpose
- Matrix (Vector v, Vector w);
- void operator=(Matrix const &m);
+ /// dyadic product: v * w.transpose
+ Matrix (Vector v, Vector w);
+ void operator=(Matrix const &m);
- /// access an element
- Real operator()(int i,int j) const { return dat->elem (i,j); }
+ /// access an element
+ Real operator()(int i,int j) const { return dat->elem (i,j); }
- /// access an element
- Real &operator()(int i, int j) { return dat->elem (i,j); }
+ /// access an element
+ Real &operator()(int i, int j) { return dat->elem (i,j); }
- /// Matrix multiply with vec (from right)
- Vector operator *(Vector const &v) const;
+ /// Matrix multiply with vec (from right)
+ Vector operator *(Vector const &v) const;
- /// set this to m1*m2.
- void set_product (Matrix const &m1, Matrix const &m2);
+ /// set this to m1*m2.
+ void set_product (Matrix const &m1, Matrix const &m2);
- Vector left_multiply (Vector const &) const;
+ Vector left_multiply (Vector const &) const;
- Matrix operator-() const;
+ Matrix operator-() const;
- /// transpose this.
- void transpose();
+ /// transpose this.
+ void transpose();
- /// return a transposed copy.
- Matrix transposed() const ;
+ /// return a transposed copy.
+ Matrix transposed() const ;
- Real norm() const;
- /** swap.
- PRE
- 0 <= c1,c2 < cols()
+ Real norm() const;
+ /** swap.
+ PRE
+ 0 <= c1,c2 < cols()
*/
- void swap_columns (int c1, int c2);
+ void swap_columns (int c1, int c2);
- /** swap.
- PRE
- 0 <= c1,c2 < rows()
+ /** swap.
+ PRE
+ 0 <= c1,c2 < rows()
*/
- void swap_rows (int c1, int c2);
+ void swap_rows (int c1, int c2);
- Vector row (int) const;
- Vector col (int) const;
+ Vector row (int) const;
+ Vector col (int) const;
- operator String() const;
- void print() const;
+ operator String() const;
+ void print() const;
};
inline Vector
Matrix operator /(Matrix const &m1,Real a);
inline Matrix operator -(Matrix m1,const Matrix m2)
{
- m1 -= m2;
- return m1;
+ m1 -= m2;
+ return m1;
}
inline Matrix operator +(Matrix m1,const Matrix m2)
{
- m1 += m2;
- return m1;
+ m1 += m2;
+ return m1;
}
#endif
*/
template<class T>
class PCursor : private Cursor<void *> {
- friend class Pointer_list<T>;
+ friend class Pointer_list<T>;
- /// delete contents
- void junk();
+ /// delete contents
+ void junk();
public:
- Cursor<void*>::ok;
- Cursor<void*>::del;
- Cursor<void*>::backspace;
- Cursor<void*>::next;
- Cursor<void*>::previous;
+ Cursor<void*>::ok;
+ Cursor<void*>::del;
+ Cursor<void*>::backspace;
+ Cursor<void*>::next;
+ Cursor<void*>::previous;
- T remove_p() {
- T p = ptr();
- Cursor<void*>::del();
- return p;
- }
- T remove_prev_p() {
- assert (ok());
- (*this)--;
- return remove_p();
- }
+ T remove_p() {
+ T p = ptr();
+ Cursor<void*>::del();
+ return p;
+ }
+ T remove_prev_p() {
+ assert (ok());
+ (*this)--;
+ return remove_p();
+ }
- Link_list<T> &list() { return (Link_list<T>&)Cursor<void*>::list (); }
- PCursor<T> operator++(int) { return Cursor<void*>::operator++(0);}
- PCursor<T> operator--(int) { return Cursor<void*>::operator--(0); }
- PCursor<T> operator+=(int i) { return Cursor<void*>::operator+=(i);}
- PCursor<T> operator-=(int i) { return Cursor<void*>::operator-=(i); }
- PCursor<T> operator -(int no) const { return Cursor<void*>::operator-(no);}
- int operator -(PCursor<T> op) const { return Cursor<void*>::operator-(op);}
- PCursor<T> operator +( int no) const {return Cursor<void*>::operator+(no);} PCursor (const Link_list<T> & l) : Cursor<void*> (l) {}
- PCursor() : Cursor<void*> () {}
- PCursor (const Cursor<void*>& cursor) : Cursor<void*>(cursor) { }
- void* vptr() const { return *((Cursor<void*> &) *this); }
+ Link_list<T> &list() { return (Link_list<T>&)Cursor<void*>::list (); }
+ PCursor<T> operator++(int) { return Cursor<void*>::operator++(0);}
+ PCursor<T> operator--(int) { return Cursor<void*>::operator--(0); }
+ PCursor<T> operator+=(int i) { return Cursor<void*>::operator+=(i);}
+ PCursor<T> operator-=(int i) { return Cursor<void*>::operator-=(i); }
+ PCursor<T> operator -(int no) const { return Cursor<void*>::operator-(no);}
+ int operator -(PCursor<T> op) const { return Cursor<void*>::operator-(op);}
+ PCursor<T> operator +( int no) const {return Cursor<void*>::operator+(no);} PCursor (const Link_list<T> & l) : Cursor<void*> (l) {}
+ PCursor() : Cursor<void*> () {}
+ PCursor (const Cursor<void*>& cursor) : Cursor<void*>(cursor) { }
+ void* vptr() const { return *((Cursor<void*> &) *this); }
- // should return T& ?
- T ptr() const { return (T) vptr (); }
- T operator ->() const { return ptr(); }
- operator T() { return ptr(); }
- T operator *() { return ptr(); }
- void add (T const & p) { Cursor<void*>::add ((void*) p); }
- void insert (T const & p) { Cursor<void*>::insert ((void*) p);}
- static int compare (PCursor<T> a,PCursor<T>b) {
- return Cursor<void*>::compare (a,b);
- }
+ // should return T& ?
+ T ptr() const { return (T) vptr (); }
+ T operator ->() const { return ptr(); }
+ operator T() { return ptr(); }
+ T operator *() { return ptr(); }
+ void add (T const & p) { Cursor<void*>::add ((void*) p); }
+ void insert (T const & p) { Cursor<void*>::insert ((void*) p);}
+ static int compare (PCursor<T> a,PCursor<T>b) {
+ return Cursor<void*>::compare (a,b);
+ }
};
template<class T>
class Link_list : public List<void *>
{
- public:
- PCursor<T> top() const{
- return PCursor<T> (List<void*>::top());
- }
- PCursor<T> bottom() const {
- return PCursor<T> (List<void*>::bottom());
- }
- PCursor<T> find (T) const;
- void concatenate (Link_list<T> const &s) { List<void*>::concatenate (s); }
-
- Link_list() {}
+public:
+ PCursor<T> top() const{
+ return PCursor<T> (List<void*>::top());
+ }
+ PCursor<T> bottom() const {
+ return PCursor<T> (List<void*>::bottom());
+ }
+ PCursor<T> find (T) const;
+ void concatenate (Link_list<T> const &s) { List<void*>::concatenate (s); }
+
+ Link_list() {}
};
/**
class Pointer_list : public Link_list<T> {
public:
- void junk();
- Pointer_list (Pointer_list const &) { set_empty(); }
- Pointer_list() { }
- ~Pointer_list() { junk (); }
+ void junk();
+ Pointer_list (Pointer_list const &) { set_empty(); }
+ Pointer_list() { }
+ ~Pointer_list() { junk (); }
};
#define Pointer_list__copy(T, to, from, op) \
- for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
- to.bottom().add (_pc_->op)\
- \
+for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
+to.bottom().add (_pc_->op)\
+\
template<class T>
OKW();
if (j > maxlen)
{
- delete data_byte_p_;
- maxlen = j;
- data_byte_p_ = new Byte[maxlen + 1];
+ delete data_byte_p_;
+ maxlen = j;
+ data_byte_p_ = new Byte[maxlen + 1];
- data_byte_p_[0] = 0;
- length_i_ = 0;
+ data_byte_p_[0] = 0;
+ length_i_ = 0;
}
}
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;
+ 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 bool
String_data::is_binary_bo() const
{
-// return !memchr (data_byte_p_, length_i_, 0);
+ // return !memchr (data_byte_p_, length_i_, 0);
return ( (int)strlen ((char const*)data_byte_p_) != length_i_ );
}
{
if (data->references !=1)
{
- String_data *newdata = new String_data (*data);
- down();
- up (newdata);
+ String_data *newdata = new String_data (*data);
+ down();
+ up (newdata);
}
}
String_handle::operator =(String_handle const &src)
{
if (this == &src)
- return;
+ return;
down();
up (src.data);
}
class String
{
protected:
- String_handle strh_;
+ String_handle strh_;
- bool null_terminated();
+ bool null_terminated();
public:
- /** init to empty string. This is needed because other
- constructors are provided.*/
- String() { }
- String (Rational);
+ /** init to empty string. This is needed because other
+ constructors are provided.*/
+ String() { }
+ String (Rational);
- /// String s = "abc";
- String (char const* source);
- String (Byte const* byte_C, int length_i);
+ /// String s = "abc";
+ String (char const* source);
+ String (Byte const* byte_C, int length_i);
- /// "ccccc"
- String (char c, int n = 1);
+ /// "ccccc"
+ String (char c, int n = 1);
- String (int i , char const *fmt=0);
- String ( double f , char const* fmt =0);
- /// 'true' or 'false'
- String (bool);
+ String (int i , char const *fmt=0);
+ String ( double f , char const* fmt =0);
+ /// 'true' or 'false'
+ String (bool);
- /// return a "new"-ed copy of contents
- Byte* copy_byte_p() const; // return a "new"-ed copy of contents
+ /// return a "new"-ed copy of contents
+ Byte* copy_byte_p() const; // return a "new"-ed copy of contents
- char const* ch_C() const;
- Byte const* byte_C() const;
- char* ch_l();
- Byte* byte_l();
+ char const* ch_C() const;
+ Byte const* byte_C() const;
+ char* ch_l();
+ Byte* byte_l();
- /// deprecated; use ch_C()
- operator char const*() const { return ch_C(); }
+ /// deprecated; use ch_C()
+ operator char const*() const { return ch_C(); }
- String &operator =( String const & source);
+ String &operator =( String const & source);
- /// concatenate s
- void operator += (char const* s) { strh_ += s; }
- void operator += (String s);
+ /// concatenate s
+ void operator += (char const* s) { strh_ += s; }
+ void operator += (String s);
- void append (String);
- void prepend (String);
+ operator bool ()
+ {
+ return length_i ();
+ }
+ void append (String);
+ void prepend (String);
- char operator []( int n) const { return strh_[n]; }
+ char operator []( int n) const { return strh_[n]; }
- /// return n leftmost chars
- String left_str (int n) const;
+ /// return n leftmost chars
+ String left_str (int n) const;
- /// return n rightmost chars
- String right_str (int n) const;
+ /// return n rightmost chars
+ String right_str (int n) const;
- /// return uppercase of *this
- String upper_str() const;
+ /// return uppercase of *this
+ String upper_str() const;
- /// return lowercase of *this
- String lower_str() const;
+ /// return lowercase of *this
+ String lower_str() const;
- /// return the "esrever" of *this
- String reversed_str() const;
+ /// return the "esrever" of *this
+ String reversed_str() const;
- /// return a piece starting at index_i (first char = index_i 0), length n
- String mid_str (int index_i, int n) const;
+ /// return a piece starting at index_i (first char = index_i 0), length n
+ String mid_str (int index_i, int n) const;
- /// cut out a middle piece, return remainder
- String nomid_str (int index_i, int n) const;
+ /// cut out a middle piece, return remainder
+ String nomid_str (int index_i, int n) const;
- /// signed comparison, analogous to memcmp;
- static int compare_i (String const & s1,const String& s2);
+ /// signed comparison, analogous to memcmp;
+ static int compare_i (String const & s1,const String& s2);
- /// index of rightmost c
- int index_last_i (char c) const;
+ /// index of rightmost c
+ int index_last_i (char c) const;
- /// index of rightmost element of string
- int index_last_i (char const* string) const;
+ /// index of rightmost element of string
+ int index_last_i (char const* string) const;
- int index_i (char c) const;
- int index_i (String) const;
- int index_any_i (String) const;
+ int index_i (char c) const;
+ int index_i (String) const;
+ int index_any_i (String) const;
- void to_upper();
- void to_lower();
- /// provide Stream output
- void print_on (ostream& os) const;
+ void to_upper();
+ void to_lower();
+ /// provide Stream output
+ void print_on (ostream& os) const;
- /// the length of the string
- int length_i() const;
+ /// the length of the string
+ int length_i() const;
- // ***** depreciated
- int len() const {
- return length_i();
- }
+ // ***** depreciated
+ int len() const {
+ return length_i();
+ }
- /// convert to an integer
- int value_i() const;
+ /// convert to an integer
+ int value_i() const;
- /// convert to a double
- double value_f() const;
+ /// convert to a double
+ double value_f() const;
};
#include "compare.hh"
// because char const* also has an operator ==, this is for safety:
inline bool operator==(String s1, char const* s2){
- return s1 == String (s2);
+ return s1 == String (s2);
}
inline bool operator==(char const* s1, String s2)
{
- return String (s1)==s2;
+ return String (s1)==s2;
}
inline bool operator!=(String s1, char const* s2 ) {
- return s1!=String (s2);
+ return s1!=String (s2);
}
inline bool operator!=(char const* s1,String s2) {
- return String (s2) !=s1;
+ return String (s2) !=s1;
}
inline String
operator + (String s1, String s2)
{
- s1 += s2;
- return s1;
+ s1 += s2;
+ return s1;
}
inline ostream &
operator << ( ostream& os, String d)
{
- d.print_on (os);
- return os;
+ d.print_on (os);
+ return os;
}
#endif
class Text_stream
{
- int line_no;
+ int line_no;
- // could just have used streams.
- FILE *f;
- Array<char> pushback;
- String name;
+ // could just have used streams.
+ FILE *f;
+ Array<char> pushback;
+ String name;
- public:
- Text_stream (String fn);
- String get_name() { return name; }
- bool eof() {
- return feof (f);
- }
- bool eol() {
- return (peek() == '\n');
- }
- char peek() {
- char c = get();
- unget (c);
- return c;
- }
- int line(){
- return line_no;
- }
+public:
+ Text_stream (String fn);
+ String get_name() { return name; }
+ bool eof() {
+ return feof (f);
+ }
+ bool eol() {
+ return (peek() == '\n');
+ }
+ char peek() {
+ char c = get();
+ unget (c);
+ return c;
+ }
+ int line(){
+ return line_no;
+ }
- char get() {
- char c;
+ char get() {
+ char c;
- if (pushback.empty())
- c = getc (f);
- else
- c = pushback.pop();
+ if (pushback.empty())
+ c = getc (f);
+ else
+ c = pushback.pop();
- if (c =='\n')
- line_no++;
- return c;
- }
- void unget (char c) {
- if (c =='\n')
- line_no--;
- pushback.push (c);
- }
- ~Text_stream(){
- if (!eof())
- cerr <<__FUNCTION__<< ": closing unended file";
+ if (c =='\n')
+ line_no++;
+ return c;
+ }
+ void unget (char c) {
+ if (c =='\n')
+ line_no--;
+ pushback.push (c);
+ }
+ ~Text_stream(){
+ if (!eof())
+ cerr <<__FUNCTION__<< ": closing unended file";
- fclose (f);
- }
+ fclose (f);
+ }
- /// GNU format message.
- void message (String s);
+ /// GNU format message.
+ void message (String s);
};
#endif
/*
- midi-parser.cc -- implement
+ midi-parser.cc -- implement Midi_parser[_info]
source file of the GNU LilyPond music typesetter
String
Midi_parser::get_str (int n)
{
- assert (n > 0);
+ assert (n >= 0);
+ if (!n)
+ warning ("Zero length string encountered");
+
Byte const* p = forward_byte_L (n);
return String (p, n);
}