stlab.adobe.com Adobe Systems Incorporated

enum_ops.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_ENUM_OPS_HPP
00010 #define ADOBE_ENUM_OPS_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 /*************************************************************************************************/
00017 
00055 /*************************************************************************************************/
00056 
00057 namespace adobe {
00058 
00059 /*************************************************************************************************/
00060 
00061 namespace implementation {
00062 
00063 /*************************************************************************************************/
00064 #if !defined(ADOBE_NO_DOCUMENTATION)
00065     inline signed char promote_enum (signed char e) { return e; }
00066     inline unsigned char promote_enum (unsigned char e) { return e; }
00067     inline signed short promote_enum (signed short e) { return e; }
00068     inline unsigned short promote_enum (unsigned short e) { return e; }
00069     inline signed int promote_enum (signed int e) { return e; }
00070     inline unsigned int promote_enum (unsigned int e) { return e; }
00071     inline signed long promote_enum (signed long e) { return e; }
00072     inline unsigned long promote_enum (unsigned long e) { return e; }
00073 
00074 #ifdef BOOST_HAS_LONG_LONG
00075     inline signed long long promote_enum (signed long long e) { return e; }
00076     inline unsigned long long promote_enum (unsigned long long e) { return e; }
00077 #endif
00078 #endif
00079 /*************************************************************************************************/
00080 
00081 } // namespace implementation
00082 
00083 /*************************************************************************************************/
00084 
00085 } // namespace adobe
00086 
00087 /*************************************************************************************************/
00088 
00089 #define ADOBE_DEFINE_BITSET_OPS(EnumType)                               \
00090 inline EnumType operator~(EnumType a)                                   \
00091 {                                                                       \
00092     return EnumType(~adobe::implementation::promote_enum(a));           \
00093 }                                                                       \
00094                                                                         \
00095 inline EnumType operator|(EnumType lhs, EnumType rhs)                   \
00096 {                                                                       \
00097     return EnumType(adobe::implementation::promote_enum(lhs)            \
00098         | adobe::implementation::promote_enum(rhs));                    \
00099 }                                                                       \
00100                                                                         \
00101 inline EnumType operator&(EnumType lhs, EnumType rhs)                   \
00102 {                                                                       \
00103     return EnumType(adobe::implementation::promote_enum(lhs)            \
00104         & adobe::implementation::promote_enum(rhs));                    \
00105 }                                                                       \
00106                                                                         \
00107 inline EnumType operator^(EnumType lhs, EnumType rhs)                   \
00108 {                                                                       \
00109     return EnumType(adobe::implementation::promote_enum(lhs)            \
00110         ^ adobe::implementation::promote_enum(rhs));                    \
00111 }                                                                       \
00112                                                                         \
00113 inline EnumType& operator&=(EnumType& lhs, EnumType rhs)                \
00114 {                                                                       \
00115     return lhs = lhs & rhs;                                             \
00116 }                                                                       \
00117                                                                         \
00118 inline EnumType& operator|=(EnumType& lhs, EnumType rhs)                \
00119 {                                                                       \
00120     return lhs = lhs | rhs;                                             \
00121 }                                                                       \
00122                                                                         \
00123 inline EnumType& operator^=(EnumType& lhs, EnumType rhs)                \
00124 {                                                                       \
00125     return lhs = lhs ^ rhs;                                             \
00126 }
00127 
00128 /*************************************************************************************************/
00129 
00130 #define ADOBE_DEFINE_ARITHMETIC_OPS(EnumType)                           \
00131 inline EnumType operator+(EnumType a)                                   \
00132 {                                                                       \
00133     return EnumType(+adobe::implementation::promote_enum(a));           \
00134 }                                                                       \
00135                                                                         \
00136 inline EnumType operator-(EnumType a)                                   \
00137 {                                                                       \
00138     return EnumType(-adobe::implementation::promote_enum(a));           \
00139 }                                                                       \
00140                                                                         \
00141 inline EnumType operator+(EnumType lhs, EnumType rhs)                   \
00142 {                                                                       \
00143     return EnumType(adobe::implementation::promote_enum(lhs)            \
00144         + adobe::implementation::promote_enum(rhs));                    \
00145 }                                                                       \
00146                                                                         \
00147 inline EnumType operator-(EnumType lhs, EnumType rhs)                   \
00148 {                                                                       \
00149     return EnumType(adobe::implementation::promote_enum(lhs)            \
00150         - adobe::implementation::promote_enum(rhs));                    \
00151 }                                                                       \
00152                                                                         \
00153 inline EnumType operator*(EnumType lhs, EnumType rhs)                   \
00154 {                                                                       \
00155     return EnumType(adobe::implementation::promote_enum(lhs)            \
00156         * adobe::implementation::promote_enum(rhs));                    \
00157 }                                                                       \
00158                                                                         \
00159 inline EnumType operator/(EnumType lhs, EnumType rhs)                   \
00160 {                                                                       \
00161     return EnumType(adobe::implementation::promote_enum(lhs)            \
00162         / adobe::implementation::promote_enum(rhs));                    \
00163 }                                                                       \
00164                                                                         \
00165 inline EnumType operator%(EnumType lhs, EnumType rhs)                   \
00166 {                                                                       \
00167     return EnumType(adobe::implementation::promote_enum(lhs)            \
00168         % adobe::implementation::promote_enum(rhs));                    \
00169 }                                                                       \
00170                                                                         \
00171 inline EnumType& operator+=(EnumType& lhs, EnumType rhs)                \
00172 {                                                                       \
00173     return lhs = lhs + rhs;                                             \
00174 }                                                                       \
00175                                                                         \
00176 inline EnumType& operator-=(EnumType& lhs, EnumType rhs)                \
00177 {                                                                       \
00178     return lhs = lhs - rhs;                                             \
00179 }                                                                       \
00180                                                                         \
00181 inline EnumType& operator*=(EnumType& lhs, EnumType rhs)                \
00182 {                                                                       \
00183     return lhs = lhs * rhs;                                             \
00184 }                                                                       \
00185                                                                         \
00186 inline EnumType& operator/=(EnumType& lhs, EnumType rhs)                \
00187 {                                                                       \
00188     return lhs = lhs / rhs;                                             \
00189 }                                                                       \
00190                                                                         \
00191 inline EnumType& operator%=(EnumType& lhs, EnumType rhs)                \
00192 {                                                                       \
00193     return lhs = lhs % rhs;                                             \
00194 }
00195 
00196 /*************************************************************************************************/
00197 
00198 #endif
00199 
00200 /*************************************************************************************************/

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