30 #ifndef _UCOMMON_PROTOCOLS_H_
31 #define _UCOMMON_PROTOCOLS_H_
33 #ifndef _UCOMMON_CPR_H_
42 class __EXPORT MemoryProtocol
45 friend class MemoryRedirect;
54 virtual void *_alloc(
size_t size) = 0;
59 virtual void fault(
void)
const;
62 virtual ~MemoryProtocol();
69 inline void *alloc(
size_t size)
70 {
return _alloc(size);};
79 void *zalloc(
size_t size);
87 char *
dup(
const char *
string);
95 void *
dup(
void *memory,
size_t size);
106 MemoryProtocol *target;
111 virtual void *_alloc(
size_t size);
124 virtual void _lock(
void);
125 virtual void _unlock(
void);
145 virtual const char *_print(
void)
const = 0;
166 virtual int _input(
int code) = 0;
186 virtual int _getch(
void) = 0;
193 virtual int _putch(
int code) = 0;
228 {
return _putch(code);};
244 size_t getline(
char *
string,
size_t size);
255 size_t getline(
String& buffer);
263 size_t putline(
const char *
string);
265 size_t putchars(
const char *
string,
size_t count = 0);
294 typedef enum {RDONLY, WRONLY, RDWR} mode_t;
298 char *input, *output;
299 size_t bufsize, bufpos, insize, outsize;
325 virtual void fault(
void)
const;
333 void allocate(
size_t size, mode_t
access = RDWR);
347 char *request(
size_t size);
355 char *gather(
size_t size);
364 virtual size_t _push(
const char *address,
size_t size) = 0;
373 virtual size_t _pull(
char *address,
size_t size) = 0;
379 virtual int _err(
void)
const = 0;
384 virtual void _clear(
void) = 0;
389 virtual bool _blocking(
void);
394 virtual bool _pending(
void);
399 virtual bool _flush(
void);
403 virtual int _putch(
int ch);
421 const char *endl(
void)
431 size_t put(
const void *address,
size_t count);
439 size_t get(
void *address,
size_t count);
447 size_t printf(
const char *format, ...) __PRINTF(2, 3);
453 inline
bool flush(
void)
476 inline operator bool()
477 {
return buffer != NULL;}
484 {
return buffer == NULL;}
491 {
return buffer != NULL;}
498 {
return input != NULL;}
505 {
return output != NULL;}
523 template<
typename T>
inline size_t write(
const T& data)
524 {
return put(&data,
sizeof(T));}
526 template<
typename T>
inline size_t read(T& data)
527 {
return get(&data,
sizeof(T));}
529 template<
typename T>
inline size_t write(
const T* data,
unsigned count)
530 {
return put(data,
sizeof(T) * count) /
sizeof(T);}
532 template<
typename T>
inline size_t read(T* data,
unsigned count)
533 {
return get(data,
sizeof(T) * count) /
sizeof(T);}
550 virtual void retain(
void) = 0;
555 virtual void release(
void) = 0;
608 {
return _character_operators::print(p, s);}
610 inline CharacterProtocol&
operator<< (CharacterProtocol& p,
const char& ch)
611 {
return _character_operators::print(p, ch);}
613 inline CharacterProtocol&
operator>> (CharacterProtocol& p,
char& ch)
614 {
return _character_operators::input(p, ch);}
616 inline CharacterProtocol&
operator>> (CharacterProtocol& p, String& str)
617 {
return _character_operators::input(p, str);}
619 inline CharacterProtocol&
operator<< (CharacterProtocol& p,
const PrintProtocol& format)
620 {p.print(format);
return p;}
622 inline CharacterProtocol&
operator>> (CharacterProtocol& p, InputProtocol& format)
623 {p.input(format);
return p;}
625 inline CharacterProtocol&
operator<< (CharacterProtocol& p,
const StringPager& list)
626 {p.save(&list);
return p;}
628 inline CharacterProtocol&
operator>> (CharacterProtocol& p, StringPager& list)
629 {p.load(&list);
return p;}
631 inline CharacterProtocol&
operator<< (CharacterProtocol& p,
const long& value)
632 {
return _character_operators::print(p, value);}
634 inline CharacterProtocol&
operator>> (CharacterProtocol& p,
long& value)
635 {
return _character_operators::input(p, value);}
637 inline CharacterProtocol&
operator<< (CharacterProtocol& p,
const double& value)
638 {
return _character_operators::print(p, value);}
640 inline CharacterProtocol&
operator>> (CharacterProtocol& p,
double& value)
641 {
return _character_operators::input(p, value);}
bool is_pending(void)
See if pending input.
Used for processing input.
bool operator!()
See if buffer closed.
void putback(int code)
Write to back buffer.
size_t output_waiting(void)
Get current output position.
String pager for storing lists of NULL terminated strings.
void access(SharedAccess &object)
Convenience function to access (lock) shared object through it's protocol.
Common character processing protocol.
void seteof(void)
Set eof flag.
At least with gcc, linking of stream operators was broken.
virtual int _putch(int code)=0
Put the next character.
Used for forming stream output.
ObjectProtocol * copy(ObjectProtocol *object)
Convenience function to access object copy.
bool is_output(void)
See if output active.
virtual int _getch(void)=0
Get the next character.
PersistEngine & operator>>(PersistEngine &ar, PersistObject &ob)
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
int getchar(void)
Get the next character.
int putchar(int code)
Put the next character.
size_t input_pending(void)
Get current input position.
A redirection base class for the memory protocol.
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
void seteol(const char *string)
Set end of line marker.
A copy-on-write string class that operates by reference count.
PersistEngine & operator<<(PersistEngine &ar, PersistObject const &ob)
A common base class for all managed objects.
bool is_open(void)
See if buffer open.
bool is_input(void)
See if input active.
void operator--(void)
Decrease retention operator.
Common buffer protocol class.
void operator++(void)
Increase retention operator.
void retain(ObjectProtocol *object)
Convenience function to access object retention.