1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef applicative_sequence_h
26 #define applicative_sequence_h
28 ////////////////////////////////////////////////////////////////////////////
29 // Class Sequence<T> allows the user to construct lists of a homogeneous
30 // type. These lists are all applicative in nature and concatenation
31 // can be accomplished in O(1) time. The lists are also symetric
32 // in nature and is not biased toward one end as is in the traditional
34 ////////////////////////////////////////////////////////////////////////////
36 #include <AD/generic/generic.h>
41 int ref_count
; // reference count
42 int len
; // length of the array
43 const Sequence
* left
; // left link
44 const Sequence
* right
; // right link
45 const T
* array
; // array of elements
48 SeqRep
* list
; // pointer to actual representation
52 /////////////////////////////////////////////////////////////
53 // Constructor and destructor
54 /////////////////////////////////////////////////////////////
56 Sequence(const Sequence
&);
61 /////////////////////////////////////////////////////////////
63 /////////////////////////////////////////////////////////////
64 Sequence
operator () (int i
, int j
) const;
66 /////////////////////////////////////////////////////////////
68 /////////////////////////////////////////////////////////////
69 const T
& operator [] (int i
) const;
72 /////////////////////////////////////////////////////////////
74 /////////////////////////////////////////////////////////////
75 friend Sequence
operator + (const Sequence
&, const Sequence
&);
76 friend Sequence
operator + (const T
&, const Sequence
&);
77 friend Sequence
operator + (const Sequence
&, const T
&);
78 friend Sequence
operator + (const T
[], const Sequence
&);
79 friend Sequence
operator + (const Sequence
&, const T
[]);
82 ///////////////////////////////////////////////////////////////////////
83 // Implementation of the template methods
84 ///////////////////////////////////////////////////////////////////////
86 Sequence
<T
>::Sequence()
90 Sequence
<T
>::Sequence(const Sequence
<T
>&)
94 Sequence
<T
>::Sequence(const T
&)
98 Sequence
<T
>::Sequence(const T
[])
102 Sequence
<T
>::~Sequence()
106 Sequence
<T
> operator + (const Sequence
<T
>&, const Sequence
<T
>&)
110 Sequence
<T
> operator + (const Sequence
<T
>&, const T
&)
114 Sequence
<T
> operator + (const T
&, const Sequence
<T
>&)
118 Sequence
<T
> operator + (const Sequence
<T
>&, const T
[])
122 Sequence
<T
> operator + (const T
[], const Sequence
<T
>&)