ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
10namespace adtf
11{
12namespace ucom
13{
14namespace ant
15{
20template<typename INTERFACE_TYPE>
22{
23protected:
26 {
27 }
28
29public:
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
66
76template <typename T,
77 typename INTERFACE_TYPE = T,
78 template<typename ELEM,
79 typename ALLOC = std::allocator<ELEM>
80 > class CONTAINER = std::list
81 >
82class object_enum_base : public iobject_enum < INTERFACE_TYPE >
83{
84 template <typename, typename, template<typename, typename> class >
85 friend class object_enum;
86public:
88 typedef CONTAINER<object_ptr<T>> container_type;
95private:
100
101private:
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 }
114public:
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
208template<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>>>
215class object_enum : public object_enum_base < T, INTERFACE_TYPE, CONTAINER >
216{
217public:
218 typedef object_enum_base<T, INTERFACE_TYPE, CONTAINER> base_type;
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;
222 typedef iobject_ptr<T> value_interface_type;
223
225 container_type m_oContainer;
226
227public: //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
237public:
241 {
242 return m_oContainer.begin();
243 }
244
247 {
248 return m_oContainer.end();
249 }
250
253 {
254 return m_oContainer.cbegin();
255 }
256
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
279public:
282 {
283 }
284
286 object_enum(const object_enum& oOther) :
287 base_type(&m_oContainer), m_oContainer(oOther.m_oContainer)
288 {
289 }
290
291 object_enum(object_enum&& oOther) : base_type()
292 {
293 std::swap(m_oContainer, oOther.m_oContainer);
294 base_type::SetContainerRef(&m_oContainer);
295 }
296
298 object_enum(const container_type& oResetContainerContent) :
299 base_type(&m_oContainer),
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
377private:
378 using base_type::Reset;
379
380};
381
386template<typename T>
387using iobject_list = iobject_enum < T > ;
388
393template<typename T>
394using iobject_vector = iobject_enum < T >;
395
401template<typename T, typename INTERFACE_TYPE = T>
402using object_list = object_enum < T, INTERFACE_TYPE, std::list>;
403
409template<typename T, typename INTERFACE_TYPE = T>
410using object_vector = object_enum < T, INTERFACE_TYPE, std::vector>;
411
412
413}//namespace ant
414
415
419
420using ant::object_enum;
421
422using ant::object_list;
424
425
426}//namespace ucom
427}//namespace adtf
428
429#endif // _ADTF_UCOM_ANT_OBJECT_LIST_INCLUDES_HEADER_
430
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#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
base_type interface_type
interface type
Definition object_list.h:92
size_t GetSize() const override
Retrieves the current value count.
CONTAINER< object_ptr< T > > container_type
container type
Definition object_list.h:88
object_enum_base(container_type *pContainer)
CTOR.
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...
object_enum(const container_type &oResetContainerContent)
special copy CTOR to copy container content of same value_type
container_type::const_iterator const_iterator
short typedefinition for cString lists iterators
const_iterator cbegin() const
const begin iterator
container_type::iterator iterator
short typedefinition for cString lists iterators
object_enum & operator=(const object_enum &oOther)
copy operator
object_enum(std::initializer_list< value_type > lstValues)
special initializer CTOR to create container content
object_enum & operator=(object_enum &&oOther)
move operator
const_iterator cend() const
const end iterator
container_type & GetContainer()
this method is ONLY for your convenience to use this in other templates !
object_enum(object_enum &&oOther)
move CTOR
container_type::const_reverse_iterator const_reverse_iterator
short typedefinition for cString lists reverse iterators
container_type::reverse_iterator reverse_iterator
short typedefinition for cString lists reverse iterators
object_enum(const object_enum &oOther)
copy CTOR
iterator end()
end iterator
iterator begin()
begin iterator
object_enum & operator=(const container_type &oResetContainerContent)
special copy operator
tVoid swap(A_UTILS_NS::d_ptr< _PARENT, _PRIVATE_D > &i_oLHS, A_UTILS_NS::d_ptr< _PARENT, _PRIVATE_D > &i_oRHS)
std::swap specialization for AUTILSDPtr for perfect fit on ADL
Definition d_ptr.h:237
Namespace for all functionality provided since v3.0.
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...
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.
iobject_enum< T > iobject_vector
alias type for iobject_enum.
iobject_enum< T > iobject_list
alias type for iobject_enum.
Namespace for the ADTF uCOM3 SDK.
Namespace for entire ADTF SDK.