33 #ifndef DRAIN_TUPLE_BASE
34 #define DRAIN_TUPLE_BASE
44 #include "StringBuilder.h"
74 template <
typename S,
size_t N=2>
83 typedef S
const* const_iterator;
85 static const size_t storageTypeSize;
102 const_iterator begin()
const = 0;
105 const_iterator end()
const = 0;
108 iterator begin() = 0;
118 const S &
at(
size_t i)
const {
121 return *(begin() + i);
133 const S & operator[](
size_t i)
const {
144 return *(begin() + i);
156 S & operator[](
size_t i){
163 const_iterator it = begin();
164 const_iterator tit = t.begin();
180 for (
const auto e: *
this){
198 return !(*
this == t);
205 for (const_iterator it = begin(); it != end(); ++it){
206 sequence.insert(sequence.end(), *it);
215 void set(
const tuplebase_t & t){
229 template <
class T2,
size_t N2=2>
244 void set(
const S & arg) {
252 template<
typename ... SS>
254 void set(
const S & arg,
const SS &... rest) {
261 void set(std::initializer_list<T> l){
288 typename T::const_iterator cit = sequence.begin();
289 iterator it = begin();
290 while (cit != sequence.end()){
296 throw std::runtime_error(
StringBuilder<':'>(__FILE__,
':', __FUNCTION__,
": index overflow in assigning: ", *cit));
316 for (iterator it = begin(); it != end(); ++it){
331 std::ostream &
toStream(std::ostream & ostr,
char separator=
',')
const {
333 for (const_iterator it = begin(); it != end(); ++it){
343 std::string toStr(
char separator=
',')
const {
344 std::stringstream sstr;
354 void updateTuple(){};
366 template<
typename T2,
typename ... TT>
369 throw std::runtime_error(
StringBuilder<>(__FILE__,
':', __FUNCTION__,
": index (", i,
") overflow in assigning: ", arg,
",..."));
373 this->
at(i) =
static_cast<S
>(arg);
380 template <
typename S,
size_t N>
381 const size_t TupleBase<S,N>::storageTypeSize =
sizeof(S);
384 template <
class S,
size_t N>
385 std::ostream & operator<<(std::ostream & ostr,
const TupleBase<S,N> & tuple){
386 return tuple.toStream(ostr);
390 template <
typename S,
size_t N>
393 static const std::string & str(){
Definition: StringBuilder.h:58
Definition: TupleBase.h:75
S & at(size_t i)
Return reference to element i.
Definition: TupleBase.h:142
static size_t size()
Return the number of elements.
Definition: TupleBase.h:97
virtual std::ostream & toStream(std::ostream &ostr, char separator=',') const
Definition: TupleBase.h:331
void setIndexed(size_t i)
Argument stack endpoint function; final step of variadic argument set(arg, ...) .
Definition: TupleBase.h:360
bool operator!=(const tuplebase_t &t) const
Inequality operator.
Definition: TupleBase.h:197
tuplebase_t & assignSequence(T &sequence, bool LENIENT=false)
Proposed for tuples only; derived classes should not shadow this.
Definition: TupleBase.h:287
T & toSequence(T &sequence) const
Copy elements to a Sequence, like stl::list, stl::set or stl::vector.
Definition: TupleBase.h:203
const S & at(size_t i) const
Return const reference to element i.
Definition: TupleBase.h:118
void fill(S i)
Set all the elements to i.
Definition: TupleBase.h:315
bool operator==(const tuplebase_t &t) const
Equality operator.
Definition: TupleBase.h:162
void setIndexed(size_t i, T2 arg, const TT &... rest)
Worker called by set(T2 arg, T2 arg2, ...)
Definition: TupleBase.h:367
void set(const TupleBase< T2, N2 > &t)
Assign tuple of different type and/or size.
Definition: TupleBase.h:232
void set(const S &arg, const SS &... rest)
Set element(s).
Definition: TupleBase.h:254
bool operator==(const value_type &t) const
Equality operator against single value.
Definition: TupleBase.h:178
Definition: DataSelector.cpp:1277
Definition: TupleBase.h:52
static const S neutral_value
Zero, by default. For enum types, must be explicitly given.
Definition: TupleBase.h:63
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition: Type.h:558