… | |
… | |
42 | # define NOTHROW throw() |
42 | # define NOTHROW throw() |
43 | # define THROW(x) throw x |
43 | # define THROW(x) throw x |
44 | #endif |
44 | #endif |
45 | |
45 | |
46 | namespace byteorder { |
46 | namespace byteorder { |
47 | static uint32_t e () |
47 | static unsigned char e () |
48 | { |
48 | { |
49 | char c [4] = { 0x11, 0x22, 0x33, 0x44 }; |
49 | const uint32_t u = 0x11223344; |
50 | return *(uint32_t *)c; |
50 | return *(unsigned char *)u; |
51 | } |
51 | } |
52 | |
52 | |
53 | static bool big_endian () { return e () == 0x11223344; }; |
53 | static bool big_endian () { return e () == 0x11; }; |
54 | static bool network () { return big_endian (); }; |
54 | static bool network () { return big_endian (); }; |
55 | static bool little_endian () { return e () == 0x44332211; }; |
55 | static bool little_endian () { return e () == 0x44; }; |
56 | static bool vax () { return little_endian (); }; |
56 | static bool vax () { return little_endian (); }; |
57 | }; |
57 | }; |
58 | |
58 | |
59 | // various utility functions |
59 | // various utility functions |
60 | template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } |
60 | template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } |
61 | template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } |
61 | template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } |