UCommon
protocols.h
Go to the documentation of this file.
1// Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2// Copyright (C) 2015 Cherokees of Idaho.
3//
4// This file is part of GNU uCommon C++.
5//
6// GNU uCommon C++ is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// GNU uCommon C++ is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18
31#ifndef _UCOMMON_PROTOCOLS_H_
32#define _UCOMMON_PROTOCOLS_H_
33
34#ifndef _UCOMMON_CPR_H_
35#include <ucommon/cpr.h>
36#endif
37
38namespace ucommon {
39
40class String;
41class StringPager;
42
43class __EXPORT MemoryProtocol
44{
45protected:
46 friend class MemoryRedirect;
47
55 virtual void *_alloc(size_t size) = 0;
56
57public:
58 virtual ~MemoryProtocol();
59
65 inline void *alloc(size_t size) {
66 return _alloc(size);
67 }
68
76 void *zalloc(size_t size);
77
84 char *dup(const char *string);
85
92 void *dup(void *memory, size_t size);
93};
94
100class __EXPORT MemoryRedirect : public __PROTOCOL MemoryProtocol
101{
102private:
103 MemoryProtocol *target;
104
105public:
106 MemoryRedirect(MemoryProtocol *protocol);
107
108 virtual void *_alloc(size_t size) __OVERRIDE;
109};
110
118class __EXPORT LockingProtocol
119{
120protected:
121 virtual void _lock(void);
122 virtual void _unlock(void);
123
124public:
125 virtual ~LockingProtocol();
126};
127
134class __EXPORT PrintProtocol
135{
136public:
137 virtual ~PrintProtocol();
138
142 virtual const char *_print(void) const = 0;
143};
144
153class __EXPORT InputProtocol
154{
155public:
156 virtual ~InputProtocol();
157
163 virtual int _input(int code) = 0;
164};
165
173class __EXPORT ObjectProtocol
174{
175public:
179 virtual void retain(void) = 0;
180
184 virtual void release(void) = 0;
185
190
195
199 inline void operator++(void) {
200 retain();
201 }
202
206 inline void operator--(void) {
207 release();
208 }
209};
210
214class __EXPORT KeyProtocol
215{
216protected:
217 virtual int keytype(void) const = 0;
218
222 virtual size_t keysize(void) const = 0;
223
227 virtual const void *keydata(void) const = 0;
228
229 virtual bool equal(const KeyProtocol& compare) const;
230
231 inline bool operator!=(const KeyProtocol& compare) const {
232 return !equal(compare);
233 }
234
235 virtual ~KeyProtocol();
236};
237
238} // namespace ucommon
239
240#endif
Runtime functions.
Common namespace for all ucommon objects.
Definition access.h:47
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
Definition generics.h:324
A redirection base class for the memory protocol.
Definition protocols.h:101
Common locking protocol.
Definition protocols.h:119
Used for forming stream output.
Definition protocols.h:135
virtual const char * _print(void) const =0
Extract formatted string for object.
Used for processing input.
Definition protocols.h:154
virtual int _input(int code)=0
Extract formatted string for object.
A common base class for all managed objects.
Definition protocols.h:174
virtual void release(void)=0
Method to release (or decrease retention) of an object.
void operator--(void)
Decrease retention operator.
Definition protocols.h:206
void operator++(void)
Increase retention operator.
Definition protocols.h:199
virtual ~ObjectProtocol()
Required virtual destructor.
ObjectProtocol * copy(void)
Retain (increase retention of) object when copying.
virtual void retain(void)=0
Method to retain (or increase retention) of an object.
Key data protocol used for things like maps and ordered lists.
Definition protocols.h:215
virtual size_t keysize(void) const =0
Size of key data.
virtual const void * keydata(void) const =0
Buffer of key value.