proxy_parameter_generator.h
Go to the documentation of this file.
1 
10 #pragma once
11 #include <gtest/gtest.h>
14 
15 
16 namespace illumina{ namespace interop { namespace unittest
17 {
18 
25  template<typename T, typename Proxy>
26  class proxy_argument_generator : public ::testing::internal::ParamGeneratorInterface< typename T::parent_type >
27  {
28  public:
34  proxy_argument_generator(T& obj, const std::vector<Proxy>& vec) : m_vec(vec), m_object(obj){}
41  ::testing::internal::ParamIteratorInterface< typename T::parent_type >* Begin() const;
46  ::testing::internal::ParamIteratorInterface< typename T::parent_type >* End() const;
47 
48  private:
49  const std::vector<Proxy>& m_vec;
50  T& m_object;
51  };
56  template<typename T, typename Proxy>
57  class proxy_argument_iterator : public ::testing::internal::ParamIteratorInterface< typename T::parent_type >
58  {
59  typedef typename std::vector< Proxy >::const_iterator const_iterator;
60  public:
70  const_iterator it,
71  const_iterator it_end) :
72  m_base(base), m_begin(it), m_current(it), m_end(it_end), m_object(obj)
73  {
74  static_assert(!is_pointer<T>::value, "This class does not free memory and should not take a pointer");
75  if(m_current < m_end)
76  {
77  m_current_val=m_object(*m_current);
78  }
79  }
82  {
83  }
90  virtual const ::testing::internal::ParamGeneratorInterface< typename T::parent_type >* BaseGenerator() const
91  {
92  return &m_base;
93  }
101  virtual void Advance()
102  {
103  if(m_current_val == 0 || m_current_val->advance())
104  {
105  ++m_current;
106  if(m_current < m_end)
107  {
108  m_current_val=m_object(*m_current);
109  }
110  }
111  }
117  virtual ::testing::internal::ParamIteratorInterface< typename T::parent_type >* Clone() const
118  {
119  return new proxy_argument_iterator(*this);
120  }
128  virtual const typename T::parent_type* Current() const
129  {
130  return &m_current_val;
131  }
139  virtual bool Equals(const ::testing::internal::ParamIteratorInterface< typename T::parent_type >& other) const
140  {
141  return &m_base == other.BaseGenerator() &&
142  m_current == dynamic_cast<const proxy_argument_iterator<T,Proxy>*>(&other)->m_current;
143  }
144 
145  private:
147  : m_base(other.m_base), m_begin(other.m_begin),
148  m_current(other.m_current), m_end(other.m_end), m_object(other.m_object)
149  {
150  if(m_current < m_end) m_current_val=m_object(*m_current);
151  }
152 
153  private:
154  const proxy_argument_generator<T,Proxy>& m_base;
155  const const_iterator m_begin;
156  const_iterator m_current;
157  const_iterator m_end;
158  T& m_object;
159  mutable typename T::parent_type m_current_val;
160  };
161 
162 
163  template<typename T, typename Proxy>
164  ::testing::internal::ParamIteratorInterface< typename T::parent_type >* proxy_argument_generator<T,Proxy>::Begin() const
165  {
166  return new proxy_argument_iterator<T,Proxy>(m_object, *this, m_vec.begin(), m_vec.end());
167  }
168  template<typename T, typename Proxy>
169  ::testing::internal::ParamIteratorInterface< typename T::parent_type >* proxy_argument_generator<T,Proxy>::End() const
170  {
171  return new proxy_argument_iterator<T,Proxy>(m_object, *this, m_vec.end(), m_vec.end());
172  }
173 
181  template<typename T, typename Proxy>
182  ::testing::internal::ParamGenerator< typename T::parent_type > ProxyValuesIn(T& object, const std::vector<Proxy>& values)
183  {
184  return ::testing::internal::ParamGenerator< typename T::parent_type >(new proxy_argument_generator<T, Proxy>(object, values));
185  }
186 }}}
187 
proxy_argument_iterator(T &obj, const proxy_argument_generator< T, Proxy > &base, const_iterator it, const_iterator it_end)
Definition: proxy_parameter_generator.h:68
::testing::internal::ParamGenerator< typename T::parent_type > ProxyValuesIn(T &object, const std::vector< Proxy > &values)
Definition: proxy_parameter_generator.h:182
Definition: enum_description.h:15
Definition: proxy_parameter_generator.h:57
virtual void Advance()
Definition: proxy_parameter_generator.h:101
proxy_argument_generator(T &obj, const std::vector< Proxy > &vec)
Definition: proxy_parameter_generator.h:34
Definition: proxy_parameter_generator.h:26
virtual bool Equals(const ::testing::internal::ParamIteratorInterface< typename T::parent_type > &other) const
Definition: proxy_parameter_generator.h:139
::testing::internal::ParamIteratorInterface< typename T::parent_type > * End() const
Definition: proxy_parameter_generator.h:169
virtual const T::parent_type * Current() const
Definition: proxy_parameter_generator.h:128
::testing::internal::ParamIteratorInterface< typename T::parent_type > * Begin() const
Definition: proxy_parameter_generator.h:164
virtual ~proxy_argument_iterator()
Definition: proxy_parameter_generator.h:81
Definition: type_traits.h:104
virtual ~proxy_argument_generator()
Definition: proxy_parameter_generator.h:36
Definition: enums.h:301
#define static_assert(x, m)
Definition: static_assert.h:23
virtual const ::testing::internal::ParamGeneratorInterface< typename T::parent_type > * BaseGenerator() const
Definition: proxy_parameter_generator.h:90
virtual ::testing::internal::ParamIteratorInterface< typename T::parent_type > * Clone() const
Definition: proxy_parameter_generator.h:117