00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
#ifndef SHMANIPULATOR_HPP
00028
#define SHMANIPULATOR_HPP
00029
00030
#include "ShProgram.hpp"
00031
#include <vector>
00032
#include <string>
00033
#include <sstream>
00034
00035
namespace SH {
00036
00047
template<
typename T>
00048 struct storage_trait {
00049
typedef T StorageType;
00050 };
00051
00052
template<>
00053
struct storage_trait<const char*> {
00054
typedef std::string StorageType;
00055 };
00056
00057
enum OffsetRangeErrors {
00058 OFFSET_RANGE_BAD_OFFSET = -1,
00059 OFFSET_RANGE_BAD_INDEX = -2
00060 };
00061
00062
template<
typename T>
00063
class OffsetRange {
00064
public:
00065 OffsetRange();
00066 OffsetRange( T start, T end );
00067 OffsetRange( T start,
int startOffset, T end,
int endOffset );
00068
00075
int absStartIndex(
const ShProgramNode::VarList vars )
const;
00076
int absEndIndex(
const ShProgramNode::VarList vars )
const;
00077
00078 std::string toString() const;
00079
00080 private:
00081 T start, end;
00082
int startOffset, endOffset;
00083
int absIndex( T index,
int offset, const ShProgramNode::VarList &vars ) const;
00084 };
00085
00086
00098 template<typename T>
00099 class
ShManipulator {
00100
public:
00101
typedef typename storage_trait<T>::StorageType StorageType;
00102
typedef OffsetRange<StorageType> IndexRange;
00103
typedef std::vector<IndexRange> IndexRangeVector;
00104
00107 ShManipulator();
00108 ~ShManipulator();
00109
00110
ShManipulator<T>& operator()(T i);
00111
ShManipulator<T>& operator()(T start, T end);
00112
ShManipulator<T>& operator()(
const IndexRange &range);
00113
00114
00115 IndexRangeVector getRanges()
const;
00116
00117
00118 std::string toString()
const;
00119
00120
protected:
00121 IndexRangeVector m_ranges;
00122
00123
00124
00125
00126 OffsetRange<int> convertRange(IndexRange range,
const ShProgramNode::VarList &v)
const;
00127 };
00128
00137
template<
typename T>
00138
ShProgram operator<<(const ShProgram &p, const ShManipulator<T> &m);
00139
00146
template<
typename T>
00147
ShProgram operator<<(const ShManipulator<T> &m,
const ShProgram &p);
00148
00149
00151
00152
00162
template<
typename T>
00163
ShManipulator<T> shSwizzle(T i0);
00164
00165
template<
typename T>
00166
ShManipulator<T> shSwizzle(T i0, T i1);
00167
00168
template<
typename T>
00169
ShManipulator<T> shSwizzle(T i0, T i1, T i2);
00170
00171
template<
typename T>
00172
ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3);
00173
00174
template<
typename T>
00175
ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4);
00176
00177
template<
typename T>
00178
ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5);
00179
00180
template<
typename T>
00181
ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6);
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);
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);
00188
00189
template<
typename T>
00190
ShManipulator<T> shSwizzle(T i0, T i1, T i2, T i3, T i4, T i5, T i6, T i7, T i8, T i9);
00191
00192
template<
typename T>
00193
ShManipulator<T> shSwizzle(std::vector<T> indices);
00194
00196
00197
template<
typename T>
00198
ShManipulator<T> shRange(T i);
00199
00200
template<
typename T>
00201
ShManipulator<T> shRange(T start, T end);
00202
00213
template<
typename T>
00214
ShManipulator<T> shExtract(T k);
00215
00227
template<
typename T>
00228
ShManipulator<T> shInsert(T k);
00229
00238
template<
typename T>
00239
ShManipulator<T> shDrop(T k);
00240
00241
typedef ShManipulator<int> ShPositionManipulator;
00242
typedef ShManipulator<char*> ShNameManipulator;
00243
00244 }
00245
00246
#include "ShManipulatorImpl.hpp"
00247
00248
#endif