00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef STXXL_STREAM__UNIQUE_H
00015 #define STXXL_STREAM__UNIQUE_H
00016
00017 #include <stxxl/bits/namespace.h>
00018
00019
00020 __STXXL_BEGIN_NAMESPACE
00021
00023 namespace stream
00024 {
00026
00028
00029 struct dummy_cmp_unique_ { };
00030
00035 template <class Input, class BinaryPredicate = dummy_cmp_unique_>
00036 class unique
00037 {
00038 Input & input;
00039 BinaryPredicate binary_pred;
00040 typename Input::value_type current;
00041
00042 public:
00044 typedef typename Input::value_type value_type;
00045
00046 unique(Input & input_, BinaryPredicate binary_pred_) : input(input_), binary_pred(binary_pred_)
00047 {
00048 if (!input.empty())
00049 current = *input;
00050 }
00051
00053 unique & operator ++ ()
00054 {
00055 value_type old_value = current;
00056 ++input;
00057 while (!input.empty() && (binary_pred(current = *input, old_value)))
00058 ++input;
00059 return *this;
00060 }
00061
00063 const value_type & operator * () const
00064 {
00065 return current;
00066 }
00067
00069 const value_type * operator -> () const
00070 {
00071 return ¤t;
00072 }
00073
00075 bool empty() const
00076 {
00077 return input.empty();
00078 }
00079 };
00080
00084 template <class Input>
00085 class unique<Input, dummy_cmp_unique_>
00086 {
00087 Input & input;
00088 typename Input::value_type current;
00089
00090 public:
00092 typedef typename Input::value_type value_type;
00093
00094 unique(Input & input_) : input(input_)
00095 {
00096 if (!input.empty())
00097 current = *input;
00098 }
00099
00101 unique & operator ++ ()
00102 {
00103 value_type old_value = current;
00104 ++input;
00105 while (!input.empty() && ((current = *input) == old_value))
00106 ++input;
00107 return *this;
00108 }
00109
00111 const value_type & operator * () const
00112 {
00113 return current;
00114 }
00115
00117 const value_type * operator -> () const
00118 {
00119 return ¤t;
00120 }
00121
00123 bool empty() const
00124 {
00125 return input.empty();
00126 }
00127 };
00128
00130 }
00131
00132 __STXXL_END_NAMESPACE
00133
00134 #endif // !STXXL_STREAM__UNIQUE_H
00135