00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHMANIPULATOR_HPP
00025 #define SHMANIPULATOR_HPP
00026
00027 #include "ShProgram.hpp"
00028 #include <vector>
00029 #include <string>
00030 #include <sstream>
00031
00032 namespace SH {
00033
00044 template<typename T>
00045 struct storage_trait {
00046 typedef T StorageType;
00047 };
00048
00049 template<>
00050 struct storage_trait<const char*> {
00051 typedef std::string StorageType;
00052 };
00053
00054 enum OffsetRangeErrors {
00055 OFFSET_RANGE_BAD_OFFSET = -1,
00056 OFFSET_RANGE_BAD_INDEX = -2
00057 };
00058
00059 template<typename T>
00060 class OffsetRange {
00061 public:
00062 OffsetRange();
00063 OffsetRange( T start, T end );
00064 OffsetRange( T start, int startOffset, T end, int endOffset );
00065
00072 int absStartIndex( const ShProgramNode::VarList vars ) const;
00073 int absEndIndex( const ShProgramNode::VarList vars ) const;
00074
00075 std::string toString() const;
00076
00077 private:
00078 T start, end;
00079 int startOffset, endOffset;
00080 int absIndex( T index, int offset, const ShProgramNode::VarList &vars ) const;
00081 };
00082
00083
00095 template<typename T>
00096 class ShManipulator {
00097 public:
00098 typedef typename storage_trait<T>::StorageType StorageType;
00099 typedef OffsetRange<StorageType> IndexRange;
00100 typedef std::vector<IndexRange> IndexRangeVector;
00101
00104 ShManipulator();
00105 ~ShManipulator();
00106
00107 ShManipulator<T>& operator()(T i);
00108 ShManipulator<T>& operator()(T start, T end);
00109 ShManipulator<T>& operator()(const IndexRange &range);
00110
00111
00112 IndexRangeVector getRanges() const;
00113
00114
00115 std::string toString() const;
00116
00117 protected:
00118 IndexRangeVector m_ranges;
00119
00120
00121
00122
00123 OffsetRange<int> convertRange(IndexRange range, const ShProgramNode::VarList &v) const;
00124 };
00125
00134 template<typename T>
00135 ShProgram operator<<(const ShProgram &p, const ShManipulator<T> &m);
00136
00143 template<typename T>
00144 ShProgram operator<<(const ShManipulator<T> &m, const ShProgram &p);
00145
00146
00148
00149
00159 template<typename T>
00160 ShManipulator<T> shSwizzle(T i0);
00161
00162 template<typename T>
00163 ShManipulator<T> shSwizzle(T i0, T i1);
00164
00165 template<typename T>
00166 ShManipulator<T> shSwizzle(T i0, T i1, T i2);
00167
00168 template<typename T>
00169 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3);
00170
00171 template<typename T>
00172 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4);
00173
00174 template<typename T>
00175 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5);
00176
00177 template<typename T>
00178 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6);
00179
00180 template<typename T>
00181 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7);
00182
00183 template<typename T>
00184 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7, T i8);
00185
00186 template<typename T>
00187 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7, T i8, T i9);
00188
00189 template<typename T>
00190 ShManipulator<T> shSwizzle(std::vector<T> indices);
00191
00193
00194 template<typename T>
00195 ShManipulator<T> shRange(T i);
00196
00197 template<typename T>
00198 ShManipulator<T> shRange(T start, T end);
00199
00210 template<typename T>
00211 ShManipulator<T> shExtract(T k);
00212
00224 template<typename T>
00225 ShManipulator<T> shInsert(T k);
00226
00235 template<typename T>
00236 ShManipulator<T> shDrop(T k);
00237
00238 typedef ShManipulator<int> ShPositionManipulator;
00239 typedef ShManipulator<char*> ShNameManipulator;
00240
00241 }
00242
00243 #include "ShManipulatorImpl.hpp"
00244
00245 #endif