00001
00002
00003
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _CHOMP_STRUCT_SETUNION_H_
00039 #define _CHOMP_STRUCT_SETUNION_H_
00040
00041 #include "chomp/system/config.h"
00042
00043 namespace chomp {
00044 namespace homology {
00045
00046
00047
00048 template <class set1type, class set2type>
00049 class setunion;
00050
00051
00052
00053
00054
00055
00060 template <class set1type, class set2type>
00061 class setunion
00062 {
00063 public:
00065 typedef typename set1type::value_type value_type;
00066
00068 setunion (const set1type &_set1, const set2type &_set2);
00069
00071 setunion (const setunion<set1type,set2type> &s);
00072
00074 setunion &operator = (const setunion<set1type,set2type> &s);
00075
00077 ~setunion ();
00078
00080 const set1type &get1 () const;
00081
00083 const set2type &get2 () const;
00084
00087 int_t getnumber (const typename set1type::value_type &e) const;
00088
00093 bool checknum (int_t n) const;
00094
00097 bool check (const typename set1type::value_type &e) const;
00098
00100 const typename setunion<set1type,set2type>::value_type &
00101 operator [] (int_t n) const;
00102
00104 const typename setunion<set1type,set2type>::value_type &get (int_t n)
00105 const;
00106
00108 int_t size () const;
00109
00111 bool empty () const;
00112
00113 private:
00115 const set1type *set1;
00116
00118 const set2type *set2;
00119
00120 };
00121
00122
00123
00124 template <class set1type, class set2type>
00125 inline setunion<set1type,set2type>::setunion (const set1type &_set1,
00126 const set2type &_set2): set1 (&_set1), set2 (&_set2)
00127 {
00128 return;
00129 }
00130
00131 template <class set1type, class set2type>
00132 inline setunion<set1type,set2type>::~setunion ()
00133 {
00134 return;
00135 }
00136
00137 template <class set1type, class set2type>
00138 inline setunion<set1type,set2type>::setunion
00139 (const setunion<set1type,set2type> &)
00140 {
00141 throw "Trying to use the copy constructor of a set union.";
00142 return;
00143 }
00144
00145 template <class set1type, class set2type>
00146 inline setunion<set1type,set2type> &setunion<set1type,set2type>::
00147 operator = (const setunion<set1type,set2type> &)
00148 {
00149 throw "Trying to use the assignment operator of a set union.";
00150 return;
00151 }
00152
00153 template <class set1type, class set2type>
00154 inline const set1type &setunion<set1type,set2type>::get1 () const
00155 {
00156 return *set1;
00157 }
00158
00159 template <class set1type, class set2type>
00160 inline const set2type &setunion<set1type,set2type>::get2 () const
00161 {
00162 return *set2;
00163 }
00164
00165 template <class set1type, class set2type>
00166 inline int_t setunion<set1type,set2type>::getnumber
00167 (const typename set1type::value_type &e) const
00168 {
00169 int_t n = set1 -> getnumber (e);
00170 if (n >= 0)
00171 return n;
00172 n = set2 -> getnumber (e);
00173 if (n >= 0)
00174 return set1 -> size () + n;
00175 else
00176 return n;
00177 }
00178
00179 template <class set1type, class set2type>
00180 inline bool setunion<set1type,set2type>::checknum (int_t n) const
00181 {
00182 return ((n >= 0) && (n < set1 -> size () + set2 -> size ()));
00183 }
00184
00185 template <class set1type, class set2type>
00186 inline bool setunion<set1type,set2type>::check
00187 (const typename set1type::value_type &e) const
00188 {
00189 return (set1 -> check (e) || set2 -> check (e));
00190 }
00191
00192 template <class set1type, class set2type>
00193 inline const typename setunion<set1type,set2type>::value_type &
00194 setunion<set1type,set2type>::get (int_t n) const
00195 {
00196 int_t size1 = set1 -> size ();
00197 if (n < size1)
00198 return set1 -> get (n);
00199 else
00200 return set2 -> get (n - size1);
00201 }
00202
00203 template <class set1type, class set2type>
00204 inline const typename setunion<set1type,set2type>::value_type &
00205 setunion<set1type,set2type>::operator [] (int_t n) const
00206 {
00207 return get (n);
00208 }
00209
00210 template <class set1type, class set2type>
00211 inline int_t setunion<set1type,set2type>::size () const
00212 {
00213 return (set1 -> size () + set2 -> size ());
00214 }
00215
00216 template <class set1type, class set2type>
00217 inline bool setunion<set1type,set2type>::empty () const
00218 {
00219 return (set1 -> empty () && set2 -> empty ());
00220 }
00221
00222
00223
00225 template <class set1type, class set2type>
00226 inline setunion<set1type,set2type> makesetunion (const set1type &set1,
00227 const set2type &set2)
00228 {
00229 return setunion<set1type,set2type> (set1, set2);
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 }
00245 }
00246
00247 #endif // _CHOMP_STRUCT_SETUNION_H_
00248
00250