From ad1cadf3512f3dd789151983e5c93af411f929db Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 17 Sep 2016 19:27:15 +0000 Subject: restructure --- omegalib/omega_lib/include/basic/Tuple.h | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 omegalib/omega_lib/include/basic/Tuple.h (limited to 'omegalib/omega_lib/include/basic/Tuple.h') diff --git a/omegalib/omega_lib/include/basic/Tuple.h b/omegalib/omega_lib/include/basic/Tuple.h new file mode 100644 index 0000000..28e83bd --- /dev/null +++ b/omegalib/omega_lib/include/basic/Tuple.h @@ -0,0 +1,90 @@ +#if !defined _Already_defined_tuple +#define _Already_defined_tuple + +#include + +#include +#include +#include + +namespace omega { + +template class Tuple_Iterator; + +// TUPLES ARE INDEXED STARTING AT 1 +// index\(i\) == 0 MEANS i IS NOT IN THE TUPLE + +template class Tuple : public Sequence { +public: + Tuple(); + Tuple(int size); + Tuple (const Tuple& tpl); + virtual ~Tuple(); + Tuple& operator=(const Tuple& tpl); + int size() const { return sz; } + int length() const { return sz; } + bool operator==(const Tuple &b) const; + void reallocate(const int); + void delete_last(); + void append(const Tuple &v); + void append(const T &v); + void join(Tuple &v); + void clear(); + int empty() const; + + Iterator *new_iterator(); + + virtual T &operator[](int index); + virtual const T &operator[](int index) const; + + int index(const T &) const; + + friend class Tuple_Iterator; + +private: + int prealloc_size(const int req_size) + { return max(req_size+prealloc_pad,prealloc_min); } + int realloc_size(const int oldsize) { return 2*oldsize; } + + + int sz, alloc_sz; // Number of elements, size of allocated array + int prealloc_min,prealloc_pad; // These should be static, but that + // causes portability prob. for initialization + +protected: + T * data; +}; + +template class Tuple_Iterator : public Iterator { +public: + Tuple_Iterator(const Tuple &tpl); + const T & operator*() const; + T & operator*(); + void set_position(const int req_pos); + void operator++(int); + void operator++(); + void operator--(int); + void operator--(); + void set_to_last(); + void set_to_first(); +// void set_position(const int req_pos); Don't do this, compiler bug + bool live() const; + Iterator *new_copy() const; + +private: + Tuple_Iterator(T * cr, T * frst, T *lst, int insz); + T * current, * lastptr, *firstptr; + int sz; +}; + +} // namespace + +#if ! defined DONT_INCLUDE_TEMPLATE_CODE +#include +#endif + +#define instantiate_Tuple(T) template class Tuple; \ + template class Tuple_Iterator; \ + instantiate_Sequence(T) + +#endif -- cgit v1.2.3-70-g09d2