DGtal  1.4.beta
OneItemOutputIterator.h
1 
17 #pragma once
18 
31 #if defined(OneItemOutputIterator_RECURSES)
32 #error Recursive header files inclusion detected in OneItemOutputIterator.h
33 #else // defined(OneItemOutputIterator_RECURSES)
35 #define OneItemOutputIterator_RECURSES
36 
37 #if !defined OneItemOutputIterator_h
39 #define OneItemOutputIterator_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
46 
47 namespace DGtal
48 {
49 
51  // template class OneItemOutputIterator
58  template <typename T>
59  class OneItemOutputIterator//: public std::iterator<std::output_iterator_tag,void,void,void,void>
60  {
61 
62  public:
63  using iterator_category = std::output_iterator_tag;
64  using value_type = void;
65  using difference_type = void;
66  using pointer = void;
67  using reference = void;
68 
69 
73 
74  // ----------------------- Standard services ------------------------------
75  public:
76 
81  {
82  myItemPtr = new T();
83  }
88 
89  // ----------------------- Interface --------------------------------------
90  public:
91 
97  inline OneItemOutputIterator& operator=(const T& aItem)
98  {
99  ASSERT( isValid() );
100  *myItemPtr = aItem;
101  return *this;
102  }
103 
108  inline OneItemOutputIterator& operator*() { return *this; }
109 
114  inline OneItemOutputIterator& operator++() { return *this; }
115 
120  inline OneItemOutputIterator operator++(int) { return *this; }
121 
126  inline T get() const
127  {
128  ASSERT( isValid() );
129  return *myItemPtr;
130  }
131 
136  inline bool isValid() const { return (myItemPtr != NULL); }
137 
138  // ------------------------- Private Datas --------------------------------
139  private:
142 
143  }; // end of class OneItemOutputIterator
144 
145 
146 } // namespace DGtal
147 
148 
150 // Includes inline functions.
151 //#include "DGtal/base/OneItemOutputIterator.ih"
152 
153 // //
155 
156 #endif // !defined OneItemOutputIterator_h
157 
158 #undef OneItemOutputIterator_RECURSES
159 #endif // else defined(OneItemOutputIterator_RECURSES)
Aim: model of output iterator, ie incrementable and writable iterator, which only stores in a variabl...
OneItemOutputIterator operator++(int)
OneItemOutputIterator & operator=(const T &aItem)
OneItemOutputIterator & operator*()
OneItemOutputIterator(const OneItemOutputIterator &other)
BOOST_CONCEPT_ASSERT((boost::DefaultConstructible< T >))
T * myItemPtr
pointer that stores the last assigned item
std::output_iterator_tag iterator_category
BOOST_CONCEPT_ASSERT((boost::CopyConstructible< T >))
BOOST_CONCEPT_ASSERT((boost::Assignable< T >))
OneItemOutputIterator & operator++()
DGtal is the top-level namespace which contains all DGtal functions and types.
Go to http://www.sgi.com/tech/stl/Assignable.html.
Definition: Boost.dox:32
Go to http://www.sgi.com/tech/stl/CopyConstructible.html.
Definition: Boost.dox:34
Go to http://www.sgi.com/tech/stl/DefaultConstructible.html.
Definition: Boost.dox:30