ZFFramework
 
Loading...
Searching...
No Matches
ZFIOCallback_input.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFIOCallback_input_h_
7#define _ZFI_ZFIOCallback_input_h_
8
9#include "ZFIOCallback_fwd.h"
11
12// ============================================================
13// ZFInput
36public:
39 ZF_OUT void *buf
40 , ZF_IN zfindex count
41 ) const {
42 if(this->valid()) {
44 }
45 else {
46 return 0;
47 }
48 }
49
50 inline zfindex operator () (
51 ZF_OUT void *buf
52 , ZF_IN zfindex count
53 ) const {
54 if(this->valid()) {
56 }
57 else {
58 return 0;
59 }
60 }
61
62 const ZFInput &input(
63 ZF_OUT void *buf
64 , ZF_IN zfindex count
65 , ZF_OUT_OPT zfindex *result = zfnull
66 ) const {
67 if(result != zfnull) {
68 *result = this->execute(buf, count);
69 }
70 else {
71 this->execute(buf, count);
72 }
73 return *this;
74 }
75
76 const ZFInput &input(
77 ZF_OUT zfstring &buf
78 , ZF_IN zfindex count
79 , ZF_OUT_OPT zfindex *result = zfnull
80 ) const {
81 zfindex blockSize = zfmMin(count, (zfindex)128);
82 do {
83 buf.capacity(buf.length() + blockSize + 1);
84 zfindex read = this->execute(buf.zfunsafe_buffer() + buf.length(), blockSize);
85 if(read == 0) {
86 break;
87 }
88 buf.zfunsafe_length(buf.length() + read);
89 buf.zfunsafe_buffer()[buf.length()] = '\0';
90 if(count != zfindexMax()) {
91 count -= blockSize;
92 if(count == 0) {
93 break;
94 }
95 }
96 } while(zftrue);
97 return *this;
98 }
99_ZFP_ZFCALLBACK_DECLARE_END_NO_ALIAS(ZFLIB_ZFCore, ZFInput, ZFIOCallback)
100
101// ============================================================
102// ZFInputDummy
113#define ZFCallbackSerializeType_ZFInputDummy "ZFInputDummy"
118
119// ============================================================
120// ZFInputForInputInRange
136#define ZFCallbackSerializeType_ZFInputForInputInRange "ZFInputForInputInRange"
137
139#define ZFSerializableKeyword_ZFInputForInputInRange_input "input"
141#define ZFSerializableKeyword_ZFInputForInputInRange_start "start"
143#define ZFSerializableKeyword_ZFInputForInputInRange_count "count"
145#define ZFSerializableKeyword_ZFInputForInputInRange_autoRestorePos "autoRestorePos"
159 ZF_IN const ZFInput &inputCallback
160 , ZF_IN_OPT zfindex start = 0
161 , ZF_IN_OPT zfindex count = zfindexMax()
162 , ZF_IN_OPT zfbool autoRestorePos = zftrue
163 );
164
165// ============================================================
166// ZFInputForBuffer
179#define ZFCallbackSerializeType_ZFInputForBuffer "ZFInputForBuffer"
180
182#define ZFSerializableKeyword_ZFInputForBuffer_buf "buf"
183
194 ZF_IN const void *src
195 , ZF_IN_OPT zfindex count = zfindexMax()
196 , ZF_IN_OPT zfbool serializable = zffalse
197 );
203 ZF_IN const void *src
204 , ZF_IN_OPT zfindex count = zfindexMax()
205 , ZF_IN_OPT zfbool serializable = zffalse
206 );
207
214 ZF_IN const zfstring &src
215 , ZF_IN_OPT zfbool serializable = zffalse
216 );
217
219#endif // #ifndef _ZFI_ZFIOCallback_input_h_
220
#define ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType)
util macro to declare a child type of ZFCallback
Definition ZFCallback.h:479
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define ZF_OUT_OPT
dummy macro that shows the param used as optional output
Definition ZFCoreTypeDef_ClassType.h:192
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
T_Number const & zfmMin(T_Number const &n0, T_Number const &n1)
well known MIN
Definition ZFCoreUtilMath.h:27
common callback defines
ZFInput ZFInputForString(const zfstring &src, zfbool serializable=_ZFT_t_zffalse)
create a input callback from string
ZFInput ZFInputDummy(void)
a dummy input that always read zero byte with success state
ZFInput ZFInputForBufferUnsafe(const void *src, zfindex count=((zfindex) -1), zfbool serializable=_ZFT_t_zffalse)
create a intput callback input from a const void *, you must ensure the buffer is alive during the ca...
ZFInput ZFInputForInputInRange(const ZFInput &inputCallback, zfindex start=0, zfindex count=((zfindex) -1), zfbool autoRestorePos=_ZFT_t_zftrue)
create a intput callback from another input callback, specified in range
ZFInput ZFInputForBuffer(const void *src, zfindex count=((zfindex) -1), zfbool serializable=_ZFT_t_zffalse)
see ZFInputForBufferUnsafe, copy the contents and auto free it
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
T_ReturnType executeExact() const
see ZFCallback, you must assign the exact return type and param types for safe
Definition ZFCallback.h:131
zfbool valid(void) const
return true if callback is valid
Definition ZFCallback.h:259
abstract base class, use ZFOutput or ZFInput
Definition ZFIOCallback_fwd.h:62
general input callback
Definition ZFIOCallback_input.h:35
const ZFInput & input(void *buf, zfindex count, zfindex *result=zft_zfnull) const
see ZFInput
Definition ZFIOCallback_input.h:62
const ZFInput & input(zfstring &buf, zfindex count, zfindex *result=zft_zfnull) const
see ZFInput
Definition ZFIOCallback_input.h:76
zfindex execute(void *buf, zfindex count) const
see ZFInput
Definition ZFIOCallback_input.h:38