18 #ifndef __SERVICES_INTERNAL_COLLECTION_H__
19 #define __SERVICES_INTERNAL_COLLECTION_H__
21 #include "services/base.h"
22 #include "services/collection.h"
23 #include "services/internal/error_handling_helpers.h"
38 template<
typename T,
typename Deleter = ObjectDeleter<T> >
39 class ObjectPtrCollection :
public Base
42 ObjectPtrCollection() { }
44 ObjectPtrCollection(
const Deleter &deleter) :
47 virtual ~ObjectPtrCollection()
49 for (
size_t i = 0; i < _objects.size(); i++)
50 { _deleter( (
const void *)_objects[i] ); }
53 T &operator [] (
size_t index)
const
55 DAAL_ASSERT( index < _objects.size() );
56 return *(_objects[index]);
61 return _objects.size();
64 bool push_back(T *
object)
69 return _objects.safe_push_back(
object);
75 return _objects.push_back(
new U());
79 ObjectPtrCollection(
const ObjectPtrCollection &);
80 ObjectPtrCollection &operator = (
const ObjectPtrCollection &);
84 services::Collection<T *> _objects;
94 class HeapAllocatableCollection :
public Base,
public services::Collection<T>
97 static SharedPtr<HeapAllocatableCollection<T> > create(services::Status *status = NULL)
99 typedef SharedPtr<HeapAllocatableCollection<T> > PtrType;
101 HeapAllocatableCollection<T> *collection =
new internal::HeapAllocatableCollection<T>();
104 services::internal::tryAssignStatusAndThrow(status, services::ErrorMemoryAllocationFailed);
108 return PtrType(collection);
111 static SharedPtr<HeapAllocatableCollection<T> > create(
size_t n, services::Status *status = NULL)
113 typedef SharedPtr<HeapAllocatableCollection<T> > PtrType;
115 HeapAllocatableCollection<T> *collection =
new internal::HeapAllocatableCollection<T>(n);
116 if (!collection || !collection->data())
119 services::internal::tryAssignStatusAndThrow(status, services::ErrorMemoryAllocationFailed);
123 return PtrType(collection);
126 HeapAllocatableCollection() { }
128 explicit HeapAllocatableCollection(
size_t n) :
129 services::Collection<T>(n) { }
138 class CollectionPtr :
public SharedPtr<HeapAllocatableCollection<T> >
141 typedef SharedPtr<HeapAllocatableCollection<T> > super;
147 CollectionPtr(
const SharedPtr<U> &other) : super(other) { }
150 explicit CollectionPtr(U *ptr) : super(ptr) { }
152 template<
class U,
class D>
153 explicit CollectionPtr(U *ptr,
const D& deleter) : super(ptr, deleter) { }
daal::services::internal::ObjectPtrCollection
Class that implements functionality of collection container and holds pointers to objects of specifie...
Definition: internal/collection.h:39
daal::services::internal::HeapAllocatableCollection
Wrapper for services::Collection that allocates and deallocates memory using internal new/delete oper...
Definition: internal/collection.h:94
daal::Base
Base class for Intel(R) Data Analytics Acceleration Library objects
Definition: base.h:41
daal::services::internal::CollectionPtr
Shared pointer to the Collection object.
Definition: internal/collection.h:138
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:150