InsertIteratorPH.hpp
1 #ifndef DM_INSERT_ITERATOR_PH_HPP_INCLUDED
2 #define DM_INSERT_ITERATOR_PH_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 
12 //forward declaration
13 template < class T, class UserAllocator > class PH_vector;
14 template < class T, class UserAllocator > class PH_List;
15 
16 DM_NAMESPACE_BEGIN
17 
18 template<typename PH_ContainerT >
19 class BackInsertIteratorPH : public InsertIterator< typename PH_ContainerT::value_type::element_type >
20 {
23 
24  template<class T1, class T2>
25  void push_back(PH_vector<T1, T2> &vect, const_handle_reference h) { vect.v_add(h); }
26  template<class T1, class T2>
27  void push_back(PH_List<T1, T2> &list, const_handle_reference h) { list.append(h); }
28 
29 public:
30  typedef PH_ContainerT container_type;
31  typedef typename base::pointer pointer;
32  typedef typename base::const_reference const_reference;
33  typedef typename base::handle_type handle_type;
34 
35  BackInsertIteratorPH(container_type &cont) : Cont(cont) {}
37 
38  virtual base& operator=(const_reference value) {
39  push_back( Cont, handle_type( (pointer)(value.clone()) ) );
40  return *this;
41  }
42  virtual base& operator=(const_handle_reference value) {
43  push_back( Cont, value );
44  return *this;
45  }
46  virtual base& operator*() { return *this; }
47  virtual base& operator++() { return *this; };
48 
49 protected:
50  container_type &Cont;
51 };
52 
53 template<typename PH_ContainerT >
54 class FrontInsertIteratorPH : public InsertIterator< typename PH_ContainerT::value_type::element_type >
55 {
58 
59  template<class T1, class T2>
60  void push_front(PH_vector<T1, T2> &vect, const_handle_reference h) { vect.v_insertAt(0,h); }
61  template<class T1, class T2>
62  void push_front(PH_List<T1, T2> &list, const_handle_reference h) { list.add(h); }
63 
64 public:
65  typedef PH_ContainerT container_type;
66  typedef typename base::pointer pointer;
67  typedef typename base::const_reference const_reference;
68  typedef typename base::handle_type handle_type;
69 
70  FrontInsertIteratorPH(container_type &cont) : Cont(cont) {}
72 
73  virtual base& operator=(const_reference value) {
74  push_front( Cont, handle_type( (pointer)(value.clone()) ) );
75  return *this;
76  }
77  virtual base& operator=(const_handle_reference value) {
78  push_front( Cont, value );
79  return *this;
80  }
81  virtual base& operator*() { return *this; }
82  virtual base& operator++() { return *this; };
83 
84 protected:
85  container_type &Cont;
86 };
87 
88 /// Creates a default inserter (back inserter) for PH containers (supported container: PH_vector, PH_List).
89 /// As container elements only handles are allowed. e.g. PH_vector< DM::PointHandle >
90 template< typename PH_ContainerT >
91 inline BackInsertIteratorPH<PH_ContainerT> PH_inserter(PH_ContainerT &cont) {
93 }
94 
95 
96 /// Creates a back inserter for PH containers (supported container: PH_vector, PH_List).
97 /// As container elements only handles are allowed. e.g. PH_vector< DM::PointHandle >
98 template< typename PH_ContainerT >
101 }
102 
103 /// Creates a front inserter for PH containers (supported container: PH_vector, PH_List).
104 /// As container elements only handles are allowed. e.g. PH_vector< DM::PointHandle >
105 template< typename PH_ContainerT >
108 }
109 
110 DM_NAMESPACE_END
111 
112 #endif //DM_INSERT_ITERATOR_SELECTOR_HPP_INCLUDED