00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #ifndef SHMANIPULATOR_HPP
00021 #define SHMANIPULATOR_HPP
00022
00023 #include "ShProgram.hpp"
00024 #include <vector>
00025 #include <string>
00026 #include <sstream>
00027
00028 namespace SH {
00029
00040 template<typename T>
00041 struct storage_trait {
00042 typedef T StorageType;
00043 };
00044
00045 template<>
00046 struct storage_trait<const char*> {
00047 typedef std::string StorageType;
00048 };
00049
00050 enum OffsetRangeErrors {
00051 OFFSET_RANGE_BAD_OFFSET = -1,
00052 OFFSET_RANGE_BAD_INDEX = -2
00053 };
00054
00055 template<typename T>
00056 class OffsetRange {
00057 public:
00058 OffsetRange();
00059 OffsetRange( T start, T end );
00060 OffsetRange( T start, int startOffset, T end, int endOffset );
00061
00068 int absStartIndex( const ShProgramNode::VarList vars ) const;
00069 int absEndIndex( const ShProgramNode::VarList vars ) const;
00070
00071 std::string toString() const;
00072
00073 private:
00074 T start, end;
00075 int startOffset, endOffset;
00076 int absIndex( T index, int offset, const ShProgramNode::VarList &vars ) const;
00077 };
00078
00079
00091 template<typename T>
00092 class ShManipulator {
00093 public:
00094 typedef typename storage_trait<T>::StorageType StorageType;
00095 typedef OffsetRange<StorageType> IndexRange;
00096 typedef std::vector<IndexRange> IndexRangeVector;
00097
00100 ShManipulator();
00101 ~ShManipulator();
00102
00103 ShManipulator<T>& operator()(T i);
00104 ShManipulator<T>& operator()(T start, T end);
00105 ShManipulator<T>& operator()(const IndexRange &range);
00106
00107
00108 IndexRangeVector getRanges() const;
00109
00110
00111 std::string toString() const;
00112
00113 protected:
00114 IndexRangeVector m_ranges;
00115
00116
00117
00118
00119 OffsetRange<int> convertRange(IndexRange range, const ShProgramNode::VarList &v) const;
00120 };
00121
00130 template<typename T>
00131 ShProgram operator<<(const ShProgram &p, const ShManipulator<T> &m);
00132
00139 template<typename T>
00140 ShProgram operator<<(const ShManipulator<T> &m, const ShProgram &p);
00141
00142
00144
00145
00155 template<typename T>
00156 ShManipulator<T> shSwizzle(T i0);
00157
00158 template<typename T>
00159 ShManipulator<T> shSwizzle(T i0, T i1);
00160
00161 template<typename T>
00162 ShManipulator<T> shSwizzle(T i0, T i1, T i2);
00163
00164 template<typename T>
00165 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3);
00166
00167 template<typename T>
00168 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4);
00169
00170 template<typename T>
00171 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5);
00172
00173 template<typename T>
00174 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6);
00175
00176 template<typename T>
00177 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7);
00178
00179 template<typename T>
00180 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7, T i8);
00181
00182 template<typename T>
00183 ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7, T i8, T i9);
00184
00185 template<typename T>
00186 ShManipulator<T> shSwizzle(std::vector<T> indices);
00187
00189
00190 template<typename T>
00191 ShManipulator<T> shRange(T i);
00192
00193 template<typename T>
00194 ShManipulator<T> shRange(T start, T end);
00195
00206 template<typename T>
00207 ShManipulator<T> shExtract(T k);
00208
00220 template<typename T>
00221 ShManipulator<T> shInsert(T k);
00222
00231 template<typename T>
00232 ShManipulator<T> shDrop(T k);
00233
00234 typedef ShManipulator<int> ShPositionManipulator;
00235 typedef ShManipulator<char*> ShNameManipulator;
00236
00237 }
00238
00239 #include "ShManipulatorImpl.hpp"
00240
00241 #endif