diff options
Diffstat (limited to '')
-rw-r--r-- | src/bitstring.h | 51 | ||||
-rw-r--r-- | src/crypt.cpp | 7 | ||||
-rw-r--r-- | src/crypt.h | 11 | ||||
-rw-r--r-- | src/doxy/formatting.dox | 35 | ||||
-rw-r--r-- | src/doxy/groups.dox | 10 | ||||
-rw-r--r-- | src/doxy/main.dox | 1 | ||||
-rw-r--r-- | src/doxy/streams.dox | 13 | ||||
-rw-r--r-- | src/fbasicstring.h | 35 | ||||
-rw-r--r-- | src/hash.h | 16 | ||||
-rw-r--r-- | src/ito.h | 2 | ||||
-rw-r--r-- | src/list.h | 2 | ||||
-rw-r--r-- | src/set.h | 3 | ||||
-rw-r--r-- | src/tests/console.cpp | 36 | ||||
-rw-r--r-- | src/util.h | 68 |
14 files changed, 205 insertions, 85 deletions
diff --git a/src/bitstring.h b/src/bitstring.h index 35f854f..b5f1ada 100644 --- a/src/bitstring.h +++ b/src/bitstring.h | |||
@@ -202,57 +202,6 @@ namespace Bu | |||
202 | */ | 202 | */ |
203 | long toLong( long iStart = 0, long iSize = 32 ); | 203 | long toLong( long iStart = 0, long iSize = 32 ); |
204 | 204 | ||
205 | /** | ||
206 | * Converts the data into a human-readable SString object. SString is | ||
207 | * used to make transport of the string and management very simple. | ||
208 | * Since BitStrings will generally be longer than your average strip of | ||
209 | * ints a faculty is included and turned on by default that will insert | ||
210 | * spacers into the output text every 8 places. For debugging work, | ||
211 | * this is definately reccomended. | ||
212 | *@param bAddSpacers Leave set to true in order to have the output | ||
213 | * broken into logical groupings of 8 bits per block. Set to off to | ||
214 | * have a harder | ||
215 | * to read solid block of bits. | ||
216 | *@returns A SString object containing the produced string. | ||
217 | */ | ||
218 | //std::string toString( bool bAddSpacers = true ); | ||
219 | |||
220 | // Utility | ||
221 | /** | ||
222 | * Converts the given number of bits into the smallest allocatable unit, | ||
223 | * which is bytes in C and on most systems nowadays. This is the | ||
224 | * minimum number of bytes needed to contain the given number of bits, | ||
225 | * so there is generally some slop if they are not evenly divisible. | ||
226 | *@param iBits The number of bits you wish to use. | ||
227 | *@returns The number of bytes you will need to contain the given number | ||
228 | * of bits. | ||
229 | */ | ||
230 | //static long bitsToBytes( long iBits ); | ||
231 | |||
232 | /** | ||
233 | * Writes all data in the BitString, including a small header block | ||
234 | * describing the number of bits in the BitString to the file described | ||
235 | * by the given file descriptor. The data writen is purely sequential | ||
236 | * and probably not too easy to read by other mechanisms, although the | ||
237 | * readFromFile function should always be able to do it. This function | ||
238 | * does not open nor close the file pointed to by fh. | ||
239 | *@param fh The file descriptor of the file to write the data to. | ||
240 | *@returns true if the operation completed without error, false | ||
241 | * otherwise. | ||
242 | */ | ||
243 | //bool writeToFile( FILE *fh ); | ||
244 | |||
245 | /** | ||
246 | * Reads data formatted by writeToFile and clears out any data that may | ||
247 | * have been in the BitString. This function preserves nothing in the | ||
248 | * original BitString that it may be replacing. This function does not | ||
249 | * open nor close the file pointed to by fh. | ||
250 | *@param fh The file descriptor to try to read the data from. | ||
251 | *@returns true if the operation completed without error, false | ||
252 | * otherwise. | ||
253 | */ | ||
254 | //bool readFromFile( FILE *fh ); | ||
255 | |||
256 | //operators | 205 | //operators |
257 | BitString &operator=( const BitString &xSrc ); | 206 | BitString &operator=( const BitString &xSrc ); |
258 | BitString operator~(); | 207 | BitString operator~(); |
diff --git a/src/crypt.cpp b/src/crypt.cpp index 9111cda..dbf90ab 100644 --- a/src/crypt.cpp +++ b/src/crypt.cpp | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #include "bu/crypt.h" | 8 | #include "bu/crypt.h" |
2 | #include "bu/md5.h" | 9 | #include "bu/md5.h" |
3 | #include "bu/base64.h" | 10 | #include "bu/base64.h" |
diff --git a/src/crypt.h b/src/crypt.h index 1ea1b85..a38ff52 100644 --- a/src/crypt.h +++ b/src/crypt.h | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #ifndef BU_CRYPT_H | 8 | #ifndef BU_CRYPT_H |
2 | #define BU_CRYPT_H | 9 | #define BU_CRYPT_H |
3 | 10 | ||
@@ -5,8 +12,8 @@ | |||
5 | 12 | ||
6 | namespace Bu | 13 | namespace Bu |
7 | { | 14 | { |
8 | FString cryptPass( const FString &sPass, const FString &sSalt ); | 15 | FString cryptPass( const Bu::FString &sPass, const Bu::FString &sSalt ); |
9 | FString cryptPass( const FString &sPass ); | 16 | FString cryptPass( const Bu::FString &sPass ); |
10 | }; | 17 | }; |
11 | 18 | ||
12 | #endif | 19 | #endif |
diff --git a/src/doxy/formatting.dox b/src/doxy/formatting.dox new file mode 100644 index 0000000..7b440cb --- /dev/null +++ b/src/doxy/formatting.dox | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | /** | ||
9 | *@page howto_formatting Formatting data for streams and the console. | ||
10 | * | ||
11 | * Libbu++ provides a powerful and flexible interface for writing formatted | ||
12 | * data easily to any Stream. This is implemented as a seperate set of | ||
13 | * classes from the basic Stream system in order to simplify both systems and | ||
14 | * provide additional flexibility and organization. | ||
15 | * | ||
16 | *@section secBasics The Basics: Writing to the console (standard i/o) | ||
17 | * Libbu++ provides the global variable Bu::sio already instantiated and ready | ||
18 | * to be used to access the standard input and output via the Bu::Formatter | ||
19 | * class. If you are familiar with the STL cout then you're practically done. | ||
20 | * A quick example may be best. | ||
21 | *@code | ||
22 | #include <bu/sio.h> | ||
23 | using namespace Bu; | ||
24 | |||
25 | int main() | ||
26 | { | ||
27 | int i = 47; | ||
28 | |||
29 | sio << "Hello, world." << sio.nl | ||
30 | << "Here is a number: " << i << sio.nl; | ||
31 | |||
32 | return 0; | ||
33 | } | ||
34 | @endcode | ||
35 | */ | ||
diff --git a/src/doxy/groups.dox b/src/doxy/groups.dox index 9b54950..285923c 100644 --- a/src/doxy/groups.dox +++ b/src/doxy/groups.dox | |||
@@ -6,26 +6,26 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | /** | 8 | /** |
9 | *@defgroup Threading | 9 | *@defgroup Threading Threading |
10 | * Threads are awesome. | 10 | * Threads are awesome. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | /** | 13 | /** |
14 | *@defgroup Serving | 14 | *@defgroup Serving Serving |
15 | * Serving data is pretty cool too. | 15 | * Serving data is pretty cool too. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | /** | 18 | /** |
19 | *@defgroup Containers | 19 | *@defgroup Containers Containers |
20 | * Containers for data. | 20 | * Containers for data. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /** | 23 | /** |
24 | *@defgroup Taf | 24 | *@defgroup Taf Taf |
25 | * Taf is the best! | 25 | * Taf is the best! |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /** | 28 | /** |
29 | *@defgroup Streams | 29 | *@defgroup Streams Streams |
30 | * Streams are for data. | 30 | * Streams are for data. |
31 | */ | 31 | */ |
diff --git a/src/doxy/main.dox b/src/doxy/main.dox index 6030f0c..5e822e1 100644 --- a/src/doxy/main.dox +++ b/src/doxy/main.dox | |||
@@ -18,6 +18,7 @@ | |||
18 | * comprehensive guides and API reference, but doesn't yet. For now check out | 18 | * comprehensive guides and API reference, but doesn't yet. For now check out |
19 | * these sections: | 19 | * these sections: |
20 | * - @ref howto_streams | 20 | * - @ref howto_streams |
21 | * - @ref howto_formatting | ||
21 | * - @ref howto_archives | 22 | * - @ref howto_archives |
22 | * - @ref howto_threading | 23 | * - @ref howto_threading |
23 | * - @ref howto_servers | 24 | * - @ref howto_servers |
diff --git a/src/doxy/streams.dox b/src/doxy/streams.dox index 8217210..9655743 100644 --- a/src/doxy/streams.dox +++ b/src/doxy/streams.dox | |||
@@ -44,11 +44,10 @@ | |||
44 | * data. | 44 | * data. |
45 | * | 45 | * |
46 | *@section difference How are libbu++ streams different form stl streams? | 46 | *@section difference How are libbu++ streams different form stl streams? |
47 | * While not globally true, many stl streams are designed for formatting the | 47 | * The most basic difference is that libbu++ streams are geared more towards a |
48 | * data that flows through the stream, that means that when you attempt to | 48 | * lower level feel, giving you easy and more direct access to many features, |
49 | * write a uint32_t into a standard stream it can be difficult to predict what | 49 | * while seperating all of the formatting code used for console I/O and number |
50 | * the result will be, will it be the binary representation or a textual | 50 | * to text conversion, etc, in a seperate place. |
51 | * conversion? | ||
52 | * | 51 | * |
53 | * Libbu++ streams are very direct about how the data is handled. All end-point | 52 | * Libbu++ streams are very direct about how the data is handled. All end-point |
54 | * streams will always handle the data that you provide or request without any | 53 | * streams will always handle the data that you provide or request without any |
@@ -59,8 +58,8 @@ | |||
59 | * easy as possible to write general code that was as easy as possible to | 58 | * easy as possible to write general code that was as easy as possible to |
60 | * extend, and as clear as possible. We have accomplished this by making | 59 | * extend, and as clear as possible. We have accomplished this by making |
61 | * streams simple, yet flexible, with a clear API and a flexible filter system | 60 | * streams simple, yet flexible, with a clear API and a flexible filter system |
62 | * that something geared towards more general formatting, conversion, and | 61 | * that something geared towards more general formatting, conversion can't |
63 | * operator-only access can't touch. | 62 | * touch. |
64 | * | 63 | * |
65 | *@section usage Using streams directly | 64 | *@section usage Using streams directly |
66 | * To create a stream depends on the type of stream that you're interested in, | 65 | * To create a stream depends on the type of stream that you're interested in, |
diff --git a/src/fbasicstring.h b/src/fbasicstring.h index b9e4871..fbfc5ef 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h | |||
@@ -706,6 +706,7 @@ namespace Bu | |||
706 | /** | 706 | /** |
707 | * Append another FString to this one. | 707 | * Append another FString to this one. |
708 | *@param sData (MyType &) The FString to append. | 708 | *@param sData (MyType &) The FString to append. |
709 | *@param nStart Start position in sData to start copying from. | ||
709 | *@param nLen How much data to append. | 710 | *@param nLen How much data to append. |
710 | */ | 711 | */ |
711 | void append( const MyType & sData, long nStart, long nLen ) | 712 | void append( const MyType & sData, long nStart, long nLen ) |
@@ -715,6 +716,11 @@ namespace Bu | |||
715 | append( sData.getStr(), nStart, nLen ); | 716 | append( sData.getStr(), nStart, nLen ); |
716 | } | 717 | } |
717 | 718 | ||
719 | /** | ||
720 | * Append data to this FString using the passed in iterator as a base. | ||
721 | * The iterator is const, it is not changed. | ||
722 | *@param s Iterator from any compatible FBasicString to copy data from. | ||
723 | */ | ||
718 | void append( const const_iterator &s ) | 724 | void append( const const_iterator &s ) |
719 | { | 725 | { |
720 | if( !s.isValid() ) | 726 | if( !s.isValid() ) |
@@ -731,11 +737,24 @@ namespace Bu | |||
731 | } | 737 | } |
732 | } | 738 | } |
733 | 739 | ||
740 | /** | ||
741 | * Append data to this FString using the passed in iterator as a base. | ||
742 | * The iterator is const, it is not changed. | ||
743 | *@param s Iterator from any compatible FBasicString to copy data from. | ||
744 | */ | ||
734 | void append( const iterator &s ) // I get complainst without this one | 745 | void append( const iterator &s ) // I get complainst without this one |
735 | { | 746 | { |
736 | append( const_iterator( s ) ); | 747 | append( const_iterator( s ) ); |
737 | } | 748 | } |
738 | 749 | ||
750 | /** | ||
751 | * Append data to this FString using the passed in iterator as a base, | ||
752 | * and copy data until the ending iterator is reached. The character | ||
753 | * at the ending iterator is not copied. | ||
754 | * The iterators are const, they are not changed. | ||
755 | *@param s Iterator from any compatible FBasicString to copy data from. | ||
756 | *@param e Iterator to stop copying at. | ||
757 | */ | ||
739 | void append( const const_iterator &s, const const_iterator &e ) | 758 | void append( const const_iterator &s, const const_iterator &e ) |
740 | { | 759 | { |
741 | if( !s.isValid() ) | 760 | if( !s.isValid() ) |
@@ -885,10 +904,6 @@ namespace Bu | |||
885 | } | 904 | } |
886 | 905 | ||
887 | /** | 906 | /** |
888 | *@todo void prepend( const chr &cData ) | ||
889 | */ | ||
890 | |||
891 | /** | ||
892 | * Clear all data from the string. | 907 | * Clear all data from the string. |
893 | */ | 908 | */ |
894 | void clear() | 909 | void clear() |
@@ -1079,7 +1094,7 @@ namespace Bu | |||
1079 | 1094 | ||
1080 | /** | 1095 | /** |
1081 | * Plus equals operator for FString. | 1096 | * Plus equals operator for FString. |
1082 | *@param pData (const MyType &) The FString to append to your FString. | 1097 | *@param rSrc (const MyType &) The FString to append to your FString. |
1083 | */ | 1098 | */ |
1084 | MyType &operator+=( const MyType &rSrc ) | 1099 | MyType &operator+=( const MyType &rSrc ) |
1085 | { | 1100 | { |
@@ -1093,7 +1108,7 @@ namespace Bu | |||
1093 | 1108 | ||
1094 | /** | 1109 | /** |
1095 | * Plus equals operator for FString. | 1110 | * Plus equals operator for FString. |
1096 | *@param pData (const chr) The character to append to your FString. | 1111 | *@param cData (const chr) The character to append to your FString. |
1097 | */ | 1112 | */ |
1098 | MyType &operator+=( const chr cData ) | 1113 | MyType &operator+=( const chr cData ) |
1099 | { | 1114 | { |
@@ -1603,7 +1618,8 @@ namespace Bu | |||
1603 | 1618 | ||
1604 | /** | 1619 | /** |
1605 | * Find the index of the first occurrance of cChar | 1620 | * Find the index of the first occurrance of cChar |
1606 | *@param sText (const chr *) The string to search for. | 1621 | *@param cChar The character to search for. |
1622 | *@param iStart The position in the string to start searching from. | ||
1607 | *@returns (long) The index of the first occurrance. -1 for not found. | 1623 | *@returns (long) The index of the first occurrance. -1 for not found. |
1608 | */ | 1624 | */ |
1609 | long findIdx( const chr cChar, long iStart=0 ) const | 1625 | long findIdx( const chr cChar, long iStart=0 ) const |
@@ -1619,8 +1635,9 @@ namespace Bu | |||
1619 | 1635 | ||
1620 | /** | 1636 | /** |
1621 | * Find the index of the first occurrance of sText | 1637 | * Find the index of the first occurrance of sText |
1622 | *@param cChar (const chr) The character to search for. | 1638 | *@param sText The null-terminated string to search for. |
1623 | *@returns (long) The index of the first occurrance. -1 for not found. | 1639 | *@param iStart The position in the string to start searching from. |
1640 | *@returns The index of the first occurrance. -1 for not found. | ||
1624 | */ | 1641 | */ |
1625 | long findIdx( const chr *sText, long iStart=0 ) const | 1642 | long findIdx( const chr *sText, long iStart=0 ) const |
1626 | { | 1643 | { |
@@ -17,8 +17,8 @@ | |||
17 | #include "bu/exceptionbase.h" | 17 | #include "bu/exceptionbase.h" |
18 | #include "bu/list.h" | 18 | #include "bu/list.h" |
19 | #include "bu/util.h" | 19 | #include "bu/util.h" |
20 | ///#include "archival.h" | 20 | //#include "archival.h" |
21 | ///#include "archive.h" | 21 | //#include "archive.h" |
22 | 22 | ||
23 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) | 23 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) |
24 | 24 | ||
@@ -37,6 +37,14 @@ namespace Bu | |||
37 | template<typename T> | 37 | template<typename T> |
38 | bool __cmpHashKeys( const T &a, const T &b ); | 38 | bool __cmpHashKeys( const T &a, const T &b ); |
39 | 39 | ||
40 | /** | ||
41 | * Default functor used to compute the size of hash tables. This version | ||
42 | * effectively doubles the size of the table when space is low, ensuring | ||
43 | * that you always wind up with an odd number for the table size. A | ||
44 | * better but slower option is to always find the next prime number that's | ||
45 | * above double your current table size, but that has the potential to be | ||
46 | * slower. | ||
47 | */ | ||
40 | struct __calcNextTSize_fast | 48 | struct __calcNextTSize_fast |
41 | { | 49 | { |
42 | uint32_t operator()( uint32_t nCapacity, uint32_t, uint32_t nDeleted ) const | 50 | uint32_t operator()( uint32_t nCapacity, uint32_t, uint32_t nDeleted ) const |
@@ -677,7 +685,7 @@ namespace Bu | |||
677 | 685 | ||
678 | /** | 686 | /** |
679 | * Get the value behind this iterator. | 687 | * Get the value behind this iterator. |
680 | *@returs (value_type &) The value behind this iterator. | 688 | *@returns (value_type &) The value behind this iterator. |
681 | */ | 689 | */ |
682 | value &getValue() | 690 | value &getValue() |
683 | { | 691 | { |
@@ -804,7 +812,7 @@ namespace Bu | |||
804 | 812 | ||
805 | /** | 813 | /** |
806 | * Get the value behind this iterator. | 814 | * Get the value behind this iterator. |
807 | *@returs (value_type &) The value behind this iterator. | 815 | *@returns (value_type &) The value behind this iterator. |
808 | */ | 816 | */ |
809 | const value &getValue() const | 817 | const value &getValue() const |
810 | { | 818 | { |
@@ -94,7 +94,7 @@ namespace Bu | |||
94 | * the function that actually makes up the thread, it simply calls the | 94 | * the function that actually makes up the thread, it simply calls the |
95 | * run member function in an OO-friendly way. This is what allows us to | 95 | * run member function in an OO-friendly way. This is what allows us to |
96 | * use member variables from within the thread itself. | 96 | * use member variables from within the thread itself. |
97 | *@param Should always be this. | 97 | *@param pThread Should always be this. |
98 | *@returns This is specified by posix, I'm not sure yet. | 98 | *@returns This is specified by posix, I'm not sure yet. |
99 | */ | 99 | */ |
100 | static void *threadRunner( void *pThread ); | 100 | static void *threadRunner( void *pThread ); |
@@ -611,7 +611,7 @@ namespace Bu | |||
611 | 611 | ||
612 | /** | 612 | /** |
613 | * Erase an item from the list if you already know the item. | 613 | * Erase an item from the list if you already know the item. |
614 | *@param ob The item to find and erase. | 614 | *@param v The item to find and erase. |
615 | */ | 615 | */ |
616 | void erase( const value &v ) | 616 | void erase( const value &v ) |
617 | { | 617 | { |
@@ -184,9 +184,8 @@ namespace Bu | |||
184 | } | 184 | } |
185 | 185 | ||
186 | /** | 186 | /** |
187 | * Insert a value (v) under key (k) into the hash table | 187 | * Insert key (k) into the set |
188 | *@param k (key_type) Key to list the value under. | 188 | *@param k (key_type) Key to list the value under. |
189 | *@param v (value_type) Value to store in the hash table. | ||
190 | */ | 189 | */ |
191 | virtual void insert( key k ) | 190 | virtual void insert( key k ) |
192 | { | 191 | { |
diff --git a/src/tests/console.cpp b/src/tests/console.cpp new file mode 100644 index 0000000..628482b --- /dev/null +++ b/src/tests/console.cpp | |||
@@ -0,0 +1,36 @@ | |||
1 | #include <bu/sio.h> | ||
2 | using namespace Bu; | ||
3 | |||
4 | #include <iostream> | ||
5 | using namespace std; | ||
6 | |||
7 | typedef struct Counter | ||
8 | { | ||
9 | Counter() : i( 0 ) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | int get() | ||
14 | { | ||
15 | i++; | ||
16 | return i-1; | ||
17 | } | ||
18 | |||
19 | int i; | ||
20 | } Counter; | ||
21 | |||
22 | template<typename a> | ||
23 | void runtest( a &out ) | ||
24 | { | ||
25 | Counter c; | ||
26 | out << c.get() << ", " << c.get() << ", " << c.get() << ", " << c.get() << ", " << c.get() << "\n"; | ||
27 | } | ||
28 | |||
29 | int main() | ||
30 | { | ||
31 | runtest( cout ); | ||
32 | runtest( sio ); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
@@ -19,6 +19,12 @@ | |||
19 | 19 | ||
20 | namespace Bu | 20 | namespace Bu |
21 | { | 21 | { |
22 | /** | ||
23 | * Swap the value of two variables, uses references, so it's pretty safe. | ||
24 | * Objects passed in must support a basic assignemnt operator (=); | ||
25 | *@param a Variable to recieve the value of parameter b | ||
26 | *@param b Variable to recieve the value of parameter a | ||
27 | */ | ||
22 | template<typename item> | 28 | template<typename item> |
23 | void swap( item &a, item &b ) | 29 | void swap( item &a, item &b ) |
24 | { | 30 | { |
@@ -27,36 +33,78 @@ namespace Bu | |||
27 | b = tmp; | 33 | b = tmp; |
28 | } | 34 | } |
29 | 35 | ||
36 | /** | ||
37 | * Finds the lesser of the two objects, objects passed in must be | ||
38 | * less-than-comparable. | ||
39 | *@param a A value to test. | ||
40 | *@param b Another value to test. | ||
41 | *@returns A reference to the lesser of a or b. | ||
42 | */ | ||
30 | template<typename item> | 43 | template<typename item> |
31 | const item &min( const item &a, const item &b ) | 44 | const item &min( const item &a, const item &b ) |
32 | { | 45 | { |
33 | return a<b?a:b; | 46 | return a<b?a:b; |
34 | } | 47 | } |
35 | 48 | ||
49 | /** | ||
50 | * Finds the lesser of the two objects, objects passed in must be | ||
51 | * less-than-comparable. | ||
52 | *@param a A value to test. | ||
53 | *@param b Another value to test. | ||
54 | *@returns A reference to the lesser of a or b. | ||
55 | */ | ||
36 | template<typename item> | 56 | template<typename item> |
37 | item &min( item &a, item &b ) | 57 | item &min( item &a, item &b ) |
38 | { | 58 | { |
39 | return a<b?a:b; | 59 | return a<b?a:b; |
40 | } | 60 | } |
41 | 61 | ||
62 | /** | ||
63 | * Finds the greater of the two objects, objects passed in must be | ||
64 | * less-than-comparable. | ||
65 | *@param a A value to test. | ||
66 | *@param b Another value to test. | ||
67 | *@returns A reference to the greater of a or b. | ||
68 | */ | ||
42 | template<typename item> | 69 | template<typename item> |
43 | const item &max( const item &a, const item &b ) | 70 | const item &max( const item &a, const item &b ) |
44 | { | 71 | { |
45 | return a>b?a:b; | 72 | return b<a?a:b; |
46 | } | 73 | } |
47 | 74 | ||
75 | /** | ||
76 | * Finds the greater of the two objects, objects passed in must be | ||
77 | * less-than-comparable. | ||
78 | *@param a A value to test. | ||
79 | *@param b Another value to test. | ||
80 | *@returns A reference to the greater of a or b. | ||
81 | */ | ||
48 | template<typename item> | 82 | template<typename item> |
49 | item &max( item &a, item &b ) | 83 | item &max( item &a, item &b ) |
50 | { | 84 | { |
51 | return a>b?a:b; | 85 | return b<a?a:b; |
52 | } | 86 | } |
53 | 87 | ||
88 | /** | ||
89 | * Given three objects this finds the one between the other two. | ||
90 | *@param a A value to test. | ||
91 | *@param b Another value to test. | ||
92 | *@param c Yet another value to test. | ||
93 | *@returns A reference to the mid-value of a, b, and c. | ||
94 | */ | ||
54 | template<typename item> | 95 | template<typename item> |
55 | const item &mid( const item &a, const item &b, const item &c ) | 96 | const item &mid( const item &a, const item &b, const item &c ) |
56 | { | 97 | { |
57 | return min( max( a, b ), c ); | 98 | return min( max( a, b ), c ); |
58 | } | 99 | } |
59 | 100 | ||
101 | /** | ||
102 | * Given three objects this finds the one between the other two. | ||
103 | *@param a A value to test. | ||
104 | *@param b Another value to test. | ||
105 | *@param c Yet another value to test. | ||
106 | *@returns A reference to the mid-value of a, b, and c. | ||
107 | */ | ||
60 | template<typename item> | 108 | template<typename item> |
61 | item &mid( item &a, item &b, item &c ) | 109 | item &mid( item &a, item &b, item &c ) |
62 | { | 110 | { |
@@ -66,6 +114,10 @@ namespace Bu | |||
66 | // | 114 | // |
67 | // Basic comparison functors | 115 | // Basic comparison functors |
68 | // | 116 | // |
117 | /** | ||
118 | * Simple less-than comparison functor. Objects being used should be | ||
119 | * less-than-comparable. | ||
120 | */ | ||
69 | template<typename item> | 121 | template<typename item> |
70 | struct __basicLTCmp | 122 | struct __basicLTCmp |
71 | { | 123 | { |
@@ -75,6 +127,10 @@ namespace Bu | |||
75 | } | 127 | } |
76 | }; | 128 | }; |
77 | 129 | ||
130 | /** | ||
131 | * Simple greater-than comparison functor. Objects being used should be | ||
132 | * greater-than-comparable. | ||
133 | */ | ||
78 | template<typename item> | 134 | template<typename item> |
79 | struct __basicGTCmp | 135 | struct __basicGTCmp |
80 | { | 136 | { |
@@ -84,6 +140,9 @@ namespace Bu | |||
84 | } | 140 | } |
85 | }; | 141 | }; |
86 | 142 | ||
143 | /** | ||
144 | * As __basicLTCmp but dereferences the passed in pointers before comparing. | ||
145 | */ | ||
87 | template<typename item> | 146 | template<typename item> |
88 | struct __basicPtrLTCmp | 147 | struct __basicPtrLTCmp |
89 | { | 148 | { |
@@ -93,6 +152,9 @@ namespace Bu | |||
93 | } | 152 | } |
94 | }; | 153 | }; |
95 | 154 | ||
155 | /** | ||
156 | * As __basicGTCmp but dereferences the passed in pointers before comparing. | ||
157 | */ | ||
96 | template<typename item> | 158 | template<typename item> |
97 | struct __basicPtrGTCmp | 159 | struct __basicPtrGTCmp |
98 | { | 160 | { |