- Main Page
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# fbxfile.h

Go to the documentation of this file.

    00001 /****************************************************************************************
    00002
    00003    Copyright (C) 2012 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
    00024 class FBXSDK_DLL FbxFile
    00025 {
    00026 public:
    00027     enum EMode {eNone, eReadOnly, eReadWrite, eCreateWriteOnly, eCreateReadWrite, eCreateAppend};
    00028     enum ESeekPos {eBegin, eCurrent, eEnd};
    00029
    00030     FbxFile();
    00031     virtual ~FbxFile();
    00032
    00033     virtual bool        Open(const char* pFileName_UTF8, const EMode& pMode=eCreateReadWrite, const bool& pBinary=true);
    00034     virtual bool        Open(FbxStream* pStream, void* pStreamData, const char* pMode);
    00035     virtual bool        Close();
    00036
    00037     virtual void        Seek(const FbxInt64& pOffset, const ESeekPos& pSeekPos=eBegin);
    00038     virtual FbxInt64    Tell() const;
    00039
    00040     virtual size_t      Read(void* pDstBuf, const size_t& pSize);
    00041     virtual char*       ReadString(char* pDstBuf, const size_t& pDstSize, bool pStopAtFirstWhiteSpace=false);
    00042     virtual size_t      Write(const void* pSrcBuf, const size_t& pSize);
    00043     virtual bool        WriteFormat(const char* pFormat, ...);
    00044
    00045     virtual bool        Truncate(const FbxInt64& pSize);
    00046     virtual bool        EndOfFile() const;
    00047     virtual FbxInt64    GetSize();
    00048     virtual void        GetMemoryFileInfo(void** pMemPtr, size_t& pSize);
    00049
    00050     bool                IsOpen() const;
    00051     bool                IsStream() const;
    00052     const char*         GetFilePathName() const;
    00053     EMode               GetFileMode() const;
    00054
    00055     int                 GetLastError();
    00056     void                ClearError();
    00057
    00058 protected:
    00059     FILE*               mFilePtr;
    00060     FbxStream*          mStreamPtr;
    00061     bool                mIsOpen;
    00062     bool                mIsStream;
    00063     EMode               mMode;
    00064     FbxString           mFileName;
    00065 };
    00066
    00067 class FBXSDK_DLL FbxFileUtils
    00068 {
    00069 public:
    00074     static bool Remove(const char* pFileName_UTF8);
    00075
    00081     static bool Rename(const char* pFileName_UTF8, const char* pNewName_UTF8);
    00082
    00088     static bool Copy(const char* pDestination_UTF8, const char* pSource_UTF8);
    00089
    00091     static FbxLong Size(const char* pFilePath_UTF8);
    00092
    00097     static bool Exist(const char* pFilePath_UTF8);
    00098
    00103     static bool IsReadOnly(const char* pFilePath_UTF8);
    00104
    00105     // We return a KLong that in fact is a cast of a time_t.
    00107     static FbxLong GetLastDate(const char* pPath_UTF8);
    00108
    00110     static bool SetLastDate(const char* pPath_UTF8, FbxLong pTime);
    00111
    00117     static char* FGets(char* pStr, int pSize, FILE* pStream);
    00118 };
    00119
    00120 template<class T> inline const T FbxSwab(const T& x)
    00121 {
    00122     switch( sizeof(x) )
    00123     {
    00124         case 2:
    00125         {
    00126             FbxUInt8 t[2];
    00127             t[0] = ((FbxUInt8*)&x)[1];
    00128             t[1] = ((FbxUInt8*)&x)[0];
    00129             return *(T*)&t;
    00130         }
    00131
    00132         case 4:
    00133         {
    00134             FbxUInt8 t[4];
    00135             t[0] = ((FbxUInt8*)&x)[3];
    00136             t[1] = ((FbxUInt8*)&x)[2];
    00137             t[2] = ((FbxUInt8*)&x)[1];
    00138             t[3] = ((FbxUInt8*)&x)[0];
    00139             return *(T*)&t;
    00140         }
    00141
    00142         case 8:
    00143         {
    00144             FbxUInt8 t[8];
    00145             t[0] = ((FbxUInt8*)&x)[7];
    00146             t[1] = ((FbxUInt8*)&x)[6];
    00147             t[2] = ((FbxUInt8*)&x)[5];
    00148             t[3] = ((FbxUInt8*)&x)[4];
    00149             t[4] = ((FbxUInt8*)&x)[3];
    00150             t[5] = ((FbxUInt8*)&x)[2];
    00151             t[6] = ((FbxUInt8*)&x)[1];
    00152             t[7] = ((FbxUInt8*)&x)[0];
    00153             return *(T*)&t;
    00154         }
    00155
    00156         default:
    00157             return x;
    00158     }
    00159 }
    00160
    00161 #include <fbxsdk/fbxsdk_nsend.h>
    00162
    00163 #endif /* _FBXSDK_CORE_BASE_FILE_H_ */