fbxsdk/core/base/fbxfile.h Source File

fbxfile.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_CORE_BASE_FILE_H_
14 #define _FBXSDK_CORE_BASE_FILE_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
19 
20 #include <fbxsdk/fbxsdk_nsbegin.h>
21 
22 class FbxStream;
23 
28 {
29 public:
30  enum EMode {eNone, eReadOnly, eReadWrite, eCreateWriteOnly, eCreateReadWrite, eCreateAppend};
31  enum ESeekPos {eBegin, eCurrent, eEnd};
32 
33  FbxFile();
34  virtual ~FbxFile();
35 
42  virtual bool Open(const char* pFileName_UTF8, const EMode pMode=eCreateReadWrite, const bool pBinary=true);
43 
50  virtual bool Open(FbxStream* pStream, void* pStreamData, const char* pMode);
51 
55  virtual bool Close();
56 
61  virtual void Seek(const FbxInt64 pOffset, const ESeekPos pSeekPos=eBegin);
62 
66  virtual FbxInt64 Tell() const;
67 
73  virtual size_t Read(void* pDstBuf, const size_t pSize);
74 
81  virtual char* ReadString(char* pDstBuf, const size_t pDstSize, bool pStopAtFirstWhiteSpace=false);
82 
88  virtual size_t Write(const void* pSrcBuf, const size_t pSize);
89 
95  virtual bool WriteFormat(const char* pFormat, ...);
96 
105  virtual bool Truncate(const FbxInt64 pSize);
106 
110  virtual bool EndOfFile() const;
111 
115  virtual FbxInt64 GetSize();
116 
121  virtual void GetMemoryFileInfo(void** pMemPtr, size_t pSize);
122 
126  bool IsOpen() const;
127 
131  bool IsStream() const;
132 
136  const char* GetFilePathName() const;
137 
141  EMode GetFileMode() const;
142 
146  int GetLastError();
147 
150  void ClearError();
151 
152 protected:
153  FILE* mFilePtr;
155  bool mIsOpen;
156  bool mIsStream;
159 };
160 
162 {
163 public:
168  static bool Delete(const char* pFileName_UTF8);
169 
175  static bool Rename(const char* pFileName_UTF8, const char* pNewName_UTF8);
176 
182  static bool Copy(const char* pDestination_UTF8, const char* pSource_UTF8);
183 
185  static FbxInt64 Size(const char* pFilePath_UTF8);
186 
191  static bool Exist(const char* pFilePath_UTF8);
192 
197  static bool IsReadOnly(const char* pFilePath_UTF8);
198 
199  // We return a KLong that in fact is a cast of a time_t.
201  static FbxLong GetLastDate(const char* pPath_UTF8);
202 
204  static bool SetLastDate(const char* pPath_UTF8, FbxLong pTime);
205 
211  static char* FGets(char* pStr, int pSize, FILE* pStream);
212 };
213 
214 template<class T> inline const T FbxSwab(const T x)
215 {
216  switch( sizeof(x) )
217  {
218  case 2:
219  {
220  FbxUInt8 t[2];
221  t[0] = ((FbxUInt8*)&x)[1];
222  t[1] = ((FbxUInt8*)&x)[0];
223  return *(T*)&t;
224  }
225 
226  case 4:
227  {
228  FbxUInt8 t[4];
229  t[0] = ((FbxUInt8*)&x)[3];
230  t[1] = ((FbxUInt8*)&x)[2];
231  t[2] = ((FbxUInt8*)&x)[1];
232  t[3] = ((FbxUInt8*)&x)[0];
233  return *(T*)&t;
234  }
235 
236  case 8:
237  {
238  FbxUInt8 t[8];
239  t[0] = ((FbxUInt8*)&x)[7];
240  t[1] = ((FbxUInt8*)&x)[6];
241  t[2] = ((FbxUInt8*)&x)[5];
242  t[3] = ((FbxUInt8*)&x)[4];
243  t[4] = ((FbxUInt8*)&x)[3];
244  t[5] = ((FbxUInt8*)&x)[2];
245  t[6] = ((FbxUInt8*)&x)[1];
246  t[7] = ((FbxUInt8*)&x)[0];
247  return *(T*)&t;
248  }
249 
250  default:
251  return x;
252  }
253 }
254 
255 #include <fbxsdk/fbxsdk_nsend.h>
256 
257 #endif /* _FBXSDK_CORE_BASE_FILE_H_ */
FBX SDK environment definition.
EMode mMode
Definition: fbxfile.h:157
Abstract class for implementing I/O operations through a stream of data.
Definition: fbxstream.h:26
Utility class to manipulate strings.
Definition: fbxstring.h:66
const T FbxSwab(const T x)
Definition: fbxfile.h:214
ESeekPos
Definition: fbxfile.h:31
unsigned char FbxUInt8
Definition: fbxtypes.h:76
FILE * mFilePtr
Definition: fbxfile.h:153
signed long long FbxInt64
Definition: fbxtypes.h:81
bool mIsOpen
Definition: fbxfile.h:155
FbxStream * mStreamPtr
Definition: fbxfile.h:154
#define FBXSDK_DLL
Definition: fbxarch.h:173
Class for interfacing with files, providing a similar interface for files independant of the OS or fi...
Definition: fbxfile.h:27
FbxString mFileName
Definition: fbxfile.h:158
signed long FbxLong
Definition: fbxtypes.h:89
bool mIsStream
Definition: fbxfile.h:156