ZFFramework
 
Loading...
Searching...
No Matches
ZFFile_util.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFFile_util_h_
7#define _ZFI_ZFFile_util_h_
8
9#include "ZFFile_file.h"
10#include "ZFFile_res.h"
11#include "ZFFile_pathInfo.h"
13
14// ============================================================
32 , ZFMP_IN_OUT(zfstring &, ret)
33 , ZFMP_IN(const zfchar *, src)
34 , ZFMP_IN_OPT(zfindex, srcLen, zfindexMax())
35 )
38 , ZFMP_IN(const zfchar *, src)
39 , ZFMP_IN_OPT(zfindex, srcLen, zfindexMax())
40 ) {
41 zfstring ret;
42 ZFPathFormatT(ret, src, srcLen);
43 return ret;
44}
45
50 , ZFMP_IN_OUT(zfstring &, ret)
51 , ZFMP_IN(const zfchar *, src)
52 , ZFMP_IN_OPT(zfindex, srcLen, zfindexMax())
53 )
56 , ZFMP_IN(const zfchar *, src)
57 , ZFMP_IN_OPT(zfindex, srcLen, zfindexMax())
58 ) {
59 zfstring ret;
60 ZFPathFormatRelativeT(ret, src, srcLen);
61 return ret;
62}
63
70 , ZFMP_OUT(zfstring &, ret)
71 , ZFMP_IN(const zfchar *, src)
72 )
75 , ZFMP_IN(const zfchar *, src)
76 )
83 , ZFMP_OUT(zfstring &, ret)
84 , ZFMP_IN(const zfchar *, src)
85 )
88 , ZFMP_IN(const zfchar *, src)
89 )
97 , ZFMP_OUT(zfstring &, ret)
98 , ZFMP_IN(const zfchar *, src)
99 )
102 , ZFMP_IN(const zfchar *, src)
111 , ZFMP_OUT(zfstring &, ret)
112 , ZFMP_IN(const zfchar *, src)
116 , ZFMP_IN(const zfchar *, src)
125 , ZFMP_OUT(zfstring &, ret)
126 , ZFMP_IN(const zfchar *, src)
130 , ZFMP_IN(const zfchar *, src)
139 , ZFMP_OUT(zfstring &, ret)
140 , ZFMP_IN(const zfchar *, src)
144 , ZFMP_IN(const zfchar *, src)
153 , ZFMP_IN(const zfchar *, src)
157 , ZFMP_IN(const zfchar *, src)
159
160// ============================================================
161zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFFileCloseHolder {
162public:
163 _ZFP_ZFFileCloseHolder(ZF_IN void *token) : token(token) {}
164 ~_ZFP_ZFFileCloseHolder(void) {
165 if(this->token != zfnull) {
166 ZFFileClose(this->token);
167 }
168 }
169private:
170 void *token;
171};
175#define ZFFileCloseHolder(token) _ZFP_ZFFileCloseHolder ZFUniqueName(ZFFileCloseHolder)(token)
176
177// ============================================================
178zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFResCloseHolder {
179public:
180 _ZFP_ZFResCloseHolder(ZF_IN void *token) : token(token) {}
181 ~_ZFP_ZFResCloseHolder(void) {
182 if(this->token != zfnull) {
183 ZFResClose(this->token);
184 }
185 }
186private:
187 void *token;
188};
192#define ZFResCloseHolder(token) _ZFP_ZFResCloseHolder ZFUniqueName(ZFResCloseHolder)(token)
193
194// ============================================================
195zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFPathInfoCloseHolder {
196public:
197 _ZFP_ZFPathInfoCloseHolder(
198 ZF_IN const ZFPathInfo &pathInfo
199 , ZF_IN void *token
200 )
201 : pathInfo(pathInfo)
202 , token(token)
203 {
204 }
205 ~_ZFP_ZFPathInfoCloseHolder(void) {
206 if(this->token != zfnull) {
207 ZFPathInfoClose(this->pathInfo, this->token);
208 }
209 }
210private:
211 const ZFPathInfo &pathInfo;
212 void *token;
213};
217#define ZFPathInfoCloseHolder(pathInfo, token) _ZFP_ZFPathInfoCloseHolder ZFUniqueName(ZFPathInfoCloseHolder)(pathInfo, token)
218
219// ============================================================
224 , ZFMP_IN(const ZFPathInfo &, pathInfo)
225 , ZFMP_IN_OPT(const ZFOutput &, outputCallback, ZFOutputDefault())
226 , ZFMP_IN_OPT(const zfchar *, headToken, zfnull)
227 , ZFMP_IN_OPT(const zfchar *, indentToken, " ")
229
230// ============================================================
249 , ZFMP_IN(const ZFPathInfo &, pathInfo)
250 , ZFMP_IN(const ZFListener &, fileCallback)
251 , ZFMP_IN_OPT(zfbool, isRecursive, zftrue)
255 , ZFMP_IN(const ZFPathInfo &, pathInfo)
256 , ZFMP_IN(const ZFListener &, fileCallback)
257 , ZFMP_IN_OPT(zfbool, isRecursive, zftrue)
261 , ZFMP_IN(const ZFPathInfo &, pathInfo)
262 , ZFMP_IN(const ZFListener &, fileCallback)
263 , ZFMP_IN_OPT(zfbool, isRecursive, zftrue)
265
267#endif // #ifndef _ZFI_ZFFile_util_h_
268
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
_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 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
file utility
zfbool ZFFileClose(void *token)
close and save the file if need, return false if save failed
file utility
zfbool ZFPathInfoClose(const ZFPathInfo &pathInfo, void *token)
see ZFPATHTYPE_FILEIO_REGISTER
file utility
zfbool ZFResClose(void *token)
see ZFResOpen ZFFileClose
zfstring ZFFileNameOf(const zfchar *src)
see ZFFileNameOfT
zfbool ZFPathOfWithoutAllExtT(zfstring &ret, const zfchar *src)
get file path without all ext, e.g. "/path/file" from "/path/file.ext0.ext1", or original string if n...
zfbool ZFPathInfoForEach(const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
util method to loop each child file or dir in specified pathInfo
zfbool ZFPathComponentsOfT(ZFCoreArray< zfstring > &ret, const zfchar *src)
get each file components from path or empty if error, e.g. {"path", "file.ext"}(as array) from "/path...
zfbool ZFPathOfWithoutExtT(zfstring &ret, const zfchar *src)
get file path without ext, e.g. "/path/file.ext0" from "/path/file.ext0.ext1", or original string if ...
zfbool ZFPathParentOfT(zfstring &ret, const zfchar *src)
get parent path
ZFCoreArray< zfstring > ZFPathComponentsOf(const zfchar *src)
see ZFPathComponentsOfT
zfstring ZFPathOfWithoutExt(const zfchar *src)
see ZFPathOfWithoutExtT
zfstring ZFFileExtOf(const zfchar *src)
see ZFFileExtOfT
zfstring ZFPathOfWithoutAllExt(const zfchar *src)
see ZFPathOfWithoutAllExtT
void ZFPathInfoTreePrint(const ZFPathInfo &pathInfo, const ZFOutput &outputCallback=(ZFOutputDefault()), const zfchar *headToken=(zft_zfnull), const zfchar *indentToken=(" "))
list all files, usually for debug use
zfstring ZFPathParentOf(const zfchar *src)
see ZFPathParentOfT
zfbool ZFPathFormatRelativeT(zfstring &ret, const zfchar *src, zfindex srcLen=(((zfindex) -1)))
util method to resolve ".." in path
zfstring ZFPathFormatRelative(const zfchar *src, zfindex srcLen=(((zfindex) -1)))
see ZFPathFormatRelativeT
Definition ZFFile_util.h:58
zfstring ZFPathFormat(const zfchar *src, zfindex srcLen=(((zfindex) -1)))
see ZFPathFormatT
Definition ZFFile_util.h:40
zfbool ZFPathInfoForEachDir(const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
util method to loop each dir, see ZFPathInfoForEach
zfbool ZFPathInfoForEachFile(const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
util method to loop each file, see ZFPathInfoForEach
zfbool ZFFileNameOfT(zfstring &ret, const zfchar *src)
get file name from path or src if error, e.g. "file.ext" from "/path/file.ext"
zfbool ZFFileExtOfT(zfstring &ret, const zfchar *src)
get file extension from path or empty if error, e.g. "ext1" from "/path/file.ext0....
zfbool ZFFileNameOfWithoutExtT(zfstring &ret, const zfchar *src)
get file name without extension from path or src if error, e.g. "file.ext0" from "/path/file....
zfbool ZFPathFormatT(zfstring &ret, const zfchar *src, zfindex srcLen=(((zfindex) -1)))
format path
zfstring ZFFileNameOfWithoutExt(const zfchar *src)
see ZFFileNameOfWithoutExtT
#define ZFMP_IN_OUT(ParamType, paramName)
see ZFMP_IN
Definition ZFMethod.h:117
#define ZFMP_OUT(ParamType, paramName)
see ZFMP_IN
Definition ZFMethod.h:111
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_FUNC_DECLARE_2(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:763
#define ZFMETHOD_FUNC_INLINE_DECLARE_2(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:835
#define ZFMETHOD_FUNC_DECLARE_3(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:910
#define ZFMETHOD_FUNC_DECLARE_4(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2, ZFMP_3)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:1065
#define ZFMETHOD_FUNC_DECLARE_1(ZFLIB_, ReturnType, MethodName, ZFMP_0)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:624
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
const ZFOutput & ZFOutputDefault(void)
default output callback, output source must be zfchar *string
light weight array
Definition ZFCoreArray.h:331
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
general output callback
Definition ZFIOCallback_output.h:37
path related info storage for impl, actual meaning of the info depends on impl
Definition ZFPathInfo.h:35