41 #ifndef STRONG_TYPEDEF_HPP 42 #define STRONG_TYPEDEF_HPP 45 #define STRONG_TYPEDEF(original_type, new_type) typedef original_type new_type 46 #define STRONG_TYPEDEF_FORWARD_DECL(original_type, new_type) typedef original_type new_type 48 template <
typename Dest,
typename Source>
51 return static_cast<Dest
>(source);
55 template<
typename Dest,
typename Source>
56 inline Dest to_strongtype_cast(Source source)
58 return static_cast<Dest
>(source);
63 #include <boost/functional/hash/hash.hpp> 64 template <
typename Dest,
typename Source>
67 return static_cast<Dest
>(source.GetContent());
71 template<
typename Dest,
typename Source>
72 inline Dest to_strongtype_cast(Source source)
78 #define STRONG_TYPEDEF_FORWARD_DECL(OriginalType, NewType) class NewType 79 #define STRONG_TYPEDEF(OriginalType, NewType) \ 85 OriginalType content; \ 89 explicit NewType(const OriginalType _content) : content(_content) \ 93 friend std::ostream& operator<<(std::ostream& os, const NewType element); \ 95 inline OriginalType GetContent() const \ 101 NewType& operator--() \ 108 NewType& operator++() \ 115 NewType operator++(int) \ 118 return NewType(content - 1); \ 122 NewType operator+(const NewType& other) const \ 124 return NewType(content + other.content); \ 126 NewType operator+(const OriginalType& other) const \ 128 return NewType(content + other); \ 132 NewType operator+=(const NewType& other) \ 134 content += other.content; \ 137 NewType operator+=(const OriginalType& other) \ 144 NewType operator-(const NewType& other) const \ 146 return NewType(content - other.content); \ 148 NewType operator-(const OriginalType& other) const \ 150 return NewType(content - other); \ 154 NewType operator-() const \ 156 return NewType(-content); \ 160 NewType operator*(const NewType& other) const \ 162 return NewType(content * other.content); \ 164 NewType operator*(const OriginalType& other) const \ 166 return NewType(content * other); \ 170 bool operator<(const NewType& other) const \ 172 return content < other.content; \ 174 bool operator<(const OriginalType& other) const \ 176 return content < other; \ 180 bool operator<=(const NewType& other) const \ 182 return content <= other.content; \ 186 bool operator>(const NewType& other) const \ 188 return content > other.content; \ 190 bool operator>(const OriginalType& other) const \ 192 return content > other; \ 196 bool operator>=(const NewType& other) const \ 198 return content >= other.content; \ 202 bool operator==(const NewType& other) const \ 204 return content == other.content; \ 206 bool operator==(const OriginalType& other) const \ 208 return content == other; \ 212 bool operator!=(const NewType& other) const \ 214 return content != other.content; \ 216 bool operator!=(const OriginalType& other) const \ 218 return content != other; \ 221 inline std::ostream& operator<<(std::ostream& os, const NewType element) \ 223 os << element.content; \ 230 struct hash<NewType> : public unary_function<NewType, size_t> \ 232 size_t operator()(NewType var) const \ 235 return hasher(static_cast<int>(var.GetContent())); \ 244 #define UINT_STRONG_TYPEDEF(new_type) STRONG_TYPEDEF(unsigned int, new_type) 245 #define UINT_STRONG_TYPEDEF_FORWARD_DECL(new_type) STRONG_TYPEDEF_FORWARD_DECL(unsigned int, new_type) Dest from_strongtype_cast(Source source)