28 #ifndef _UCOMMON_VECTOR_H_
29 #define _UCOMMON_VECTOR_H_
31 #ifndef _UCOMMON_THREAD_H_
37 typedef unsigned short vectorsize_t;
50 unsigned count,
limit, used;
55 ArrayReuse(
size_t objsize,
unsigned c,
void *memory);
64 bool avail(
void)
const;
81 unsigned limit, count;
88 bool avail(
void)
const;
116 vectorsize_t
max, len;
120 array(vectorsize_t size);
126 void inc(vectorsize_t adj);
127 void dec(vectorsize_t adj);
133 array *create(vectorsize_t size)
const;
136 virtual void cow(vectorsize_t adj = 0);
139 friend class Vector::array;
152 static const vectorsize_t
npos;
163 Vector(vectorsize_t size);
185 vectorsize_t len(
void)
const;
192 vectorsize_t size(
void)
const;
207 vectorsize_t
get(
void **mem, vectorsize_t
max)
const;
236 void split(vectorsize_t position);
244 void rsplit(vectorsize_t position);
281 virtual bool resize(vectorsize_t size);
313 set(position, pointer);
322 return get(position);
370 void operator^=(
Vector &vector);
386 void operator+=(vectorsize_t count);
392 void operator-=(vectorsize_t count);
399 static vectorsize_t size(
void **list);
410 bool resize(vectorsize_t size);
411 void cow(vectorsize_t adj = 0);
414 friend class Vector::array;
459 inline T& operator[](
int index) {
463 inline const T& at(
int index) {
499 return static_cast<Vector &
>(*this);
532 inline operator bool()
const {
549 return static_cast<T*
>(ArrayReuse::request());
557 inline T*
get(void) {
558 return static_cast<T*
>(ArrayReuse::get());
567 return init<T>(
static_cast<T*
>(ArrayReuse::get()));
576 inline T*
get(timeout_t timeout) {
577 return static_cast<T*
>(ArrayReuse::get(timeout));
587 return init<T>(
static_cast<T*
>(ArrayReuse::get(timeout)));
603 inline operator T*() {
641 inline operator bool()
const {
642 return PagerReuse::avail();
650 return !PagerReuse::avail();
658 inline T *
get(void) {
659 return static_cast<T*
>(PagerReuse::get());
669 return init<T>(
static_cast<T*
>(PagerReuse::get()));
678 inline T *
get(timeout_t timeout) {
679 return static_cast<T*
>(PagerReuse::get(timeout));
690 return init<T>(
static_cast<T*
>(PagerReuse::get(timeout)));
698 return static_cast<T*
>(PagerReuse::request());
723 inline operator T*() {
735 template<
typename T, vector
size_t S>
739 char buffer[
sizeof(array) + (S *
sizeof(
void *))];
752 inline const T&
at(
int index) {
756 inline T& operator[](
int index) {
bool operator!() const
Test if no objects are available for reuse or the pager.
T * get(void)
Get a typed object from the heap.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
vectorsize_t size(void) const
Get the effective allocation space used by the vector.
void release(ReusableObject *object)
Release resuable object.
Thread classes and sychronization objects.
T * operator*()
Get a typed object from the pager heap by type casting reference.
A base class for reference counted objects.
void release(T *object)
Release (return) a typed object back to the heap for re-use.
T * get(void)
Get a typed object from the pager heap.
static const vectorsize_t npos
npos is a constant for an "invalid" position value.
A mempager source of reusable objects.
ObjectProtocol * operator()(vectorsize_t position)
Retrieve a member of the vector directly.
T * create(void)
Create a typed object from the heap.
A managed private heap for small allocations.
T * create(void)
Get a typed object from the pager heap.
void add(ObjectProtocol **list)
Add (append) a NULL terminated list of objects to the vector.
array_reuse(unsigned count, void *memory)
Create reusable objects of specific type in preallocated memory.
array_reuse(unsigned count)
Create private heap of reusable objects of specified type.
vectorbuf()
Construct fixed sized vector object in heap or stack.
T * create(timeout_t timeout)
Create a typed object from the heap.
T * end(void)
Get the last typed object pointer contained in the fixed vector.
A managed vector for generic object pointers.
void operator+=(Vector &vector)
Append into our existing vector from another vector.
T * operator()(vectorsize_t position)
Retrieve a typed member of the fixed vector directly.
T * create(timeout_t timeout)
Create a typed object from the heap.
A redirection base class for the memory protocol.
T * operator*()
Get a typed object from the heap by pointer reference.
A common base class for all managed objects.
T * begin(void)
Get the first typed object pointer contained in the fixed vector.
Reusable objects for forming private heaps.
bool operator!() const
Test if the entire heap has been allocated.
ObjectProtocol * begin(void) const
Get the first object pointer contained in the vector.
Generic smart pointer class.
An array of reusable objects.
Vector & operator+(Vector &vector)
Concatenate into our existing vector from assignment list.
ObjectProtocol * get(int index) const
Get an object pointer from a specified member of the vector.
Vector with fixed size member list.
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
Common namespace for all ucommon objects.
T * begin(void)
Get the first typed object pointer contained in the vector.
Vector & operator+(Vector &vector)
Concatenate typed vector in an expression.
paged_reuse(mempager *pager, unsigned count)
Create a managed reusable typed object pool.
ObjectProtocol * end(void) const
Get the last object pointer contained in the vector.
Class for resource bound memory pools between threads.
const T & at(int index)
Get object pointer of specified type from fixed vector.
Mempager managed type factory for pager pool objects.
Vector & operator+(Vector &vector)
Concatenate fixed typed vector in an expression.
T * end(void)
Get the last typed object pointer contained in the vector.
void set(Vector &vector)
Set (duplicate) an existing vector into our vector.
A templated vector for a list of a specific Object subtype.
T * request(void)
Request immediately next available typed object from the heap.
vectorof()
Create an empty vector for specified type.
vectorof(vectorsize_t size)
Create an empty vector of allocated size for specified type.
void operator()(vectorsize_t position, ObjectProtocol *pointer)
Assign a member of the vector directly.
ObjectProtocol * operator[](int index)
Return a pointer from the vector by array reference.
T * operator()(vectorsize_t position)
Retrieve a typed member of the vector directly.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
void release(T *object)
Release (return) a typed object back to the pager heap for re-use.
void add(Vector &vector)
Add (append) an existing vector to our vector.
void operator=(Vector &vector)
Assign an existing vector into our fixed vector list.
T * request(void)
Request immediately next available typed object from the pager heap.
An array of reusable types.
A reusable private pool of reusable types.
void operator=(Vector &vector)
Assign (copy) into our existing vector from another vector.
void operator()(ObjectProtocol *pointer)
Append a member to the vector directly.
Allocated vector list of a specified type.