2 #include <netinet/in.h>
5 // using namespace std;
7 template<class T> // big endian value
12 typedef be_val<value_type> my_type;
18 unsigned long *lp = (unsigned long *)((void *) &data);
19 printf ("%08lx", *lp);
25 // explicit: this constructor is not used
26 // for automatic type promotion
27 explicit be_val (value_type d) : data (ne2be (d)) {}
29 be_val (const my_type& other)
34 operator value_type () const
36 return static_cast<value_type> (be2ne (data));
38 const my_type& operator= (const value_type d)
43 const my_type& operator++ () // pre increment operator
45 value_type tmp = static_cast<value_type> (*this);
46 return *this = my_type (++tmp);
48 const my_type operator++ (int) // post increment operator
54 const my_type& operator-- () // pre increment operator
56 value_type tmp = static_cast<value_type> (*this);
57 return *this = my_type (--tmp);
59 const my_type operator-- (int) // post increment operator
65 const my_type& operator+= (const my_type& other)
67 *this = *this + other;
69 const my_type& operator-= (const my_type& other)
71 *this = *this - other;
73 const my_type& operator*= (const my_type& other)
75 *this = *this * other;
77 const my_type& operator/= (const my_type& other)
79 *this = *this / other;
81 const my_type& operator&= (const my_type& other)
83 *this = *this & other;
85 const my_type& operator|= (const my_type& other)
87 *this = *this | other;
89 const my_type& operator%= (const my_type& other)
91 *this = *this % other;
93 const my_type& operator^= (const my_type& other)
95 *this = *this ^ other;
97 const my_type& operator<<= (const my_type& other)
99 *this = *this << other;
101 const my_type& operator>>= (const my_type& other)
103 *this = *this >> other;
111 inline const be_val<C> operator+ (const be_val<C>& a, const be_val<C>& b)
113 return be_val<C>(static_cast<C> (a) + static_cast<C> (b));
117 inline const be_val<C> operator- (const be_val<C>& a, const be_val<C>& b)
119 return be_val<C>(static_cast<C> (a) - static_cast<C> (b));
123 inline const be_val<C> operator* (const be_val<C>& a, const be_val<C>& b)
125 return be_val<C>(static_cast<C> (a) * static_cast<C> (b));
129 inline const be_val<C> operator/ (const be_val<C>& a, const be_val<C>& b)
131 return be_val<C>(static_cast<C> (a) / static_cast<C> (b));
135 inline const be_val<C> operator% (const be_val<C>& a, const be_val<C>& b)
137 return be_val<C>(static_cast<C> (a) % static_cast<C> (b));
141 inline const be_val<C> operator^ (const be_val<C>& a, const be_val<C>& b)
143 return be_val<C>(static_cast<C> (a) ^ static_cast<C> (b));
147 inline const be_val<C> operator& (const be_val<C>& a, const be_val<C>& b)
149 return be_val<C>(static_cast<C> (a) & static_cast<C> (b));
153 inline const be_val<C> operator| (const be_val<C>& a, const be_val<C>& b)
155 return be_val<C>(static_cast<C> (a) | static_cast<C> (b));
159 inline const be_val<C> operator<< (const be_val<C>& a, const be_val<C>& b)
161 return be_val<C>(static_cast<C> (a) << static_cast<C> (b));
165 inline const be_val<C> operator>> (const be_val<C>& a, const be_val<C>& b)
167 return be_val<C>(static_cast<C> (a) >> static_cast<C> (b));
171 inline bool operator< (const be_val<C>& a, const be_val<C>& b)
173 return static_cast<C> (a) < static_cast<C> (b);
177 inline bool operator> (const be_val<C>& a, const be_val<C>& b)
179 return static_cast<C> (a) > static_cast<C> (b);
183 inline bool operator<= (const be_val<C>& a, const be_val<C>& b)
185 return static_cast<C> (a) <= static_cast<C> (b);
189 inline bool operator>= (const be_val<C>& a, const be_val<C>& b)
191 return static_cast<C> (a) >= static_cast<C> (b);
195 inline bool operator== (const be_val<C>& a, const be_val<C>& b)
197 return static_cast<C> (a) == static_cast<C> (b);
201 inline bool operator!= (const be_val<C>& a, const be_val<C>& b)
203 return static_cast<C> (a) != static_cast<C> (b);