InsertIteratorSTL.hpp
1 #ifndef DM_INSERT_ITERATOR_STL_HPP_INCLUDED
2 #define DM_INSERT_ITERATOR_STL_HPP_INCLUDED
3 
4 #ifdef _MSC_VER
5  #pragma once
6 #endif
7 
8 #include "DM/config.hpp"
9 #include "DM/Iterator.hpp"
10 
11 DM_NAMESPACE_BEGIN
12 
13 template<typename ContainerT >
14 class BackInsertIteratorSTL : public InsertIterator< typename ContainerT::value_type::element_type >
15 {
17 
18 public:
19  typedef ContainerT container_type;
20  typedef typename base::pointer pointer;
21  typedef typename base::const_reference const_reference;
22  typedef typename base::handle_type handle_type;
24 
25  BackInsertIteratorSTL(container_type &cont) : Cont(cont) {}
27 
28  virtual base& operator=(const_reference value) {
29  Cont.push_back( handle_type( (pointer)(value.clone()) ) );
30  return *this;
31  }
32  virtual base& operator=(const_handle_reference value) {
33  Cont.push_back(value);
34  return *this;
35  }
36  virtual base& operator*() { return *this; }
37  virtual base& operator++() { return *this; };
38 
39 protected:
40  container_type &Cont;
41 };
42 
43 template<typename ContainerT >
44 class FrontInsertIteratorSTL : public InsertIterator< typename ContainerT::value_type::element_type >
45 {
47 
48 public:
49  typedef ContainerT container_type;
50  typedef typename base::pointer pointer;
51  typedef typename base::const_reference const_reference;
52  typedef typename base::handle_type handle_type;
54 
55  FrontInsertIteratorSTL(container_type &cont) : Cont(cont) {}
57 
58  virtual base& operator=(const_reference value) {
59  Cont.push_front( handle_type( (pointer)(value.clone()) ) );
60  return *this;
61  }
62  virtual base& operator=(const_handle_reference value) {
63  Cont.push_front(value);
64  return *this;
65  }
66  virtual base& operator*() { return *this; }
67  virtual base& operator++() { return *this; };
68 
69 protected:
70  container_type &Cont;
71 };
72 
73 /// Creates a back inserter for stl containers.
74 /// As container elements only handles are allowed. e.g. std::vector< DM::PointHandle >
75 template< typename ContainerT >
78 }
79 
80 /// Creates a front inserter for stl containers.
81 /// As container elements only handles are allowed. e.g. std::vector< DM::PointHandle >
82 template< typename ContainerT >
85 }
86 
87 
88 DM_NAMESPACE_END
89 
90 #endif //DM_INSERT_ITERATOR_STL_HPP_INCLUDED