X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcontrib%2Flibqxt-2007-10-24%2Fsrc%2Fcore%2Fqxttuple.h;fp=src%2Fcontrib%2Flibqxt-2007-10-24%2Fsrc%2Fcore%2Fqxttuple.h;h=555091e6c001383410a8db6db21f5e5ed399144e;hp=0000000000000000000000000000000000000000;hb=a634acadbcf6017474f68a3eaf7cb632660e9e49;hpb=cd122ca8e0d2c0ffc5397e0a813c75d791a7e6e3 diff --git a/src/contrib/libqxt-2007-10-24/src/core/qxttuple.h b/src/contrib/libqxt-2007-10-24/src/core/qxttuple.h new file mode 100644 index 00000000..555091e6 --- /dev/null +++ b/src/contrib/libqxt-2007-10-24/src/core/qxttuple.h @@ -0,0 +1,441 @@ +/**************************************************************************** +** +** Copyright (C) Qxt Foundation. Some rights reserved. +** +** This file is part of the QxtCore module of the Qt eXTension library +** +** This library is free software; you can redistribute it and/or modify it +** under the terms of th Common Public License, version 1.0, as published by +** IBM. +** +** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY +** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY +** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR +** FITNESS FOR A PARTICULAR PURPOSE. +** +** You should have received a copy of the CPL along with this file. +** See the LICENSE file and the cpl1.0.txt file included with the source +** distribution for more information. If you did not receive a copy of the +** license, contact the Qxt Foundation. +** +** +** +****************************************************************************/ + +#ifndef QXTTUPLE_H +#define QXTTUPLE_H +#include + +namespace QxtType +{ + +template +struct get + { + typedef typename get::type type; + }; + +template +struct get + {}; // does not define type + +template +struct get + { + typedef typename TYPELIST::head type; + }; + +template class QxtTuple; +template8)> struct QxtTupleValue; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return QxtTupleValue::value(&t->extend); + } + + static void setValue(QxtTuple* t, typename get::type val) + { + QxtTupleValue::setValue(&t->extend, val); + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t1; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t1 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t2; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t2 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t3; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t3 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t4; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t4 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t5; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t5 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t6; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t6 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t7; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t7 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t8; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t8 = val; + } +}; + +template struct QxtTupleValue +{ + static typename get::type value(QxtTuple* t) + { + return t->t9; + } + static void setValue(QxtTuple* t, typename get::type val) + { + t->t9 = val; + } +}; + +//----------------------------------------------------------------------------------------------- + +template +/** +\class QxtTuple QxtTuple + +\ingroup QxtCore + +\brief Arbitrary-length templated list + +Tuples and cons pairs are both pretty common template metaprogramming hacks. This set of classes +attempts to implement a healthy balance between the two. Tuples generally are implemented with a +fixed length; cons pairs have a lot of overhead and require a ton of typing. As with all template +metaprograms, it may take a while to compile. + +It is recommended to use the convenience macros to create tuples, but you can construct the +QxtTypeList template yourself if you desire; this may be preferable if you want to write generic +functions that use tuples. + +----- example: +\code +#include +#include +using namespace std; + +int main(int argc, char** argv) { + Qxt7Tuple(bool, char, short, int, long long, float, double) tuple; + + tuple.setValue<0>(true); + tuple.setValue<1>('a'); + tuple.setValue<2>(32767); + tuple.setValue<3>(1234567); + tuple.setValue<4>(987654321); + tuple.setValue<5>(1.414); + tuple.setValue<6>(3.14159265); + + cout << 0 << "=" << tuple.value<0>() << endl; + cout << 1 << "=" << tuple.value<1>() << endl; + cout << 2 << "=" << tuple.value<2>() << endl; + cout << 3 << "=" << tuple.value<3>() << endl; + cout << 4 << "=" << tuple.value<4>() << endl; + cout << 5 << "=" << tuple.value<5>() << endl; + cout << 6 << "=" << tuple.value<6>() << endl; +} +\endcode +*/ + +class QxtTuple +{ +public: + template typename get::type value() + { + return QxtTupleValue::value(this); + } + template void setValue(typename get::type val) + { + QxtTupleValue::setValue(this, val); + } + bool operator<(const QxtTuple& other) + { + if (t1 < other.t1) return true; + if (t2 < other.t2) return true; + if (t3 < other.t3) return true; + if (t4 < other.t4) return true; + if (t5 < other.t5) return true; + if (t6 < other.t6) return true; + if (t7 < other.t7) return true; + if (t8 < other.t8) return true; + if (t9 < other.t9) return true; + return false; + } + bool operator==(const QxtTuple& other) + { + if (t1 != other.t1) return false; + if (t2 != other.t2) return false; + if (t3 != other.t3) return false; + if (t4 != other.t4) return false; + if (t5 != other.t5) return false; + if (t6 != other.t6) return false; + if (t7 != other.t7) return false; + if (t8 != other.t8) return false; + if (t9 != other.t9) return false; + return true; + } + bool operator>=(const QxtTuple& other) + { + return !(*this < other); + } + bool operator<=(const QxtTuple& other) + { + if (t1 <= other.t1) return true; + if (t2 <= other.t2) return true; + if (t3 <= other.t3) return true; + if (t4 <= other.t4) return true; + if (t5 <= other.t5) return true; + if (t6 <= other.t6) return true; + if (t7 <= other.t7) return true; + if (t8 <= other.t8) return true; + if (t9 <= other.t9) return true; + return false; + } + bool operator>(const QxtTuple& other) + { + return !(*this <= other); + } + bool operator!=(const QxtTuple& other) + { + return !(*this == other); + } + + +// if only we could get away with making these protected + typename get::type t1; + typename get::type t2; + typename get::type t3; + typename get::type t4; + typename get::type t5; + typename get::type t6; + typename get::type t7; + typename get::type t8; + typename get::type t9; +}; + +//----------------------------------------------------------------------------------------------- + +template +class QxtTuple +{ +public: + template typename get::type value() + { + return QxtTupleValue::value(this); + } + template void setValue(typename get::type val) + { + QxtTupleValue::setValue(this, val); + } + bool operator<(const QxtTuple& other) + { + if (t1 < other.t1) return true; + if (t2 < other.t2) return true; + if (t3 < other.t3) return true; + if (t4 < other.t4) return true; + if (t5 < other.t5) return true; + if (t6 < other.t6) return true; + if (t7 < other.t7) return true; + if (t8 < other.t8) return true; + if (t9 < other.t9) return true; + if (extend < other.extend) return true; + return false; + } + bool operator==(const QxtTuple& other) + { + if (t1 != other.t1) return false; + if (t2 != other.t2) return false; + if (t3 != other.t3) return false; + if (t4 != other.t4) return false; + if (t5 != other.t5) return false; + if (t6 != other.t6) return false; + if (t7 != other.t7) return false; + if (t8 != other.t8) return false; + if (t9 != other.t9) return false; + if (extend != other.extend) return false; + return true; + } + bool operator>=(const QxtTuple& other) + { + return !(*this < other); + } + bool operator<=(const QxtTuple& other) + { + if (t1 <= other.t1) return true; + if (t2 <= other.t2) return true; + if (t3 <= other.t3) return true; + if (t4 <= other.t4) return true; + if (t5 <= other.t5) return true; + if (t6 <= other.t6) return true; + if (t7 <= other.t7) return true; + if (t8 <= other.t8) return true; + if (t9 <= other.t9) return true; + if (extend <= other.extend) return true; + return false; + } + bool operator>(const QxtTuple& other) + { + return !(*this <= other); + } + bool operator!=(const QxtTuple& other) + { + return !(*this == other); + } + +// if only we could get away with making these protected + typename get::type t1; + typename get::type t2; + typename get::type t3; + typename get::type t4; + typename get::type t5; + typename get::type t6; + typename get::type t7; + typename get::type t8; + typename get::type t9; + QxtTuple extend; +}; + +} + +#ifndef QXT_NO_USING +using QxtType::QxtTuple; +#endif + +#ifndef QXT_NO_MACROS +/*! \relates QxtTuple + * Declares a one-column tuple. + */ +#define Qxt1Tuple(a) QxtTuple > + +/*! \relates QxtTuple + * Declares a two-column tuple, similar to QPair. + */ +#define Qxt2Tuple(a, b) QxtTuple > + +/*! \relates QxtTuple + * Declares a three-column tuple, similar to QxtTriple. + */ +#define Qxt3Tuple(a, b, c) QxtTuple > + +/*! \relates QxtTuple + * Declares a four-column tuple. + */ +#define Qxt4Tuple(a, b, c, d) QxtTuple > + +/*! \relates QxtTuple + * Declares a five-column tuple. + */ +#define Qxt5Tuple(a, b, c, d, e) QxtTuple > + +/*! \relates QxtTuple + * Declares a six-column tuple. + */ +#define Qxt6Tuple(a, b, c, d, e, f) QxtTuple > + +/*! \relates QxtTuple + * Declares a seven-column tuple. + */ +#define Qxt7Tuple(a, b, c, d, e, f, g) QxtTuple > + +/*! \relates QxtTuple + * Declares an eight-column tuple. + */ +#define Qxt8Tuple(a, b, c, d, e, f, g, h) QxtTuple > + +/*! \relates QxtTuple + * Declares a nine-column tuple. + */ +#define Qxt9Tuple(a, b, c, d, e, f, g, h, i) QxtTuple > + +/*! \relates QxtTuple + * Declares an extended tuple with ten or more columns. Pay special attention to the syntax of the tenth parameter, which + * must be a QxtTypeList, not a storage type. +\code +QxtLongTuple(int, int, int, int, int, int, int, int, int, Qxt1TypeList(int)) tuple; // correct way to implement a 10-tuple +QxtLongTuple(int, int, int, int, int, int, int, int, int, int) tuple; // this will produce a (very long) compile-time error +\endcode + */ +#define QxtLongTuple(a, b, c, d, e, f, g, h, i, extend) QxtTuple, true > + +#endif + +#endif