We now have a current svn snapshot of libqxt in our contrib dir, and
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / core / qxthypermacros.h
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtCore module of the Qt eXTension library
6 **
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
9 ** IBM.
10 **
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
15 **
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
20 **
21 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24
25 /**
26 \class QxtHyperMacros QxtHyperMacros
27
28 \ingroup QxtCore
29
30 \brief some helper macros for your daily work
31
32 hypermacros use templates in order to work
33 */
34
35
36
37
38 #ifndef HEADER_GUARDS_QxtHyperMacros_H
39 #define HEADER_GUARDS_QxtHyperMacros_H
40
41
42 /*! \relates QxtHyperMacros
43  * just do something n times
44  */
45 #define fortimes(times) for (QxtHyperValue<typeof(times)> hyperhyperthingyhopefullynooneusesthisnamehere=QxtHyperValue<typeof(times)>(0); hyperhyperthingyhopefullynooneusesthisnamehere<times; hyperhyperthingyhopefullynooneusesthisnamehere++)
46
47
48
49
50 template<typename T>
51 class  QxtHyperValue
52 {
53 public:
54
55     QxtHyperValue(const T& p)
56     {
57         value=p;
58     }
59
60     QxtHyperValue<T> & operator=(const QxtHyperValue<T> &rhs)
61     {
62         value=rhs;
63         return this;
64     }
65
66     operator T() const
67     {
68         return value;
69     }
70
71     const QxtHyperValue<T>& operator++()
72     {
73         value++;
74         return this;
75     }
76     const QxtHyperValue<T>& operator--()
77     {
78         value--;
79         return this;
80     }
81     const QxtHyperValue<T> operator++(int)
82     {
83         QxtHyperValue<T> clone = *this;
84         value++;
85         return clone;
86     }
87     const QxtHyperValue<T> operator--(int)
88     {
89         QxtHyperValue<T> clone = *this;
90         value--;
91         return clone;
92     }
93
94     bool operator== ( T& v)
95     {
96         return (value==v);
97     }
98
99     bool operator> ( T& v)
100     {
101         return (value>v);
102     }
103
104     bool operator< ( T& v)
105     {
106         return (value<v);
107     }
108
109 private:
110     T value;
111 };
112
113
114
115
116
117 #endif