33 #ifndef DRAIN_TUPLE_BASE
34 #define DRAIN_TUPLE_BASE
44 #include "StringBuilder.h"
53 template <
typename S,
size_t N=2>
62 typedef S
const* const_iterator;
64 static const size_t storageTypeSize;
81 const_iterator begin()
const = 0;
84 const_iterator end()
const = 0;
97 const S &
at(
size_t i)
const {
100 return *(begin() + i);
112 const S & operator[](
size_t i)
const {
123 return *(begin() + i);
135 S & operator[](
size_t i){
142 const_iterator it = begin();
143 const_iterator tit = t.begin();
155 return !(*
this == t);
162 for (const_iterator it = begin(); it != end(); ++it){
163 sequence.insert(sequence.end(), *it);
172 void set(
const tuplebase_t & t){
186 template <
class T2,
size_t N2=2>
201 void set(
const S & arg) {
209 template<
typename ... SS>
211 void set(
const S & arg,
const SS &... rest) {
218 void set(std::initializer_list<T> l){
245 typename T::const_iterator cit = sequence.begin();
246 iterator it = begin();
247 while (cit != sequence.end()){
253 throw std::runtime_error(
StringBuilder<':'>(__FILE__,
':', __FUNCTION__,
": index overflow in assigning: ", *cit));
273 for (iterator it = begin(); it != end(); ++it){
288 std::ostream &
toStream(std::ostream & ostr,
char separator=
',')
const {
290 for (const_iterator it = begin(); it != end(); ++it){
300 std::string toStr(
char separator=
',')
const {
301 std::stringstream sstr;
311 void updateTuple(){};
323 template<
typename T2,
typename ... TT>
326 throw std::runtime_error(
StringBuilder<>(__FILE__,
':', __FUNCTION__,
": index (", i,
") overflow in assigning: ", arg,
",..."));
330 this->
at(i) =
static_cast<S
>(arg);
337 template <
typename S,
size_t N>
338 const size_t TupleBase<S,N>::storageTypeSize =
sizeof(S);
341 template <
class S,
size_t N>
342 std::ostream & operator<<(std::ostream & ostr,
const TupleBase<S,N> & tuple){
343 return tuple.toStream(ostr);
347 template <
typename S,
size_t N>
350 static const std::string & str(){
Definition: StringBuilder.h:58
Definition: TupleBase.h:54
S & at(size_t i)
Return reference to element i.
Definition: TupleBase.h:121
static size_t size()
Return the number of elements.
Definition: TupleBase.h:76
virtual std::ostream & toStream(std::ostream &ostr, char separator=',') const
Definition: TupleBase.h:288
void setIndexed(size_t i)
Argument stack endpoint function; final step of variadic argument set(arg, ...) .
Definition: TupleBase.h:317
bool operator!=(const tuplebase_t &t) const
Inequality operator.
Definition: TupleBase.h:154
tuplebase_t & assignSequence(T &sequence, bool LENIENT=false)
Proposed for tuples only; derived classes should not shadow this.
Definition: TupleBase.h:244
T & toSequence(T &sequence) const
Copy elements to a Sequence, like stl::list, stl::set or stl::vector.
Definition: TupleBase.h:160
const S & at(size_t i) const
Return const reference to element i.
Definition: TupleBase.h:97
void fill(S i)
Set all the elements to i.
Definition: TupleBase.h:272
bool operator==(const tuplebase_t &t) const
Equality operator.
Definition: TupleBase.h:141
void setIndexed(size_t i, T2 arg, const TT &... rest)
Worker called by set(T2 arg, T2 arg2, ...)
Definition: TupleBase.h:324
void set(const TupleBase< T2, N2 > &t)
Assign tuple of different type and/or size.
Definition: TupleBase.h:189
void set(const S &arg, const SS &... rest)
Set element(s).
Definition: TupleBase.h:211
Definition: DataSelector.cpp:1277
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition: Type.h:558