x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
NXU_File.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\NxuStream2\source\NXU_File.cpp
旋转
特效
属性
历史版本
#include
#include
#include
#include
#include "NXU_File.h" #include "NXU_string.h" #ifdef _MSC_VER #pragma warning(disable:4996) // Disabling stupid .NET deprecated warning. #endif namespace NXU { #define DEFAULT_BUFFER_SIZE 1000000 #define DEFAULT_GROW_SIZE 2000000 #if defined(LINUX) # define _stricmp(a,b) strcasecmp((a),(b)) #endif class NXU_FILE { public: NXU_FILE(const char *fname,const char *spec,void *mem,int len) { mMyAlloc = false; mRead = true; // default is read access. mFph = 0; mData = (char *) mem; mLen = len; mLoc = 0; if ( spec && _stricmp(spec,"wmem") == 0 ) { mRead = false; if ( mem == 0 || len == 0 ) { mData = new char[DEFAULT_BUFFER_SIZE]; mLen = DEFAULT_BUFFER_SIZE; mMyAlloc = true; } } if ( mData == 0 ) { mFph = fopen(fname,spec); } strncpy(mName,fname,512); } ~NXU_FILE(void) { if ( mMyAlloc ) { delete mData; } if ( mFph ) { fclose(mFph); } } int read(char *data,int size) { int ret = 0; if ( (mLoc+size) <= mLen ) { memcpy(data, &mData[mLoc], size ); mLoc+=size; ret = 1; } return ret; } int write(const char *data,int size) { int ret = 0; if ( (mLoc+size) >= mLen && mMyAlloc ) // grow it { int newLen = mLen+DEFAULT_GROW_SIZE; if ( size > newLen ) newLen = size+DEFAULT_GROW_SIZE; char *data = new char[newLen]; memcpy(data,mData,mLoc); delete mData; mData = data; mLen = newLen; } if ( (mLoc+size) <= mLen ) { memcpy(&mData[mLoc],data,size); mLoc+=size; ret = 1; } return ret; } int read(void *buffer,int size,int count) { int ret = 0; if ( mFph ) { ret = (int) fread(buffer,size,count,mFph); } else { char *data = (char *)buffer; for (int i=0; i
= mLen ) ret = 1; } return ret; } int error(void) { int ret = 0; if ( mFph ) { ret = ferror(mFph); } return ret; } FILE *mFph; char *mData; int mLen; int mLoc; bool mRead; char mName[512]; bool mMyAlloc; }; NXU_FILE * nxu_fopen(const char *fname,const char *spec,void *mem,int len) { NXU_FILE *ret = 0; ret = new NXU_FILE(fname,spec,mem,len); if ( mem == 0 && ret->mData == 0) { if ( ret->mFph == 0 ) { delete ret; ret = 0; } } return ret; } void nxu_fclose(NXU_FILE *file) { delete file; } int nxu_fread(void *buffer,int size,int count,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->read(buffer,size,count); } return ret; } int nxu_fwrite(const void *buffer,int size,int count,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->write(buffer,size,count); } return ret; } int nxu_fprintf(NXU_FILE *fph,const char *fmt,...) { int ret = 0; char buffer[2048]; va_list ap; va_start(ap, fmt); vsprintf(buffer, fmt, ap); va_end(ap); if ( fph ) { ret = fph->writeString(buffer); } return ret; } int nxu_fflush(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->flush(); } return ret; } int nxu_fseek(NXU_FILE *fph,int loc,int mode) { int ret = 0; if ( fph ) { ret = fph->seek(loc,mode); } return ret; } int nxu_ftell(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->tell(); } return ret; } int nxu_fputc(char c,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->myputc(c); } return ret; } int nxu_fputs(const char *str,NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->writeString(str); } return ret; } int nxu_feof(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->eof(); } return ret; } int nxu_ferror(NXU_FILE *fph) { int ret = 0; if ( fph ) { ret = fph->error(); } return ret; } void * nxu_getMemBuffer(NXU_FILE *fph,int &outputLength) { outputLength = 0; void * ret = 0; if ( fph ) { ret = fph->mData; outputLength = fph->mLoc; fph->mMyAlloc = false; } return ret; } }; // end of NXU namespace
NXU_File.cpp
网页地址
文件地址
上一页
6/21
下一页
下载
( 5 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.