25 #ifndef _UCOMMON_TEMPORARY_H_
26 #define _UCOMMON_TEMPORARY_H_
28 #ifndef _UCOMMON_CONFIG_H_
32 #ifndef _UCOMMON_PROTOCOLS_H_
36 #ifndef _UCOMMON_THREAD_H_
40 #ifndef _UCOMMON_STRING_H_
44 #ifndef _UCOMMON_MEMORY_H_
48 #ifndef _UCOMMON_FSYS_H_
52 #ifndef _UCOMMON_FILE_H_
60 #ifndef UCOMMON_SYSRUNTIME
61 #define THROW(x) throw x
62 #define THROWS(x) throw(x)
63 #define THROWS_ANY throw()
65 #define THROW(x) ::abort()
102 inline temporary(
size_t size,
const T initial) {
105 for(
size_t p = 0; p < size; ++p)
109 inline explicit temporary(
const T initial) {
115 inline ~temporary() {
122 inline operator T&()
const {
142 inline operator bool()
const {
143 return array != NULL;
146 inline bool operator!()
const {
147 return array == NULL;
150 inline temporary& operator=(
const T initial) {
155 inline void release() {
162 inline T& operator[](
size_t index)
const {
163 crit(index < used,
"array out of bound");
167 inline T* operator()(
size_t index)
const {
168 crit(index < used,
"array out of bound");
169 return &array[index];
172 inline void operator()(
size_t index,
const T value) {
173 crit(index < used,
"array out of bound");
174 array[index] = value;
177 inline T& value(
size_t index)
const {
178 crit(index < used,
"array out of bound");
182 inline void value(
size_t index,
const T value) {
183 crit(index < used,
"array out of bound");
184 array[index] = value;
187 inline size_t read(file& fp) {
188 return (*fp == NULL) || (array == NULL) ?
189 0 : fread(array,
sizeof(T), used, *fp);
192 inline size_t write(file& fp) {
193 return (*fp == NULL) || (array == NULL) ?
194 0 : fwrite(array,
sizeof(T), used, *fp);
197 inline size_t seek(file& fp,
long pos) {
198 return (*fp == NULL) ?
199 0 : (fseek(*fp,
sizeof(T) * pos, SEEK_CUR) /
sizeof(T));
204 class temporary<char *>
207 __DELETE_COPY(temporary);
217 inline temporary(
size_t size) {
218 object = (
char *)::malloc(size);
222 inline operator char *()
const {
226 inline size_t size()
const {
234 inline char *operator*()
const {
238 inline operator bool()
const {
239 return object != NULL;
242 inline bool operator!()
const {
243 return object == NULL;
253 inline ~temporary() {
260 inline size_t read(file& fp) {
261 return (*fp == NULL) || (
object == NULL) ?
265 inline size_t write(file& fp) {
266 return (*fp == NULL) || (
object == NULL) ?
267 0 : fputs(
object, *fp);
270 inline size_t seek(file& fp,
long pos) {
271 return (*fp == NULL) ?
272 0 : fseek(*fp, pos, SEEK_CUR);
277 class temporary<uint8_t *>
280 inline temporary(
const temporary<uint8_t *>&) {};
290 inline temporary(
size_t size) {
291 object = (uint8_t *)::malloc(size);
295 inline operator uint8_t *()
const {
299 inline size_t size()
const {
307 inline uint8_t *operator*()
const {
311 inline operator bool()
const {
312 return object != NULL;
315 inline bool operator!()
const {
316 return object == NULL;
326 inline size_t read(file& fp) {
327 return (*fp == NULL) || (
object == NULL) ?
328 0 : fread(
object, 1, used, *fp);
331 inline size_t write(file& fp) {
332 return (*fp == NULL) || (
object == NULL) ?
333 0 : fwrite(
object, 1, used, *fp);
336 inline size_t seek(file& fp,
long pos) {
337 return (*fp == NULL) ?
338 0 : fseek(*fp, pos, SEEK_CUR);
341 inline size_t read(fsys& fs) {
343 if(!
object || (result = fs.read(
object, used)) < 0)
345 return (
size_t)result;
348 inline size_t write(fsys& fs) {
350 if(!
object || (result = fs.write(
object, used)) < 0)
352 return (
size_t)result;
355 inline ~temporary() {
A common string class and character string support functions.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
Thread classes and sychronization objects.
Various miscellaneous platform specific headers and defines.
Thread-aware file system manipulation class.
Adaption of C runtime FILE processing.
Manage temporary object stored on the heap.
T * operator->() const
Access members of our heap object through our temporary.
Private heaps, pools, and associations.
T & operator*() const
Access heap object through our temporary directly.
temporary(size_t size=1)
Construct a temporary object, create our stack frame reference.
Common namespace for all ucommon objects.
strsize_t count(void) const
Count all characters in the string (strlen).
Abstract interfaces and support.