00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022 #ifndef INTELIB_SVECTOR_HPP_SENTRY
00023 #define INTELIB_SVECTOR_HPP_SENTRY
00024
00025 #include "iexcept.hpp"
00026 #include "sexpress.hpp"
00027 #include "gensref.hpp"
00028
00030
00037 class SExpressionVector : public SExpression {
00038 SReference *vector;
00039 unsigned int size;
00040 unsigned int real_size;
00041 bool resizeable;
00042 public:
00044 static IntelibTypeId TypeId;
00045
00047
00054 SExpressionVector(int n = 0);
00055
00056 protected:
00058 SExpressionVector(const IntelibTypeId &tid, int n = 0);
00060 ~SExpressionVector() { if(vector) delete [] vector; }
00061
00062 public:
00064 const SReference& operator[](unsigned int n) const;
00066 SReference& operator[](unsigned int n);
00067
00069 int Size() const { return size; }
00071 void SetSize(unsigned int n);
00073 bool IsResizeable() const { return resizeable; }
00074
00075 virtual SExpression* Clone() const;
00076
00077 #if INTELIB_TEXT_REPRESENTATIONS == 1
00078 virtual SString TextRepresentation() const;
00079 #endif
00080
00081 private:
00082 void Resize(unsigned int n);
00083 };
00084
00086 class IntelibX_not_a_vector : public IntelibX {
00087 public:
00088 IntelibX_not_a_vector(SReference a_param);
00089 };
00090
00092 typedef GenericSReference<SExpressionVector,IntelibX_not_a_vector>
00093 SVectorRefBase;
00094
00096
00108 class SVectorRef : public SVectorRefBase {
00109 public:
00111
00112 SVectorRef() {}
00113
00115
00122 explicit SVectorRef(int n) : SVectorRefBase(new SExpressionVector(n)) {}
00123
00125 SVectorRef(SExpressionVector *ts) : SVectorRefBase(ts) {}
00126
00128
00129 SVectorRef(const SVectorRef &other) : SVectorRefBase(other) {}
00130
00132
00135 SVectorRef(const SReference &other) : SVectorRefBase(other) {}
00136
00138
00147 SVectorRef(SReference &ref, int fake);
00148
00150 ~SVectorRef() {}
00151
00153 const SReference& operator[](int index) const
00154 { return (*GetPtr())[index]; }
00155
00157 SReference& operator[](int index) { return (*GetPtr())[index]; }
00158 };
00159
00161
00165 class SVectorRange : public SVectorRef {
00166 int idx, len;
00167 public:
00169
00173 SVectorRange(const SVectorRef& vec, int a_idx = 0, int a_len = -1)
00174 : SVectorRef(vec), idx(a_idx), len(a_len)
00175 {
00176 if(len==-1 || len > (*this)->Size()-idx )
00177 len = (*this)->Size()-idx;
00178 }
00179
00181 ~SVectorRange() {}
00182
00184
00187 SVectorRef Copy(bool resizeable) const;
00188
00190
00193 SVectorRef Copy() const;
00194
00196 void Erase();
00197
00199 void Replace(const SVectorRange& other);
00200 };
00201
00202
00204
00210 class SVector : public SVectorRef {
00211 public:
00213
00222 explicit SVector(unsigned int n = 0) : SVectorRef(n) {}
00224
00227 SVector(SExpressionVector *ts) : SVectorRef(ts) {}
00229
00232 SVector(const SVector &other) : SVectorRef(other.Clone()) {}
00234
00237 SVector(const SVectorRef &other) : SVectorRef(other.Clone()) {}
00238 ~SVector() {}
00239
00240 SVector& operator =(const SVectorRef& ref)
00241 { SReference::operator=(ref.Clone()); return *this; }
00242 SVector& operator =(SExpressionVector *lt)
00243 { SReference::operator=(lt); return *this; }
00244
00245 private:
00246
00247
00248 void operator =(const SReference& ref) {}
00249
00250 };
00251
00253
00259 template<int dim>
00260 class SMatrixRef : public SVectorRef {
00261 public:
00262 SMatrixRef() : SVectorRef() {}
00263 SMatrixRef(const SReference &ref) : SVectorRef(ref) {}
00264 SMatrixRef<dim-1> operator[](int i)
00265 { return SVectorRef(SVectorRef::operator[](i), 1); }
00266 };
00267
00269 template<>
00270 class SMatrixRef<2> : public SVectorRef {
00271 public:
00272 SMatrixRef() : SVectorRef() {}
00273 SMatrixRef(const SReference &ref) : SVectorRef(ref) {}
00274 SVectorRef operator[](int i)
00275 { return SVectorRef(SVectorRef::operator[](i), 1); }
00276 };
00277
00279
00282 class IntelibX_vector_out_of_range : public IntelibX {
00283 public:
00284 IntelibX_vector_out_of_range(SReference a_param);
00285 };
00286
00287 #endif