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);
401 virtual int _getch(
void);
403 virtual int _putch(
int ch);
421 const char *endl(
void)
const
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()
const
477 {
return buffer != NULL;}
484 {
return buffer == NULL;}
491 {
return buffer != NULL;}
498 {
return input != NULL;}
505 {
return output != NULL;}
520 inline int err(
void)
const
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;
586 virtual int keytype(
void)
const = 0;
591 virtual size_t keysize(
void)
const = 0;
596 virtual const void *
keydata(
void)
const = 0;
598 virtual bool equal(
const KeyProtocol& compare)
const;
600 inline bool operator!=(
const KeyProtocol& compare)
const {
601 return !equal(compare);
635 {
return _character_operators::print(p, s);}
637 inline CharacterProtocol& operator<< (CharacterProtocol& p,
const char& ch)
638 {
return _character_operators::print(p, ch);}
640 inline CharacterProtocol& operator>> (CharacterProtocol& p,
char& ch)
641 {
return _character_operators::input(p, ch);}
643 inline CharacterProtocol& operator>> (CharacterProtocol& p, String& str)
644 {
return _character_operators::input(p, str);}
646 inline CharacterProtocol& operator<< (CharacterProtocol& p,
const PrintProtocol& format)
647 {p.print(format);
return p;}
649 inline CharacterProtocol& operator>> (CharacterProtocol& p, InputProtocol& format)
650 {p.input(format);
return p;}
652 inline CharacterProtocol& operator<< (CharacterProtocol& p,
const StringPager& list)
653 {p.save(&list);
return p;}
655 inline CharacterProtocol& operator>> (CharacterProtocol& p, StringPager& list)
656 {p.load(&list);
return p;}
658 inline CharacterProtocol& operator<< (CharacterProtocol& p,
const long& value)
659 {
return _character_operators::print(p, value);}
661 inline CharacterProtocol& operator>> (CharacterProtocol& p,
long& value)
662 {
return _character_operators::input(p, value);}
664 inline CharacterProtocol& operator<< (CharacterProtocol& p,
const double& value)
665 {
return _character_operators::print(p, value);}
667 inline CharacterProtocol& operator>> (CharacterProtocol& p,
double& value)
668 {
return _character_operators::input(p, value);}
A common base class for all managed objects.
size_t input_pending(void) const
Get current input position.
void putback(int code)
Write to back buffer.
At least with gcc, linking of stream operators was broken.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
A redirection base class for the memory protocol.
A copy-on-write string class that operates by reference count.
Common namespace for all ucommon objects.
bool is_pending(void)
See if pending input.
bool is_input(void) const
See if input active.
void retain(ObjectProtocol *object)
Convenience function to access object retention.
void seteof(void)
Set eof flag.
void operator++(void)
Increase retention operator.
bool operator!() const
See if buffer closed.
int putchar(int code)
Put the next character.
void operator--(void)
Decrease retention operator.
Common buffer protocol class.
int getchar(void)
Get the next character.
String pager for storing lists of NULL terminated strings.
Key data protocol used for things like maps and ordered lists.
ObjectProtocol * copy(ObjectProtocol *object)
Convenience function to access object copy.
size_t output_waiting(void) const
Get current output position.
bool is_open(void) const
See if buffer open.
Used for processing input.
void seteol(const char *string)
Set end of line marker.
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
void access(SharedAccess &object)
Convenience function to access (lock) shared object through it's protocol.
bool is_output(void) const
See if output active.
Data keys parsed from a keyfile.
Common character processing protocol.
Used for forming stream output.