ADTF
object_list.h
Go to the documentation of this file.
1 
7 #ifndef _ADTF_UCOM_ANT_OBJECT_LIST_INCLUDES_HEADER_
8 #define _ADTF_UCOM_ANT_OBJECT_LIST_INCLUDES_HEADER_
9 
10 namespace adtf
11 {
12 namespace ucom
13 {
14 namespace ant
15 {
20 template<typename INTERFACE_TYPE>
22 {
23 protected:
26  {
27  }
28 
29 public:
34 
42  virtual tResult PushObject(const value_type& oObject) = 0;
48  virtual tResult GetObjects(my_type& oObjectsEnum) const = 0;
53  virtual size_t GetSize() const = 0;
54 };
55 
60 {
62  eNone = 0x00,
64  eNoDuplicates = 0x01
65 };
66 
76 template <typename T,
77  typename INTERFACE_TYPE = T,
78  template<typename ELEM,
79  typename ALLOC = std::allocator<ELEM>
80  > class CONTAINER = std::list
81  >
82 class object_enum_base : public iobject_enum < INTERFACE_TYPE >
83 {
84  template <typename, typename, template<typename, typename> class >
85  friend class object_enum;
86 public:
88  typedef CONTAINER<object_ptr<T>> container_type;
95 private:
100 
101 private:
102  object_enum_base() : m_pContainer(nullptr)
103  {
104  }
105  object_enum_base(const object_enum_base&) = delete;
107  object_enum_base& operator=(const object_enum_base&) = delete;
108  object_enum_base& operator=(object_enum_base&&) = delete;
109 
110  void SetContainerRef(container_type* pContainer)
111  {
112  m_pContainer = pContainer;
113  }
114 public:
116  object_enum_base(container_type* pContainer) : m_pContainer(pContainer)
117  {
118  }
119  virtual ~object_enum_base()
120  {
121  Reset();
122  }
123  void Reset()
124  {
125  m_pContainer = nullptr;
126  }
127 
128  void SetPushOption(uint32_t ui32PushOption)
129  {
130  m_ui32PushOption = ui32PushOption;
131  }
132 
133  tResult PushObject(const typename interface_type::value_type& oObject) override
134  {
135  if (m_pContainer)
136  {
137  value_type oPushObject = oObject;
138  if (oPushObject)
139  {
142  {
143  //needs to be implemented!!
144  }
145  //succedded ucom_cast conversion from INTERFACE_TYPE to T
146  m_pContainer->push_back(oObject);
148  }
149  else
150  {
151  //no ucom_cast conversion from INTERFACE_TYPE to T
152  RETURN_ERROR(ERR_INVALID_INTERFACE);
153  }
154  }
155  else
156  {
157  RETURN_ERROR(ERR_NOT_INITIALIZED);
158  }
159  }
160  tResult GetObjects(base_type& oObjectsEnum) const override
161  {
162  if (m_pContainer)
163  {
164  typename container_type::const_iterator it = m_pContainer->cbegin();
165  for (; it != m_pContainer->cend(); ++it)
166  {
167  object_ptr<INTERFACE_TYPE> oConversion = *it;
168  if (oConversion)
169  {
170  //not care about result
171  oObjectsEnum.PushObject(oConversion);
172  }
173  else
174  {
175  //ucomcast failed we can non push the value
176  }
177  }
179  }
180  else
181  {
182  RETURN_ERROR(ERR_NOT_INITIALIZED);
183  }
184 
185  }
186  size_t GetSize() const override
187  {
188  if (m_pContainer)
189  {
190  return m_pContainer->size();
191  }
192  else
193  {
194  return 0;
195  }
196  }
197 };
198 
199 
208 template<typename T,
209  typename INTERFACE_TYPE = T,
210  template<typename ELEM,
211  typename ALLOC = std::allocator<ELEM>
212  > class CONTAINER = std::list
213  >
214 //template <typename T, typename INTERFACE_TYPE = T, typename CONTAINER = std::list<object_ptr<T>>>
215 class object_enum : public object_enum_base < T, INTERFACE_TYPE, CONTAINER >
216 {
217 public:
219  typedef typename base_type::container_type container_type;
220  typedef typename base_type::interface_type interface_type;
221  typedef object_ptr<T> value_type;
223 
225  container_type m_oContainer;
226 
227 public: //iterators
229  typedef typename container_type::const_iterator const_iterator;
231  typedef typename container_type::const_reverse_iterator const_reverse_iterator;
233  typedef typename container_type::iterator iterator;
235  typedef typename container_type::reverse_iterator reverse_iterator;
236 
237 public:
241  {
242  return m_oContainer.begin();
243  }
247  {
248  return m_oContainer.end();
249  }
253  {
254  return m_oContainer.cbegin();
255  }
259  {
260  return m_oContainer.cend();
261  }
262  reverse_iterator rbegin()
263  {
264  return m_oContainer.rbegin();
265  }
266  reverse_iterator rend()
267  {
268  return m_oContainer.rend();
269  }
270  const_reverse_iterator crbegin() const
271  {
272  return m_oContainer.crbegin();
273  }
274  const_reverse_iterator crend() const
275  {
276  return m_oContainer.crend();
277  }
278 
279 public:
282  {
283  }
284 
286  object_enum(const object_enum& oOther) :
288  {
289  }
292  {
293  std::swap(m_oContainer, oOther.m_oContainer);
294  base_type::SetContainerRef(&m_oContainer);
295  }
298  object_enum(const container_type& oResetContainerContent) :
300  m_oContainer(oResetContainerContent)
301  {
302  }
303 
306  object_enum(std::initializer_list<value_type> lstValues) : base_type(&m_oContainer),
307  m_oContainer(lstValues)
308  {
309  }
310 
314  {
315  m_oContainer = oOther.m_oContainer;
316  return *this;
317  }
318 
322  {
323  std::swap(m_oContainer, oOther.m_oContainer);
324  this->SetContainerRef(&m_oContainer);
325  return *this;
326  }
327 
330  object_enum& operator=(const container_type& oResetContainerContent)
331  {
332  m_oContainer = oResetContainerContent;
333  return *this;
334  }
335 
336 
342  container_type& GetContainer()
343  {
344  return m_oContainer;
345  }
346 
347  void PushBack(const value_type& oObjectValue)
348  {
349  m_oContainer.push_back(oObjectValue);
350  }
351 
352  void PushFront(const value_type& oObjectValue)
353  {
354  m_oContainer.push_front(oObjectValue);
355  }
356 
357  void Clear()
358  {
359  m_oContainer.clear();
360  }
361 
362  void DeleteObject(const value_interface_type& oObject)
363  { //gcc 4.8 doesn't take const_iterator types as parameter for erase()...
364  for (auto it = m_oContainer.begin();
365  it != m_oContainer.end();
366  it++)
367  {
368  if ((*it) == oObject)
369  {
370  m_oContainer.erase(it);
371  return;
372  }
373  }
374  }
375 
376 // hide the reset function of object_enum_intf
377 private:
378  using base_type::Reset;
379 
380 };
381 
386 template<typename T>
388 
393 template<typename T>
395 
401 template<typename T, typename INTERFACE_TYPE = T>
403 
409 template<typename T, typename INTERFACE_TYPE = T>
411 
412 
413 }//namespace ant
414 
415 
416 using ant::iobject_enum;
417 using ant::iobject_list;
418 using ant::iobject_vector;
419 
420 using ant::object_enum;
421 
422 using ant::object_list;
423 using ant::object_vector;
424 
425 
426 }//namespace ucom
427 }//namespace adtf
428 
429 #endif // _ADTF_UCOM_ANT_OBJECT_LIST_INCLUDES_HEADER_
430 
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Interface definition for a container of objects.
Definition: object_list.h:22
virtual tResult GetObjects(my_type &oObjectsEnum) const =0
Pushes every contained value to the given container in oObjectsEnum.
virtual size_t GetSize() const =0
Retrieves the current value count.
iobject_enum< INTERFACE_TYPE > my_type
this type
Definition: object_list.h:33
virtual tResult PushObject(const value_type &oObject)=0
Pushes a object of value_type to the container.
iobject_ptr< INTERFACE_TYPE > value_type
value type of the contained objects
Definition: object_list.h:31
Base object pointer to realize binary compatible reference counting in interface methods.
basic object interface implementation template.
Definition: object_list.h:83
iobject_enum< INTERFACE_TYPE > base_type
base type
Definition: object_list.h:90
uint32_t m_ui32PushOption
current set push option
Definition: object_list.h:99
base_type interface_type
interface type
Definition: object_list.h:92
size_t GetSize() const override
Retrieves the current value count.
Definition: object_list.h:186
container_type * m_pContainer
container reference
Definition: object_list.h:97
CONTAINER< object_ptr< T > > container_type
container type
Definition: object_list.h:88
object_enum_base(container_type *pContainer)
CTOR.
Definition: object_list.h:116
object_ptr< T > value_type
internal value type
Definition: object_list.h:94
container type template for a set of object_ptr This template will provide a container for object_ptr...
Definition: object_list.h:216
object_enum(const container_type &oResetContainerContent)
special copy CTOR to copy container content of same value_type
Definition: object_list.h:298
object_enum & operator=(object_enum &&oOther)
move operator
Definition: object_list.h:321
container_type::const_iterator const_iterator
short typedefinition for cString lists iterators
Definition: object_list.h:229
object_enum & operator=(const object_enum &oOther)
copy operator
Definition: object_list.h:313
const_iterator cbegin() const
const begin iterator
Definition: object_list.h:252
container_type::iterator iterator
short typedefinition for cString lists iterators
Definition: object_list.h:233
container_type m_oContainer
container implementation
Definition: object_list.h:225
object_enum & operator=(const container_type &oResetContainerContent)
special copy operator
Definition: object_list.h:330
object_enum(std::initializer_list< value_type > lstValues)
special initializer CTOR to create container content
Definition: object_list.h:306
container_type & GetContainer()
this method is ONLY for your convenience to use this in other templates !! AND to use optimized empla...
Definition: object_list.h:342
const_iterator cend() const
const end iterator
Definition: object_list.h:258
object_enum(object_enum &&oOther)
move CTOR
Definition: object_list.h:291
container_type::const_reverse_iterator const_reverse_iterator
short typedefinition for cString lists reverse iterators
Definition: object_list.h:231
container_type::reverse_iterator reverse_iterator
short typedefinition for cString lists reverse iterators
Definition: object_list.h:235
object_enum(const object_enum &oOther)
copy CTOR
Definition: object_list.h:286
iterator end()
end iterator
Definition: object_list.h:246
iterator begin()
begin iterator
Definition: object_list.h:240
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
object_enum_push_option
Push option for object_enum_intf::PushObject.
Definition: object_list.h:60
@ eNone
no push option set
Definition: object_list.h:62
@ eNoDuplicates
filter duplicates on PushObject call
Definition: object_list.h:64
object_enum< T, INTERFACE_TYPE, std::vector > object_vector
Implementation of an iobject_vector<INTERFACE_TYPE> interface by using a std::vector as container typ...
Definition: object_list.h:410
object_enum< T, INTERFACE_TYPE, std::list > object_list
Implementation of an iobject_list<INTERFACE_TYPE> interface by using a std::list as container type.
Definition: object_list.h:402
iobject_enum< T > iobject_vector
alias type for iobject_enum.
Definition: object_list.h:394
iobject_enum< T > iobject_list
alias type for iobject_enum.
Definition: object_list.h:387
Namespace for entire ADTF SDK.