First of all, I apologize for the lengthy approach to such a simplified question.
I implement a class that serves as a very long 1-dimensional index on a space filling curve or an n-tuple representing the Cartesian coordinate to which the index corresponds.
class curvePoint
{
public:
friend class curveCalculate;
curvePoint(): point(NULL), dimensions(0) {}
virtual ~curvePoint(){if(point!=NULL) delete[] point;}
void convertToIndex(){ if(isTuple()) calc(this); }
void convertToTuple(){ if(isIndex()) calc(this); }
void setTuple(quint16 *tuple, int size);
void setIndex(quint16 *index, int size);
void setAlgorithm(curveType alg){algorithm = alg;}
bool isIndex(){return current==Index;}
bool isTuple(){return current==Tuple;}
size_t size(){return dimensions;}
quint16 operator[](size_t index);
enum curveType{HilbertCurve, ZCurve, GrayCodeCurve};
enum status{Index, Tuple};
private:
curveCalculate calc;
curveType algorithm;
quint16 *point;
size_t dimensions;
status current;
};
(The length of the array pointed to by the dot is the dimensions)
In any case, in the implementation of the operator [], I was wondering what is the best method for checking bounds. I want to avoid exception exceptions, if at all possible, and the entire range of values โโcan be used for each number in the array, so it is also impossible to return a special value for an error outside the bounds;
I was thinking of something similar, but implemented in a class definition:
quint16 curvePoint::operator[](size_t index)
{
return point[ index % dimensions ];
}
, , , , ; , .
?
, ?
:
, .., , , stl .
, , , , stl , .
; , , ?
, , , , , Qt, , , .