1 
2 
3 #ifndef ZIM_TYPES_H
4 #define ZIM_TYPES_H
5 
6 #include <zim/zim.h>
7 
8 #include <ostream>
9 
10 template<typename B>
11 struct REAL_TYPEDEF{
12   typedef B base_type;
13   B v;
REAL_TYPEDEFREAL_TYPEDEF14   REAL_TYPEDEF() : v(0) {};
REAL_TYPEDEFREAL_TYPEDEF15   explicit REAL_TYPEDEF(B v) : v(v) {};
16   explicit inline operator bool() const { return v != 0; }
BREAL_TYPEDEF17   explicit inline operator B() const { return v; }
18 
19   inline bool operator==(const REAL_TYPEDEF<B>& rhs) const
20   { return v == rhs.v; }
21 };
22 
23 template<typename T> inline T& operator+= (T& lhs, const T& rhs)
24 {
25   lhs.v += rhs.v;
26   return lhs;
27 }
28 
29 template<typename T> inline T& operator+= (T& lhs, const typename T::base_type& rhs)
30 {
31   lhs.v += rhs;
32   return lhs;
33 }
34 
35 template<typename T> inline T operator+(T lhs, const T& rhs)
36 {
37   lhs += rhs;
38   return lhs;
39 }
40 
41 template<typename T> inline T& operator-=(T& lhs, const T& rhs)
42 {
43   lhs.v -= rhs.v;
44   return lhs;
45 }
46 
47 template<typename T> inline T operator-(T lhs, const T& rhs)
48 {
49   lhs -= rhs;
50   return lhs;
51 }
52 
53 template<typename T> inline bool operator< (const T& lhs, const T& rhs)
54 { return lhs.v < rhs.v; }
55 
56 template<typename T> inline bool operator> (const T& lhs, const T& rhs)
57 { return rhs < lhs; }
58 
59 template<typename T> inline bool operator<=(const T& lhs, const T& rhs)
60 { return !(lhs > rhs); }
61 
62 template<typename T> inline bool operator>=(const T& lhs, const T& rhs)
63 { return !(lhs < rhs); }
64 
65 template<typename T> inline bool operator!=(const T& lhs, const T& rhs)
66 { return !(lhs == rhs); }
67 
68 
69 template<typename B>
70 std::ostream& operator<<(std::ostream& os, const REAL_TYPEDEF<B>& obj)
71 {
72     os << obj.v;
73     return os;
74 }
75 
76 namespace zim {
77 
78 #define TYPEDEF(NAME, TYPE) struct NAME : public REAL_TYPEDEF<TYPE> { \
79 explicit NAME(TYPE v=0) : REAL_TYPEDEF<TYPE>(v) {}; }; \
80 static_assert(sizeof(NAME) == sizeof(TYPE), "");
81 
82 TYPEDEF(article_index_t, article_index_type)
83 TYPEDEF(cluster_index_t, cluster_index_type)
84 TYPEDEF(blob_index_t, blob_index_type)
85 
86 TYPEDEF(zsize_t, size_type)
87 TYPEDEF(offset_t, offset_type)
88 
89 #undef TYPEDEF
90 
91 inline offset_t& operator+= (offset_t& lhs, const zsize_t& rhs)
92 {
93   lhs.v += rhs.v;
94   return lhs;
95 }
96 
97 inline offset_t operator+(offset_t lhs, const zsize_t& rhs)
98 {
99   lhs += rhs;
100   return lhs;
101 }
102 
103 };
104 
105 #endif //ZIM_TYPES_H
106