00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVTENSORINDEX_H
00026 #define QVTENSORINDEX_H
00027
00028 #include <QMap>
00029 #include <qvdefines.h>
00030
00031 #ifndef DOXYGEN_IGNORE_THIS
00032 class QVTensorIndexRange;
00033 class QVTensorIndexValues: public QList<QVTensorIndexRange>
00034 {
00035 public:
00036 QVTensorIndexValues(): QList<QVTensorIndexRange>() {}
00037
00038 const QVTensorIndexValues operator&(const QVTensorIndexRange &indexRange) const
00039 {
00040 QVTensorIndexValues result = *this;
00041 result.append(indexRange);
00042 return result;
00043 }
00044
00045 QMap<int, QVector<int> > getIndexesValues() const;
00046 };
00047
00048 class QVTensorIndexRange
00049 {
00050 friend class QVTensorIndex;
00051
00052 public:
00053 int id, rangeMin, rangeMax;
00054
00055 QVTensorIndexRange(const QVTensorIndexRange &tensorIndexRange):
00056 id(tensorIndexRange.id), rangeMin(tensorIndexRange.rangeMin), rangeMax(tensorIndexRange.rangeMax) { }
00057
00058 const QVTensorIndexValues operator&(const QVTensorIndexRange &indexRange) const
00059 {
00060 QVTensorIndexValues result;
00061 result.append(*this);
00062 result.append(indexRange);
00063 return result;
00064 }
00065
00066 operator QVTensorIndexValues() const
00067 {
00068 QVTensorIndexValues result;
00069 result.append(*this);
00070 return result;
00071 }
00072 private:
00073 QVTensorIndexRange(const int id, const int rangeMin, const int rangeMax): id(id), rangeMin(rangeMin), rangeMax(rangeMax) { }
00074 };
00075
00077
00078 class QVTensorIndex;
00079 class QVTensorValence: public QList<QVTensorIndex>
00080 {
00081 public:
00082 QVTensorValence(): QList<QVTensorIndex>() {}
00083
00084 const QVTensorValence operator*(const QVTensorIndex &index) const
00085 {
00086 QVTensorValence result = *this;
00087 result.append(index);
00088 return result;
00089 }
00090
00091 const QVTensorValence operator&(const QVTensorIndex &index) const
00092 {
00093 QVTensorValence result = *this;
00094 result.append(index);
00095 return result;
00096 }
00097
00098 const QVTensorValence operator+(const QVTensorValence &indexList) const
00099 { return *this + indexList; }
00100
00101 QMap<int, QVector<int> > getIndexesPositions() const;
00102 };
00103
00104 #endif
00105
00118 class QVTensorIndex
00119 {
00120 public:
00123 QVTensorIndex(const int dimension): dim(dimension), id(nextIndexId++) { }
00124
00128 QVTensorIndex(const QVTensorIndex &tensorIndex): dim(tensorIndex.dim), id(tensorIndex.id) { }
00129
00132 QVTensorIndex cov() const { return QVTensorIndex(*this, true); }
00133
00136 QVTensorIndex covariant() const { return QVTensorIndex(*this, true); }
00137
00140 QVTensorIndexRange range(const int min, const int max) const { return QVTensorIndexRange(ABS(id), min, max); }
00141
00144 const QVTensorIndexRange operator[](const int value) const { return QVTensorIndexRange(ABS(id), value, value); }
00145
00146 #ifndef DOXYGEN_IGNORE_THIS
00147 QVTensorIndex(): dim(0), id(1) { }
00148 QVTensorIndex(const int dimension, const int ident): dim(dimension), id(ident) { }
00149 QVTensorIndex(const QVTensorIndex &tensorIndex, bool variate): dim(tensorIndex.dim), id((variate?-1:1)*tensorIndex.id) { }
00150
00151 int dim, id;
00152 const QVTensorValence operator*(const QVTensorIndex &index) const
00153 {
00154 QVTensorValence result;
00155 result.append(*this);
00156 result.append(index);
00157 return result;
00158 }
00159
00160 bool operator==(const QVTensorIndex &index) const
00161 { return true; }
00162
00163 operator QVTensorValence() const
00164 {
00165 QVTensorValence result;
00166 result.append(*this);
00167 return result;
00168 }
00169
00170 const QVTensorValence operator*(const QVTensorValence &indexList) const
00171 {
00172 QVTensorValence result = *this;
00173 result << indexList;
00174 return result;
00175 }
00176 #endif
00177 private:
00178 static int nextIndexId;
00179 static QVTensorIndex anyIndex;
00180 };
00181 #endif