aboutsummaryrefslogtreecommitdiff
path: root/src/stable/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/util.h')
-rw-r--r--src/stable/util.h294
1 files changed, 147 insertions, 147 deletions
diff --git a/src/stable/util.h b/src/stable/util.h
index 4514281..ab9cd08 100644
--- a/src/stable/util.h
+++ b/src/stable/util.h
@@ -25,158 +25,158 @@
25 25
26namespace Bu 26namespace Bu
27{ 27{
28 /** 28 /**
29 * Swap the value of two variables, uses references, so it's pretty safe. 29 * Swap the value of two variables, uses references, so it's pretty safe.
30 * Objects passed in must support a basic assignemnt operator (=); 30 * Objects passed in must support a basic assignemnt operator (=);
31 *@param a Variable to recieve the value of parameter b 31 *@param a Variable to recieve the value of parameter b
32 *@param b Variable to recieve the value of parameter a 32 *@param b Variable to recieve the value of parameter a
33 */ 33 */
34 template<typename item> 34 template<typename item>
35 void swap( item &a, item &b ) 35 void swap( item &a, item &b )
36 { 36 {
37 item tmp = a; 37 item tmp = a;
38 a = b; 38 a = b;
39 b = tmp; 39 b = tmp;
40 } 40 }
41 41
42 /** 42 /**
43 * Finds the lesser of the two objects, objects passed in must be 43 * Finds the lesser of the two objects, objects passed in must be
44 * less-than-comparable. 44 * less-than-comparable.
45 *@param a A value to test. 45 *@param a A value to test.
46 *@param b Another value to test. 46 *@param b Another value to test.
47 *@returns A reference to the lesser of a or b. 47 *@returns A reference to the lesser of a or b.
48 */ 48 */
49 template<typename item> 49 template<typename item>
50 const item &buMin( const item &a, const item &b ) 50 const item &buMin( const item &a, const item &b )
51 { 51 {
52 return a<b?a:b; 52 return a<b?a:b;
53 } 53 }
54 54
55 /** 55 /**
56 * Finds the lesser of the two objects, objects passed in must be 56 * Finds the lesser of the two objects, objects passed in must be
57 * less-than-comparable. 57 * less-than-comparable.
58 *@param a A value to test. 58 *@param a A value to test.
59 *@param b Another value to test. 59 *@param b Another value to test.
60 *@returns A reference to the lesser of a or b. 60 *@returns A reference to the lesser of a or b.
61 */ 61 */
62 template<typename item> 62 template<typename item>
63 item &buMin( item &a, item &b ) 63 item &buMin( item &a, item &b )
64 { 64 {
65 return a<b?a:b; 65 return a<b?a:b;
66 } 66 }
67 67
68 /** 68 /**
69 * Finds the greater of the two objects, objects passed in must be 69 * Finds the greater of the two objects, objects passed in must be
70 * less-than-comparable. 70 * less-than-comparable.
71 *@param a A value to test. 71 *@param a A value to test.
72 *@param b Another value to test. 72 *@param b Another value to test.
73 *@returns A reference to the greater of a or b. 73 *@returns A reference to the greater of a or b.
74 */ 74 */
75 template<typename item> 75 template<typename item>
76 const item &buMax( const item &a, const item &b ) 76 const item &buMax( const item &a, const item &b )
77 { 77 {
78 return b<a?a:b; 78 return b<a?a:b;
79 } 79 }
80 80
81 /** 81 /**
82 * Finds the greater of the two objects, objects passed in must be 82 * Finds the greater of the two objects, objects passed in must be
83 * less-than-comparable. 83 * less-than-comparable.
84 *@param a A value to test. 84 *@param a A value to test.
85 *@param b Another value to test. 85 *@param b Another value to test.
86 *@returns A reference to the greater of a or b. 86 *@returns A reference to the greater of a or b.
87 */ 87 */
88 template<typename item> 88 template<typename item>
89 item &buMax( item &a, item &b ) 89 item &buMax( item &a, item &b )
90 { 90 {
91 return b<a?a:b; 91 return b<a?a:b;
92 } 92 }
93 93
94 /** 94 /**
95 * Given three objects this finds the one between the other two. 95 * Given three objects this finds the one between the other two.
96 *@param a A value to test. 96 *@param a A value to test.
97 *@param b Another value to test. 97 *@param b Another value to test.
98 *@param c Yet another value to test. 98 *@param c Yet another value to test.
99 *@returns A reference to the mid-value of a, b, and c. 99 *@returns A reference to the mid-value of a, b, and c.
100 */ 100 */
101 template<typename item> 101 template<typename item>
102 const item &buMid( const item &a, const item &b, const item &c ) 102 const item &buMid( const item &a, const item &b, const item &c )
103 { 103 {
104 return buMin( buMax( a, b ), c ); 104 return buMin( buMax( a, b ), c );
105 } 105 }
106 106
107 /** 107 /**
108 * Given three objects this finds the one between the other two. 108 * Given three objects this finds the one between the other two.
109 *@param a A value to test. 109 *@param a A value to test.
110 *@param b Another value to test. 110 *@param b Another value to test.
111 *@param c Yet another value to test. 111 *@param c Yet another value to test.
112 *@returns A reference to the mid-value of a, b, and c. 112 *@returns A reference to the mid-value of a, b, and c.
113 */ 113 */
114 template<typename item> 114 template<typename item>
115 item &buMid( item &a, item &b, item &c ) 115 item &buMid( item &a, item &b, item &c )
116 { 116 {
117 return buMin( buMax( a, b ), c ); 117 return buMin( buMax( a, b ), c );
118 } 118 }
119 119
120 // 120 //
121 // Basic comparison functors 121 // Basic comparison functors
122 // 122 //
123 /** 123 /**
124 * Simple less-than comparison functor. Objects being used should be 124 * Simple less-than comparison functor. Objects being used should be
125 * less-than-comparable. 125 * less-than-comparable.
126 */ 126 */
127 template<typename item> 127 template<typename item>
128 struct __basicLTCmp 128 struct __basicLTCmp
129 { 129 {
130 bool operator()( const item &a, const item &b ) 130 bool operator()( const item &a, const item &b )
131 { 131 {
132 return a < b; 132 return a < b;
133 } 133 }
134 }; 134 };
135 135
136 /** 136 /**
137 * Simple greater-than comparison functor. Objects being used should be 137 * Simple greater-than comparison functor. Objects being used should be
138 * greater-than-comparable. 138 * greater-than-comparable.
139 */ 139 */
140 template<typename item> 140 template<typename item>
141 struct __basicGTCmp 141 struct __basicGTCmp
142 { 142 {
143 bool operator()( const item &a, const item &b ) 143 bool operator()( const item &a, const item &b )
144 { 144 {
145 return a > b; 145 return a > b;
146 } 146 }
147 }; 147 };
148 148
149 /** 149 /**
150 * As __basicLTCmp but dereferences the passed in pointers before comparing. 150 * As __basicLTCmp but dereferences the passed in pointers before comparing.
151 */ 151 */
152 template<typename item> 152 template<typename item>
153 struct __basicPtrLTCmp 153 struct __basicPtrLTCmp
154 { 154 {
155 bool operator()( const item &a, const item &b ) 155 bool operator()( const item &a, const item &b )
156 { 156 {
157 return *a < *b; 157 return *a < *b;
158 } 158 }
159 }; 159 };
160 160
161 /** 161 /**
162 * As __basicGTCmp but dereferences the passed in pointers before comparing. 162 * As __basicGTCmp but dereferences the passed in pointers before comparing.
163 */ 163 */
164 template<typename item> 164 template<typename item>
165 struct __basicPtrGTCmp 165 struct __basicPtrGTCmp
166 { 166 {
167 bool operator()( const item &a, const item &b ) 167 bool operator()( const item &a, const item &b )
168 { 168 {
169 return *a > *b; 169 return *a > *b;
170 } 170 }
171 }; 171 };
172 172
173 /** 173 /**
174 * Get the number of days in the month in the gregorian calendar, taking 174 * Get the number of days in the month in the gregorian calendar, taking
175 * leap years into account. 175 * leap years into account.
176 */ 176 */
177 int getDaysInMonth( int iMonth, int iYear ); 177 int getDaysInMonth( int iMonth, int iYear );
178 178
179 void memcpy( void *pDest, const void *pSrc, size_t iBytes ); 179 void memcpy( void *pDest, const void *pSrc, size_t iBytes );
180}; 180};
181 181
182#endif 182#endif