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_
56#ifndef UCOMMON_SYSRUNTIME
57#define THROW(x) throw x
58#if __cplusplus > 199711L
62#define THROWS(x) throw(x)
63#define THROWS_ANY throw()
66#define THROW(x) ::abort()
103 inline temporary(
size_t size,
const T initial) {
106 for(
size_t p = 0; p < size; ++p)
110 inline explicit temporary(
const T initial) {
116 inline ~temporary() {
123 inline operator T&()
const {
143 inline operator bool()
const {
144 return array != NULL;
147 inline bool operator!()
const {
148 return array == NULL;
151 inline temporary& operator=(
const T initial) {
156 inline void release() {
163 inline T& operator[](
size_t index)
const {
164 crit(index < used,
"array out of bound");
168 inline T* operator()(
size_t index)
const {
169 crit(index < used,
"array out of bound");
170 return &array[index];
173 inline void operator()(
size_t index,
const T value) {
174 crit(index < used,
"array out of bound");
175 array[index] = value;
178 inline T& value(
size_t index)
const {
179 crit(index < used,
"array out of bound");
183 inline void value(
size_t index,
const T value) {
184 crit(index < used,
"array out of bound");
185 array[index] = value;
188 inline size_t read(FILE *fp) {
189 return (fp == NULL) || (array == NULL) ?
190 0 : fread(array,
sizeof(T), used, fp);
193 inline size_t write(FILE *fp) {
194 return (fp == NULL) || (array == NULL) ?
195 0 : fwrite(array,
sizeof(T), used, fp);
198 inline size_t seek(FILE *fp,
long pos) {
199 return (fp == NULL) ?
200 0 : (fseek(fp,
sizeof(T) * pos, SEEK_CUR) /
sizeof(T));
205class temporary<char *>
208 __DELETE_COPY(temporary);
218 inline temporary(
size_t size) {
219 object = (
char *)::malloc(size);
223 inline operator char *()
const {
227 inline size_t size()
const {
235 inline char *operator*()
const {
239 inline operator bool()
const {
240 return object != NULL;
243 inline bool operator!()
const {
244 return object == NULL;
247 inline void release() {
254 inline ~temporary() {
261 inline size_t read(FILE *fp) {
262 return (fp == NULL) || (
object == NULL) ?
266 inline size_t write(FILE *fp) {
267 return (fp == NULL) || (
object == NULL) ?
268 0 : fputs(
object, fp);
271 inline size_t seek(FILE *fp,
long pos) {
272 return (fp == NULL) ?
273 0 : fseek(fp, pos, SEEK_CUR);
278class temporary<uint8_t *>
281 inline temporary(
const temporary<uint8_t *>&) {};
291 inline temporary(
size_t size) {
292 object = (uint8_t *)::malloc(size);
296 inline operator uint8_t *()
const {
300 inline size_t size()
const {
308 inline uint8_t *operator*()
const {
312 inline operator bool()
const {
313 return object != NULL;
316 inline bool operator!()
const {
317 return object == NULL;
320 inline void release() {
327 inline size_t read(FILE *fp) {
328 return (fp == NULL) || (
object == NULL) ?
329 0 : fread(
object, 1, used, fp);
332 inline size_t write(FILE *fp) {
333 return (fp == NULL) || (
object == NULL) ?
334 0 : fwrite(
object, 1, used, fp);
337 inline size_t seek(FILE *fp,
long pos) {
338 return (fp == NULL) ?
339 0 : fseek(fp, pos, SEEK_CUR);
342 inline size_t read(fsys& fs) {
344 if(!
object || (result = fs.read(
object, used)) < 0)
346 return (
size_t)result;
349 inline size_t write(fsys& fs) {
351 if(!
object || (result = fs.write(
object, used)) < 0)
353 return (
size_t)result;
356 inline ~temporary() {
Private heaps, pools, and associations.
Thread-aware file system manipulation class.
Abstract interfaces and support.
Various miscellaneous platform specific headers and defines.
Common namespace for all ucommon objects.
size_t count(void) const
Count all characters in the string (strlen).
Manage temporary object stored on the heap.
T * operator->() const
Access members of our heap object through our temporary.
T & operator*() const
Access heap object through our temporary directly.
temporary(size_t size=1)
Construct a temporary object, create our stack frame reference.
A common string class and character string support functions.
Thread classes and sychronization objects.