stlab.adobe.com Adobe Systems Incorporated
enum_ops.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ENUM_OPS_HPP
10 #define ADOBE_ENUM_OPS_HPP
11 
12 /*************************************************************************************************/
13 
14 #include <adobe/config.hpp>
15 
16 /*************************************************************************************************/
17 
55 /*************************************************************************************************/
56 
57 namespace adobe {
58 
59 /*************************************************************************************************/
60 
61 namespace implementation {
62 
63 /*************************************************************************************************/
64 #if !defined(ADOBE_NO_DOCUMENTATION)
65  inline signed char promote_enum (signed char e) { return e; }
66  inline unsigned char promote_enum (unsigned char e) { return e; }
67  inline signed short promote_enum (signed short e) { return e; }
68  inline unsigned short promote_enum (unsigned short e) { return e; }
69  inline signed int promote_enum (signed int e) { return e; }
70  inline unsigned int promote_enum (unsigned int e) { return e; }
71  inline signed long promote_enum (signed long e) { return e; }
72  inline unsigned long promote_enum (unsigned long e) { return e; }
73 
74 #ifdef BOOST_HAS_LONG_LONG
75  inline signed long long promote_enum (signed long long e) { return e; }
76  inline unsigned long long promote_enum (unsigned long long e) { return e; }
77 #endif
78 #endif
79 /*************************************************************************************************/
80 
81 } // namespace implementation
82 
83 /*************************************************************************************************/
84 
85 } // namespace adobe
86 
87 /*************************************************************************************************/
88 
89 #define ADOBE_DEFINE_BITSET_OPS(EnumType) \
90 inline EnumType operator~(EnumType a) \
91 { \
92  return EnumType(~adobe::implementation::promote_enum(a)); \
93 } \
94  \
95 inline EnumType operator|(EnumType lhs, EnumType rhs) \
96 { \
97  return EnumType(adobe::implementation::promote_enum(lhs) \
98  | adobe::implementation::promote_enum(rhs)); \
99 } \
100  \
101 inline EnumType operator&(EnumType lhs, EnumType rhs) \
102 { \
103  return EnumType(adobe::implementation::promote_enum(lhs) \
104  & adobe::implementation::promote_enum(rhs)); \
105 } \
106  \
107 inline EnumType operator^(EnumType lhs, EnumType rhs) \
108 { \
109  return EnumType(adobe::implementation::promote_enum(lhs) \
110  ^ adobe::implementation::promote_enum(rhs)); \
111 } \
112  \
113 inline EnumType& operator&=(EnumType& lhs, EnumType rhs) \
114 { \
115  return lhs = lhs & rhs; \
116 } \
117  \
118 inline EnumType& operator|=(EnumType& lhs, EnumType rhs) \
119 { \
120  return lhs = lhs | rhs; \
121 } \
122  \
123 inline EnumType& operator^=(EnumType& lhs, EnumType rhs) \
124 { \
125  return lhs = lhs ^ rhs; \
126 }
127 
128 /*************************************************************************************************/
129 
130 #define ADOBE_DEFINE_ARITHMETIC_OPS(EnumType) \
131 inline EnumType operator+(EnumType a) \
132 { \
133  return EnumType(+adobe::implementation::promote_enum(a)); \
134 } \
135  \
136 inline EnumType operator-(EnumType a) \
137 { \
138  return EnumType(-adobe::implementation::promote_enum(a)); \
139 } \
140  \
141 inline EnumType operator+(EnumType lhs, EnumType rhs) \
142 { \
143  return EnumType(adobe::implementation::promote_enum(lhs) \
144  + adobe::implementation::promote_enum(rhs)); \
145 } \
146  \
147 inline EnumType operator-(EnumType lhs, EnumType rhs) \
148 { \
149  return EnumType(adobe::implementation::promote_enum(lhs) \
150  - adobe::implementation::promote_enum(rhs)); \
151 } \
152  \
153 inline EnumType operator*(EnumType lhs, EnumType rhs) \
154 { \
155  return EnumType(adobe::implementation::promote_enum(lhs) \
156  * adobe::implementation::promote_enum(rhs)); \
157 } \
158  \
159 inline EnumType operator/(EnumType lhs, EnumType rhs) \
160 { \
161  return EnumType(adobe::implementation::promote_enum(lhs) \
162  / adobe::implementation::promote_enum(rhs)); \
163 } \
164  \
165 inline EnumType operator%(EnumType lhs, EnumType rhs) \
166 { \
167  return EnumType(adobe::implementation::promote_enum(lhs) \
168  % adobe::implementation::promote_enum(rhs)); \
169 } \
170  \
171 inline EnumType& operator+=(EnumType& lhs, EnumType rhs) \
172 { \
173  return lhs = lhs + rhs; \
174 } \
175  \
176 inline EnumType& operator-=(EnumType& lhs, EnumType rhs) \
177 { \
178  return lhs = lhs - rhs; \
179 } \
180  \
181 inline EnumType& operator*=(EnumType& lhs, EnumType rhs) \
182 { \
183  return lhs = lhs * rhs; \
184 } \
185  \
186 inline EnumType& operator/=(EnumType& lhs, EnumType rhs) \
187 { \
188  return lhs = lhs / rhs; \
189 } \
190  \
191 inline EnumType& operator%=(EnumType& lhs, EnumType rhs) \
192 { \
193  return lhs = lhs % rhs; \
194 }
195 
196 /*************************************************************************************************/
197 
198 #endif
199 
200 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google