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 #define THROWS(x) throw(x) 59 #define THROWS_ANY throw() 61 #define THROW(x) ::abort() 98 inline temporary(
size_t size,
const T initial) {
101 for(
size_t p = 0; p < size; ++p)
105 inline explicit temporary(
const T initial) {
111 inline ~temporary() {
118 inline operator T&()
const {
138 inline operator bool()
const {
139 return array != NULL;
142 inline bool operator!()
const {
143 return array == NULL;
146 inline temporary& operator=(
const T initial) {
151 inline void release() {
158 inline T& operator[](
size_t index)
const {
159 crit(index < used,
"array out of bound");
163 inline T* operator()(
size_t index)
const {
164 crit(index < used,
"array out of bound");
165 return &array[index];
168 inline void operator()(
size_t index,
const T value) {
169 crit(index < used,
"array out of bound");
170 array[index] = value;
173 inline T& value(
size_t index)
const {
174 crit(index < used,
"array out of bound");
178 inline void value(
size_t index,
const T value) {
179 crit(index < used,
"array out of bound");
180 array[index] = value;
183 inline size_t read(FILE *fp) {
184 return (fp == NULL) || (array == NULL) ?
185 0 : fread(array,
sizeof(T), used, fp);
188 inline size_t write(FILE *fp) {
189 return (fp == NULL) || (array == NULL) ?
190 0 : fwrite(array,
sizeof(T), used, fp);
193 inline size_t seek(FILE *fp,
long pos) {
194 return (fp == NULL) ?
195 0 : (fseek(fp,
sizeof(T) * pos, SEEK_CUR) /
sizeof(T));
200 class temporary<char *>
203 __DELETE_COPY(temporary);
213 inline temporary(
size_t size) {
214 object = (
char *)::malloc(size);
218 inline operator char *()
const {
222 inline size_t size()
const {
230 inline char *operator*()
const {
234 inline operator bool()
const {
235 return object != NULL;
238 inline bool operator!()
const {
239 return object == NULL;
242 inline void release() {
249 inline ~temporary() {
256 inline size_t read(FILE *fp) {
257 return (fp == NULL) || (
object == NULL) ?
261 inline size_t write(FILE *fp) {
262 return (fp == NULL) || (
object == NULL) ?
263 0 : fputs(
object, fp);
266 inline size_t seek(FILE *fp,
long pos) {
267 return (fp == NULL) ?
268 0 : fseek(fp, pos, SEEK_CUR);
273 class temporary<uint8_t *>
276 inline temporary(
const temporary<uint8_t *>&) {};
286 inline temporary(
size_t size) {
287 object = (uint8_t *)::malloc(size);
291 inline operator uint8_t *()
const {
295 inline size_t size()
const {
303 inline uint8_t *operator*()
const {
307 inline operator bool()
const {
308 return object != NULL;
311 inline bool operator!()
const {
312 return object == NULL;
315 inline void release() {
322 inline size_t read(FILE *fp) {
323 return (fp == NULL) || (
object == NULL) ?
324 0 : fread(
object, 1, used, fp);
327 inline size_t write(FILE *fp) {
328 return (fp == NULL) || (
object == NULL) ?
329 0 : fwrite(
object, 1, used, fp);
332 inline size_t seek(FILE *fp,
long pos) {
333 return (fp == NULL) ?
334 0 : fseek(fp, pos, SEEK_CUR);
337 inline size_t read(fsys& fs) {
339 if(!
object || (result = fs.read(
object, used)) < 0)
341 return (
size_t)result;
344 inline size_t write(fsys& fs) {
346 if(!
object || (result = fs.write(
object, used)) < 0)
348 return (
size_t)result;
351 inline ~temporary() {
size_t count(void) const
Count all characters in the string (strlen).
A common string class and character string support functions.
T * operator->() const
Access members of our heap object through our temporary.
Manage temporary object stored on the heap.
Thread classes and sychronization objects.
Private heaps, pools, and associations.
T & operator *() const
Access heap object through our temporary directly.
Various miscellaneous platform specific headers and defines.
Common namespace for all ucommon objects.
temporary(size_t size=1)
Construct a temporary object, create our stack frame reference.
Thread-aware file system manipulation class.
Abstract interfaces and support.