16 #ifndef __SERVICES_INTERNAL_COLLECTION_H__
17 #define __SERVICES_INTERNAL_COLLECTION_H__
19 #include "services/base.h"
20 #include "services/collection.h"
21 #include "services/internal/error_handling_helpers.h"
36 template<
typename T,
typename Deleter = ObjectDeleter<T> >
37 class ObjectPtrCollection :
public Base
40 ObjectPtrCollection() { }
42 ObjectPtrCollection(
const Deleter &deleter) :
45 virtual ~ObjectPtrCollection()
47 for (
size_t i = 0; i < _objects.size(); i++)
48 { _deleter( (
const void *)_objects[i] ); }
51 T &operator [] (
size_t index)
const
53 DAAL_ASSERT( index < _objects.size() );
54 return *(_objects[index]);
59 return _objects.size();
62 bool push_back(T *
object)
67 return _objects.safe_push_back(
object);
73 return _objects.push_back(
new U());
77 ObjectPtrCollection(
const ObjectPtrCollection &);
78 ObjectPtrCollection &operator = (
const ObjectPtrCollection &);
82 services::Collection<T *> _objects;
92 class HeapAllocatableCollection :
public Base,
public services::Collection<T>
95 static SharedPtr<HeapAllocatableCollection<T> > create(services::Status *status = NULL)
97 typedef SharedPtr<HeapAllocatableCollection<T> > PtrType;
99 HeapAllocatableCollection<T> *collection =
new internal::HeapAllocatableCollection<T>();
102 services::internal::tryAssignStatusAndThrow(status, services::ErrorMemoryAllocationFailed);
106 return PtrType(collection);
109 static SharedPtr<HeapAllocatableCollection<T> > create(
size_t n, services::Status *status = NULL)
111 typedef SharedPtr<HeapAllocatableCollection<T> > PtrType;
113 HeapAllocatableCollection<T> *collection =
new internal::HeapAllocatableCollection<T>(n);
114 if (!collection || !collection->data())
117 services::internal::tryAssignStatusAndThrow(status, services::ErrorMemoryAllocationFailed);
121 return PtrType(collection);
124 HeapAllocatableCollection() { }
126 explicit HeapAllocatableCollection(
size_t n) :
127 services::Collection<T>(n) { }
136 class CollectionPtr :
public SharedPtr<HeapAllocatableCollection<T> >
139 typedef SharedPtr<HeapAllocatableCollection<T> > super;
145 CollectionPtr(
const SharedPtr<U> &other) : super(other) { }
148 explicit CollectionPtr(U *ptr) : super(ptr) { }
150 template<
class U,
class D>
151 explicit CollectionPtr(U *ptr,
const D& deleter) : super(ptr, deleter) { }
daal::services::internal::HeapAllocatableCollection
Wrapper for services::Collection that allocates and deallocates memory using internal new/delete oper...
Definition: internal/collection.h:92
daal
Definition: algorithm_base_common.h:31
daal::services::internal::CollectionPtr
Shared pointer to the Collection object.
Definition: internal/collection.h:136
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:147
daal::services::internal::ObjectPtrCollection
Class that implements functionality of collection container and holds pointers to objects of specifie...
Definition: internal/collection.h:37
daal::Base
Base class for Intel(R) Data Analytics Acceleration Library objects
Definition: base.h:39