00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OMC_TUPLE_H
00032 #define OMC_TUPLE_H
00033
00034 #include "Core.h"
00035 #include "Util.h"
00036 #include <algorithm>
00037 #include <iostream>
00038 #include <vector>
00039 #include <string>
00040 #include <cmath>
00041 #include <climits>
00042
00043 namespace omc
00044 {
00045 class Tuple
00046 {
00047 friend std::ostream & operator<< (std::ostream &, const Tuple &);
00048
00049 public:
00050 Tuple (size_t, size_t);
00051 Tuple (size_t, const std::string &);
00052 Tuple (size_t, const std::vector <index_t> &);
00053 Tuple ();
00054 Tuple (const Tuple &);
00055
00056 bool next ();
00057
00058 index_t & operator[] (index_t);
00059 index_t operator[] (index_t) const;
00060
00061 bool operator== (const Tuple &);
00062 bool operator!= (const Tuple &);
00063
00064 size_t size () const;
00065
00066 int order () const;
00067
00068 static const int norder = 0;
00069
00070 protected:
00071 size_t m_numElements;
00072
00073 std::vector <index_t> m_Element;
00074
00075 private:
00076 index_t increment (index_t);
00077 };
00078
00079
00080 std::ostream & operator<< (std::ostream &, const Tuple &);
00081
00082
00084 inline Tuple::Tuple ()
00085 : m_numElements (0), m_Element()
00086 {}
00087
00089 inline Tuple::Tuple (const Tuple & T)
00090 : m_numElements (T.m_numElements), m_Element (T.m_Element)
00091 {}
00092
00095 inline bool Tuple::next () {
00096 return increment (m_Element.size()-1) < m_numElements ? true : false;
00097 }
00098
00100 inline index_t & Tuple::operator[] (index_t i) {
00101 return m_Element[i];
00102 }
00103
00105 inline index_t Tuple::operator[] (index_t i) const {
00106 return m_Element[i];
00107 }
00108
00110 inline bool Tuple::operator== (const Tuple & t) {
00111 return m_numElements == t.m_numElements &&
00112 m_Element.size() == t.m_Element.size() && m_Element == t.m_Element;
00113 }
00114
00116 inline bool Tuple::operator!= (const Tuple & t) {
00117 return ! ( (*this) == t);
00118 }
00119
00121 inline size_t Tuple::size () const {
00122 return m_Element.size();
00123 }
00124
00126 inline std::ostream & operator<< (std::ostream & os, const Tuple & T) {
00127 for (index_t i=0; i<T.size(); i++)
00128 os << T[i];
00129 return os;
00130 }
00131
00132 }
00133
00134 #endif // OMC_TUPLE_H