25#ifndef _UCOMMON_ARRAYREF_H_
26#define _UCOMMON_ARRAYREF_H_
28#ifndef _UCOMMON_CPR_H_
32#ifndef _UCOMMON_ATOMIC_H_
36#ifndef _UCOMMON_PROTOCOLS_H_
40#ifndef _UCOMMON_OBJECT_H_
44#ifndef _UCOMMON_TYPEREF_H_
48#ifndef _UCOMMON_THREAD_H_
54class __EXPORT ArrayRef :
public TypeRef
57 typedef enum {ARRAY, STACK, QUEUE, FALLBACK} arraytype_t;
59 class __EXPORT Array :
public Counted,
public ConditionalAccess
62 __DELETE_DEFAULTS(Array);
65 friend class ArrayRef;
71 explicit Array(arraytype_t mode,
void *addr,
size_t size);
73 void assign(
size_t index, Counted *
object);
75 Counted *remove(
size_t index);
79 virtual void dealloc() __OVERRIDE;
81 inline Counted **get(
void) {
82 return reinterpret_cast<Counted **
>(((caddr_t)(
this)) +
sizeof(Array));
85 Counted *get(
size_t index);
88 ArrayRef(arraytype_t mode,
size_t size);
89 ArrayRef(arraytype_t mode,
size_t size, TypeRef&
object);
90 ArrayRef(
const ArrayRef& copy);
93 void assign(
size_t index, TypeRef& t);
95 void reset(TypeRef&
object);
97 void reset(Counted *
object);
99 Counted *get(
size_t index);
101 bool is(
size_t index);
103 static Array *create(arraytype_t type,
size_t size);
106 void push(
const TypeRef&
object);
108 void pull(TypeRef&
object);
110 bool push(
const TypeRef&
object, timeout_t timeout);
112 void pull(TypeRef&
object, timeout_t timeout);
117 void resize(
size_t size);
119 void realloc(
size_t size);
127class stackref :
public ArrayRef
130 inline stackref() : ArrayRef() {};
132 inline stackref(
const stackref&
copy) : ArrayRef(
copy) {};
134 inline stackref(
size_t size) : ArrayRef(STACK,
size + 1) {};
136 inline stackref& operator=(
const stackref&
copy) {
141 inline typeref<T> operator[](
size_t index) {
142 return typeref<T>(ArrayRef::get(index));
145 inline typeref<T> operator()(
size_t index) {
146 return typeref<T>(ArrayRef::get(index));
149 inline typeref<T> at(
size_t index) {
150 return typeref<T>(ArrayRef::get(index));
153 inline void release(
void) {
157 inline typeref<T> pull() {
163 inline typeref<T> pull(timeout_t timeout) {
165 ArrayRef::pull(obj, timeout);
169 inline stackref& operator>>(typeref<T>& target) {
170 ArrayRef::pull(target);
174 inline void push(
const typeref<T>& source) {
175 ArrayRef::push(source);
178 inline bool push(
const typeref<T>& source, timeout_t timeout) {
179 return ArrayRef::push(source, timeout);
182 inline stackref& operator<<(
const typeref<T>& source) {
183 ArrayRef::push(source);
187 inline stackref& operator<<(T t) {
195class queueref :
public ArrayRef
198 inline queueref() : ArrayRef() {};
200 inline queueref(
const queueref&
copy) : ArrayRef(
copy) {};
202 inline queueref(
size_t size,
bool fallback =
false) : ArrayRef(fallback ? FALLBACK : QUEUE,
size + 1) {};
204 inline queueref& operator=(
const queueref&
copy) {
209 inline typeref<T> operator[](
size_t index) {
210 return typeref<T>(ArrayRef::get(index));
213 inline typeref<T> operator()(
size_t index) {
214 return typeref<T>(ArrayRef::get(index));
217 inline typeref<T> at(
size_t index) {
218 return typeref<T>(ArrayRef::get(index));
221 inline void release(
void) {
225 inline typeref<T> pull() {
231 inline typeref<T> pull(timeout_t timeout) {
233 ArrayRef::pull(obj, timeout);
237 inline queueref& operator>>(typeref<T>& target) {
238 ArrayRef::pull(target);
242 inline void push(
const typeref<T>& source) {
243 ArrayRef::push(source);
246 inline bool push(
const typeref<T>& source, timeout_t timeout) {
247 return ArrayRef::push(source, timeout);
250 inline queueref& operator<<(
const typeref<T>& source) {
251 ArrayRef::push(source);
255 inline queueref& operator<<(T t) {
263class arrayref :
public ArrayRef
266 inline arrayref() : ArrayRef() {};
268 inline arrayref(
const arrayref&
copy) : ArrayRef(
copy) {};
270 inline arrayref(
size_t size) : ArrayRef(ARRAY,
size) {};
272 inline arrayref(
size_t size, typeref<T>& t) : ArrayRef(ARRAY,
size, t) {};
274 inline arrayref(
size_t size, T t) : ArrayRef(ARRAY,
size) {
279 inline arrayref& operator=(
const arrayref&
copy) {
284 inline arrayref& operator=(typeref<T>& t) {
289 inline arrayref& operator=(T t) {
294 inline typeref<T> operator[](
size_t index) {
295 return typeref<T>(ArrayRef::get(index));
298 inline typeref<T> operator()(
size_t index) {
299 return typeref<T>(ArrayRef::get(index));
302 inline typeref<T> at(
size_t index) {
303 return typeref<T>(ArrayRef::get(index));
306 inline typeref<T> value(
size_t index) {
307 return typeref<T>(ArrayRef::get(index));
310 inline void value(
size_t index, typeref<T>& t) {
311 ArrayRef::assign(index, t);
314 inline void put(typeref<T>& target,
size_t index) {
318 inline void operator()(
size_t index, typeref<T>& t) {
319 ArrayRef::assign(index, t);
322 inline void operator()(
size_t index, T t) {
324 ArrayRef::assign(index, v);
327 inline void release(
void) {
332typedef arrayref<Type::Bytes> bytearray_t;
333typedef arrayref<Type::Chars> stringarray_t;
A thread-safe atomic heap management system.
Atomic pointers and locks.
Abstract interfaces and support.
Common namespace for all ucommon objects.
T copy(const T &src)
Convenience function to copy objects.
bool is(T &object)
Convenience function to validate object assuming it is castable to bool.
void set(Counted *object)
Set our smart pointer to a specific heap container.
size_t size(void) const
Get size of referenced heap object.
static void put(TypeRef &target, Counted *object)
Special weak-public means to copy a container reference.
A common object base class with auto-pointer support.
Thread classes and sychronization objects.