• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

unique.h

00001 /***************************************************************************
00002  *  include/stxxl/bits/stream/unique.h
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2003-2005 Roman Dementiev <[email protected]>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #ifndef STXXL_STREAM__UNIQUE_H
00014 #define STXXL_STREAM__UNIQUE_H
00015 
00016 #include <stxxl/bits/namespace.h>
00017 
00018 
00019 __STXXL_BEGIN_NAMESPACE
00020 
00022 namespace stream
00023 {
00025     //     UNIQUE                                                         //
00027 
00028     struct dummy_cmp_unique_ { };
00029 
00034     template <class Input, class BinaryPredicate = dummy_cmp_unique_>
00035     class unique
00036     {
00037         Input & input;
00038         BinaryPredicate binary_pred;
00039         typename Input::value_type current;
00040 
00041     public:
00043         typedef typename Input::value_type value_type;
00044 
00045         unique(Input & input_, BinaryPredicate binary_pred_) : input(input_), binary_pred(binary_pred_)
00046         {
00047             if (!input.empty())
00048                 current = *input;
00049         }
00050 
00052         unique & operator ++ ()
00053         {
00054             value_type old_value = current;
00055             ++input;
00056             while (!input.empty() && (binary_pred(current = *input, old_value)))
00057                 ++input;
00058         }
00059 
00061         const value_type & operator * () const
00062         {
00063             return current;
00064         }
00065 
00067         const value_type * operator -> () const
00068         {
00069             return &current;
00070         }
00071 
00073         bool empty() const
00074         {
00075             return input.empty();
00076         }
00077     };
00078 
00082     template <class Input>
00083     class unique<Input, dummy_cmp_unique_>
00084     {
00085         Input & input;
00086         typename Input::value_type current;
00087 
00088     public:
00090         typedef typename Input::value_type value_type;
00091 
00092         unique(Input & input_) : input(input_)
00093         {
00094             if (!input.empty())
00095                 current = *input;
00096         }
00097 
00099         unique & operator ++ ()
00100         {
00101             value_type old_value = current;
00102             ++input;
00103             while (!input.empty() && ((current = *input) == old_value))
00104                 ++input;
00105         }
00106 
00108         value_type & operator * () const
00109         {
00110             return current;
00111         }
00112 
00114         const value_type * operator -> () const
00115         {
00116             return &current;
00117         }
00118 
00120         bool empty() const
00121         {
00122             return input.empty();
00123         }
00124     };
00125 
00127 }
00128 
00129 __STXXL_END_NAMESPACE
00130 
00131 #endif // !STXXL_STREAM__UNIQUE_H
00132 // vim: et:ts=4:sw=4

Generated by  doxygen 1.7.1