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
38public:
41 ZF_OUT void *buf
42 , ZF_IN zfindex count
43 ) const {
44 if(this->valid()) {
46 }
47 else {
48 return 0;
49 }
50 }
51
52 inline zfindex operator () (
53 ZF_OUT void *buf
54 , ZF_IN zfindex count
55 ) const {
56 if(this->valid()) {
58 }
59 else {
60 return 0;
61 }
62 }
63
64 const ZFInput &input(
65 ZF_OUT void *buf
66 , ZF_IN zfindex count
67 , ZF_OUT_OPT zfindex *result = zfnull
68 ) const {
69 if(result != zfnull) {
70 *result = this->execute(buf, count);
71 }
72 else {
73 this->execute(buf, count);
74 }
75 return *this;
76 }
77
78 const ZFInput &input(
79 ZF_OUT zfstring &buf
80 , ZF_IN zfindex count
81 , ZF_OUT_OPT zfindex *result = zfnull
82 ) const {
83 if(count == zfindexMax()) {
84 count = this->execute(zfnull, zfindexMax());
85 if(count == zfindexMax()) {
86 if(result != zfnull) {
87 *result = zfindexMax();
88 }
89 return *this;
90 }
91 }
92 void *bufTmp = zfmalloc(count);
93 zfindex read = this->execute(bufTmp, count);
94 if(read > count) {
95 zffree(bufTmp);
96 if(result != zfnull) {
97 *result = zfindexMax();
98 }
99 return *this;
100 }
101 buf.append((const zfchar *)bufTmp, read);
102 zffree(bufTmp);
103 if(result != zfnull) {
104 *result = read;
105 }
106 return *this;
107 }
108_ZFP_ZFCALLBACK_DECLARE_END_NO_ALIAS(ZFLIB_ZFCore, ZFInput, ZFIOCallback)
109
110// ============================================================
111// ZFInputDummy
122#define ZFCallbackSerializeType_ZFInputDummy "ZFInputDummy"
127
128// ============================================================
129// ZFInputForInputInRange
145#define ZFCallbackSerializeType_ZFInputForInputInRange "ZFInputForInputInRange"
146
148#define ZFSerializableKeyword_ZFInputForInputInRange_input "input"
150#define ZFSerializableKeyword_ZFInputForInputInRange_start "start"
152#define ZFSerializableKeyword_ZFInputForInputInRange_count "count"
154#define ZFSerializableKeyword_ZFInputForInputInRange_autoRestorePos "autoRestorePos"
168 ZF_IN const ZFInput &inputCallback
169 , ZF_IN_OPT zfindex start = 0
170 , ZF_IN_OPT zfindex count = zfindexMax()
171 , ZF_IN_OPT zfbool autoRestorePos = zftrue
172 );
173
174// ============================================================
175// ZFInputForBuffer
188#define ZFCallbackSerializeType_ZFInputForBuffer "ZFInputForBuffer"
189
191#define ZFSerializableKeyword_ZFInputForBuffer_buf "buf"
192
203 ZF_IN const void *src
204 , ZF_IN_OPT zfindex count = zfindexMax()
205 , ZF_IN_OPT zfbool serializable = zffalse
206 );
212 ZF_IN const void *src
213 , ZF_IN_OPT zfindex count = zfindexMax()
214 , ZF_IN_OPT zfbool serializable = zffalse
215 );
216
223 ZF_IN const zfstring &src
224 , ZF_IN_OPT zfbool serializable = zffalse
225 );
226
228#endif // #ifndef _ZFI_ZFIOCallback_input_h_
229
#define ZFCALLBACK_DECLARE_BEGIN(ZFLIB_, CallbackTypeName, ParentType)
util macro to declare a child type of ZFCallback
Definition ZFCallback.h:458
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define ZF_OUT_OPT
dummy macro that shows the param used as optional output
Definition ZFCoreTypeDef_ClassType.h:192
#define zffree(ptr)
same as free defined for future use, do nothing if ptr is NULL
Definition ZFCoreTypeDef_ClassType.h:112
#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
#define zfmalloc(size)
same as malloc defined for future use
Definition ZFCoreTypeDef_ClassType.h:100
_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
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:123
zfbool valid(void) const
return true if callback is valid
Definition ZFCallback.h:238
abstract base class, use ZFOutput or ZFInput
Definition ZFIOCallback_fwd.h:62
general input callback
Definition ZFIOCallback_input.h:37
const ZFInput & input(void *buf, zfindex count, zfindex *result=zft_zfnull) const
see ZFInput
Definition ZFIOCallback_input.h:64
const ZFInput & input(zfstring &buf, zfindex count, zfindex *result=zft_zfnull) const
see ZFInput
Definition ZFIOCallback_input.h:78
zfindex execute(void *buf, zfindex count) const
see ZFInput
Definition ZFIOCallback_input.h:40