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
37public:
40 ZF_OUT void *buf
41 , ZF_IN zfindex count
42 ) const {
43 if(this->valid()) {
45 }
46 else {
47 return zfindexMax();
48 }
49 }
50
51 inline zfindex operator () (
52 ZF_OUT void *buf
53 , ZF_IN zfindex count
54 ) const {
55 if(this->valid()) {
57 }
58 else {
59 return zfindexMax();
60 }
61 }
62
63 const ZFInput &input(
64 ZF_OUT void *buf
65 , ZF_IN zfindex count
66 , ZF_OUT_OPT zfindex *result = zfnull
67 ) const {
68 if(result != zfnull) {
69 *result = this->execute(buf, count);
70 }
71 else {
72 this->execute(buf, count);
73 }
74 return *this;
75 }
76
77 const ZFInput &input(
78 ZF_OUT zfstring &buf
79 , ZF_IN zfindex count
80 , ZF_OUT_OPT zfindex *result = zfnull
81 ) const {
82 zfindex blockSize = zfmMin(count, (zfindex)128);
83 do {
84 buf.capacity(buf.length() + blockSize + 1);
85 zfindex read = this->execute(buf.zfunsafe_buffer() + buf.length(), blockSize);
86 if(read == 0 || read == zfindexMax()) {
87 break;
88 }
89 buf.zfunsafe_length(buf.length() + read);
90 buf.zfunsafe_buffer()[buf.length()] = '\0';
91 if(count != zfindexMax()) {
92 count -= blockSize;
93 if(count == 0) {
94 break;
95 }
96 }
97 } while(zftrue);
98 return *this;
99 }
100_ZFP_ZFCALLBACK_DECLARE_END_NO_ALIAS(ZFLIB_ZFCore, ZFInput, ZFIOCallback)
101
102// ============================================================
103// ZFInputDummy
114#define ZFCallbackSerializeType_ZFInputDummy "ZFInputDummy"
119
120// ============================================================
121// ZFInputForInputInRange
137#define ZFCallbackSerializeType_ZFInputForInputInRange "ZFInputForInputInRange"
138
140#define ZFSerializableKeyword_ZFInputForInputInRange_input "input"
142#define ZFSerializableKeyword_ZFInputForInputInRange_start "start"
144#define ZFSerializableKeyword_ZFInputForInputInRange_count "count"
146#define ZFSerializableKeyword_ZFInputForInputInRange_autoRestorePos "autoRestorePos"
160 ZF_IN const ZFInput &inputCallback
161 , ZF_IN_OPT zfindex start = 0
162 , ZF_IN_OPT zfindex count = zfindexMax()
163 , ZF_IN_OPT zfbool autoRestorePos = zftrue
164 );
165
166// ============================================================
167// ZFInputForBuffer
180#define ZFCallbackSerializeType_ZFInputForBuffer "ZFInputForBuffer"
181
183#define ZFSerializableKeyword_ZFInputForBuffer_buf "buf"
184
195 ZF_IN const void *src
196 , ZF_IN_OPT zfindex count = zfindexMax()
197 , ZF_IN_OPT zfbool serializable = zffalse
198 );
204 ZF_IN const void *src
205 , ZF_IN_OPT zfindex count = zfindexMax()
206 , ZF_IN_OPT zfbool serializable = zffalse
207 );
208
215 ZF_IN const zfstring &src
216 , ZF_IN_OPT zfbool serializable = zffalse
217 );
218
220#endif // #ifndef _ZFI_ZFIOCallback_input_h_
221
#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:36
const ZFInput & input(void *buf, zfindex count, zfindex *result=zft_zfnull) const
see ZFInput
Definition ZFIOCallback_input.h:63
const ZFInput & input(zfstring &buf, zfindex count, zfindex *result=zft_zfnull) const
see ZFInput
Definition ZFIOCallback_input.h:77
zfindex execute(void *buf, zfindex count) const
see ZFInput
Definition ZFIOCallback_input.h:39