DGtal  1.2.0
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>
60  public std::iterator<std::output_iterator_tag,void,void,void,void>
61  {
62 
66 
67  // ----------------------- Standard services ------------------------------
68  public:
69 
74  {
75  myItemPtr = new T();
76  }
81 
82  // ----------------------- Interface --------------------------------------
83  public:
84 
90  inline OneItemOutputIterator& operator=(const T& aItem)
91  {
92  ASSERT( isValid() );
93  *myItemPtr = aItem;
94  return *this;
95  }
96 
101  inline OneItemOutputIterator& operator*() { return *this; }
102 
107  inline OneItemOutputIterator& operator++() { return *this; }
108 
113  inline OneItemOutputIterator operator++(int) { return *this; }
114 
119  inline T get() const
120  {
121  ASSERT( isValid() );
122  return *myItemPtr;
123  }
124 
129  inline bool isValid() const { return (myItemPtr != NULL); }
130 
131  // ------------------------- Private Datas --------------------------------
132  private:
135 
136  }; // end of class OneItemOutputIterator
137 
138 
139 } // namespace DGtal
140 
141 
143 // Includes inline functions.
144 //#include "DGtal/base/OneItemOutputIterator.ih"
145 
146 // //
148 
149 #endif // !defined OneItemOutputIterator_h
150 
151 #undef OneItemOutputIterator_RECURSES
152 #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
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