fbxsdk/core/base/fbxfile.h Source File
 
 
 
fbxsdk/core/base/fbxfile.h
Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2013 Autodesk, Inc.
00004    All rights reserved.
00005  
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009  
00010 ****************************************************************************************/
00011 
00013 #ifndef _FBXSDK_CORE_BASE_FILE_H_
00014 #define _FBXSDK_CORE_BASE_FILE_H_
00015 
00016 #include <fbxsdk/fbxsdk_def.h>
00017 
00018 #include <fbxsdk/core/base/fbxstring.h>
00019 
00020 #include <fbxsdk/fbxsdk_nsbegin.h>
00021 
00022 class FbxStream;
00023 
00027 class FBXSDK_DLL FbxFile
00028 {
00029 public:
00030         enum EMode {eNone, eReadOnly, eReadWrite, eCreateWriteOnly, eCreateReadWrite, eCreateAppend};
00031         enum ESeekPos {eBegin, eCurrent, eEnd};
00032 
00033     FbxFile();
00034     virtual ~FbxFile();
00035 
00042     virtual bool        Open(const char* pFileName_UTF8, const EMode pMode=eCreateReadWrite, const bool pBinary=true);
00043 
00050     virtual bool        Open(FbxStream* pStream, void* pStreamData, const char* pMode);
00051 
00055     virtual bool        Close();
00056 
00061     virtual void                Seek(const FbxInt64 pOffset, const ESeekPos pSeekPos=eBegin);
00062 
00066     virtual FbxInt64    Tell() const;
00067 
00073     virtual     size_t          Read(void* pDstBuf, const size_t pSize);
00074 
00081         virtual char*           ReadString(char* pDstBuf, const size_t pDstSize, bool pStopAtFirstWhiteSpace=false);
00082 
00088     virtual size_t              Write(const void* pSrcBuf, const size_t pSize);
00089 
00095     virtual bool                WriteFormat(const char* pFormat, ...);
00096 
00105     virtual bool                Truncate(const FbxInt64 pSize);
00106 
00110     virtual bool                EndOfFile() const;
00111 
00115         virtual FbxInt64        GetSize();
00116 
00121         virtual void            GetMemoryFileInfo(void** pMemPtr, size_t pSize);
00122 
00126     bool                IsOpen() const;
00127 
00131     bool                IsStream() const;
00132 
00136     const char*                 GetFilePathName() const;
00137 
00141     EMode                               GetFileMode() const;
00142 
00146     int                 GetLastError();
00147 
00150     void                ClearError();
00151 
00152 protected:
00153         FILE*                           mFilePtr;
00154     FbxStream*          mStreamPtr;
00155         bool                mIsOpen;
00156         bool                mIsStream;
00157         EMode                           mMode;
00158         FbxString                       mFileName;
00159 };
00160 
00161 class FBXSDK_DLL FbxFileUtils
00162 {
00163 public:
00168     static bool Delete(const char* pFileName_UTF8);
00169 
00175     static bool Rename(const char* pFileName_UTF8, const char* pNewName_UTF8);
00176 
00182         static bool Copy(const char* pDestination_UTF8, const char* pSource_UTF8);
00183 
00185         static FbxLong Size(const char* pFilePath_UTF8);
00186 
00191         static bool Exist(const char* pFilePath_UTF8);
00192 
00197         static bool IsReadOnly(const char* pFilePath_UTF8);
00198 
00199         // We return a KLong that in fact is a cast of a time_t.
00201         static FbxLong GetLastDate(const char* pPath_UTF8);
00202 
00204         static bool SetLastDate(const char* pPath_UTF8, FbxLong pTime);
00205 
00211         static char* FGets(char* pStr, int pSize, FILE* pStream);
00212 };
00213 
00214 template<class T> inline const T FbxSwab(const T x)
00215 {
00216         switch( sizeof(x) )
00217         {
00218                 case 2:
00219                 {
00220                         FbxUInt8 t[2];
00221                         t[0] = ((FbxUInt8*)&x)[1];
00222                         t[1] = ((FbxUInt8*)&x)[0];
00223                         return *(T*)&t;
00224                 }
00225 
00226                 case 4:
00227                 {
00228                         FbxUInt8 t[4];
00229                         t[0] = ((FbxUInt8*)&x)[3];
00230                         t[1] = ((FbxUInt8*)&x)[2];
00231                         t[2] = ((FbxUInt8*)&x)[1];
00232                         t[3] = ((FbxUInt8*)&x)[0];
00233                         return *(T*)&t;
00234                 }
00235 
00236                 case 8:
00237                 {
00238                         FbxUInt8 t[8];
00239                         t[0] = ((FbxUInt8*)&x)[7];
00240                         t[1] = ((FbxUInt8*)&x)[6];
00241                         t[2] = ((FbxUInt8*)&x)[5];
00242                         t[3] = ((FbxUInt8*)&x)[4];
00243                         t[4] = ((FbxUInt8*)&x)[3];
00244                         t[5] = ((FbxUInt8*)&x)[2];
00245                         t[6] = ((FbxUInt8*)&x)[1];
00246                         t[7] = ((FbxUInt8*)&x)[0];
00247                         return *(T*)&t;
00248                 }
00249 
00250                 default:
00251                         return x;
00252         }
00253 }
00254 
00255 #include <fbxsdk/fbxsdk_nsend.h>
00256 
00257 #endif /* _FBXSDK_CORE_BASE_FILE_H_ */