24 #ifndef _UCOMMON_GENERICS_H_
25 #define _UCOMMON_GENERICS_H_
27 #ifndef _UCOMMON_CPR_H_
38 #if defined(NEW_STDCPP) || defined(OLD_STDCPP)
39 #define THROW(x) throw x
40 #define THROWS(x) throw(x)
41 #define THROWS_ANY throw()
43 #define THROW(x) ::abort()
77 inline void set(T* ptr) {
87 if(
object == ref.object)
105 inline explicit pointer(T* ptr = NULL) : object(ptr) {
126 inline pointer& operator=(T *ptr) {
134 inline T& operator*()
const
137 inline T* operator->()
const
140 inline bool operator!()
const
143 inline operator bool()
const
152 template <
typename T>
169 inline void retain(
void) {
174 inline void set(T* ptr) {
184 if(array == ref.array)
231 inline T* operator*()
const
234 inline T& operator[](
size_t offset)
const
235 {
return array[offset];};
237 inline T* operator()(
size_t offset)
const
238 {
return &array[offset];};
240 inline bool operator!()
const
243 inline operator bool()
const
258 template <
typename T>
301 inline void set(T *temp) {
321 inline operator bool()
const
322 {
return object != NULL;};
324 inline bool operator!()
const
325 {
return object == NULL;};
327 inline ~temporary() {
345 template <
typename T>
357 {array =
new T[s]; size = s;};
366 for(
size_t p = 0; p < s; ++p)
370 inline void reset(
size_t s)
371 {
delete[] array; array =
new T[s]; size = s;};
373 inline void reset(
const T& initial,
size_t s) {
378 for(
size_t p = 0; p < s; ++p)
382 inline void set(
const T& initial) {
383 for(
size_t p = 0; p < size; ++p)
393 inline operator bool()
const
394 {
return array != NULL;};
396 inline bool operator!()
const
397 {
return array == NULL;};
399 inline ~temp_array() {
406 inline T& operator[](
size_t offset)
const {
407 crit(offset < size,
"array out of bound");
408 return array[offset];
411 inline T* operator()(
size_t offset)
const {
412 crit(offset < size,
"array out of bound");
413 return &array[offset];
434 {original = &object; temp = object;};
449 inline bool is(T&
object)
450 {
return object.operator bool();}
460 {
return (
bool)(
object.operator*() == NULL);}
470 {
return (
bool)(
object->operator*() == NULL);}
478 inline T*
dup(
const T&
object)
479 {
return new T(
object);}
482 inline void dupfree(T
object)
486 inline char *dup<char>(
const char& object)
487 {
return strdup(&
object);}
490 inline void dupfree<char*>(
char* object)
499 {
new((caddr_t)&
object) T;}
507 {memset((
void *)&
object, 0,
sizeof(T));
new((caddr_t)&
object) T;}
516 {memcpy((
void *)target, (
void *)source,
sizeof(T));}
525 {memcpy((
void *)&target, (
void *)source,
sizeof(T));}
543 inline T& (
max)(T& o1, T& o2)
545 return o1 > o2 ? o1 : o2;
555 inline T& (
min)(T& o1, T& o2)
557 return o1 < o2 ? o1 : o2;
568 inline T& (
limit)(T& value, T& low, T& high)
570 return (value < low) ? low : ((value > high) ? high : value);
~save_restore()
Restore original when stack frame is released.
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
temporary(T *ptr)
Construct an assigned pointer.
Save and restore global objects in function call stack frames.
Manage temporary array stored on the heap.
void cpr_memswap(void *mem1, void *mem2, size_t size)
Portable swap code.
temporary()
Construct a temporary object, create our stack frame reference.
void swap(T &o1, T &o2)
Convenience function to swap objects.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
void copy_unsafe(T *target, const T *source)
Convenience function to copy class.
temp_array(const T &initial, size_t s)
Construct a temporary object with a copy of some initial value.
void retain(ObjectProtocol *object)
Convenience function to access object retention.
Manage temporary object stored on the heap.
void store_unsafe(T &target, const T *source)
Convenience function to store object pointer into object.
Generic smart pointer class.
T * operator->() const
Access members of our heap object through our temporary.
T &() min(T &o1, T &o2)
Convenience function to return min of two objects.
A common string class and character string support functions.
temp_array(size_t s)
Construct a temporary object, create our stack frame reference.
Automatic integer counting class.
T & operator*() const
Access heap object through our temporary directly.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
void zero_unsafe(T &object)
Convenience function to zero an object and restore type info.
save_restore(T &object)
Save object into local copy and keep reference to the original object.
void set(T *temp)
Assign a temporary object.
T & operator=(T *temp)
Assign a temporary object.
temp_array(const temp_array< T > &)
Disable copy constructor.
bool isnull(T &object)
Convenience function to test pointer object.
void reset_unsafe(T &object)
Convenience function to reset an existing object.
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
bool is(T &object)
Convenience function to validate object assuming it is castable to bool.
bool isnullp(T *object)
Convenience function to test pointer-pointer object.
Generic smart array class.
temporary(const temporary< T > &)
Disable copy constructor.