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
12//! \file fbxstream.h
13#ifndef _FBXSDK_CORE_STREAM_H_
14#define _FBXSDK_CORE_STREAM_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxfile.h>
19
20#include <fbxsdk/fbxsdk_nsbegin.h>
21
22/** Abstract class for implementing I/O operations through a stream of data.
23* For instance, it can be used to read data from a memory source, thus making it possible to import files from memory. However,
24* for the time being, the FbxStream class is only supported with FBX files.
25*/
26class FBXSDK_DLL FbxStream
27{
28public:
29 /** Current stream state. */
30 enum EState
31 {
32 eClosed, //!< The stream is closed.
33 eOpen, //!< The stream is open.
34 eEmpty //!< The stream is empty.
35 };
36
37 /** Query the current state of the stream. */
38 virtual EState GetState() = 0;
39
40 /** Open the stream.
41 * \return True if successful.
42 * \remark Each time the stream is open or closed, the stream position must be reset to zero. */
43 virtual bool Open(void* pStreamData) = 0;
44
45 /** Close the stream.
46 * \return True if successful.
47 * \remark Each time the stream is open or closed, the stream position must be reset to zero. */
48 virtual bool Close() = 0;
49
50 /** Empties the internal data of the stream.
51 * \return True if successful. */
52 virtual bool Flush() = 0;
53
54 /** Writes a memory block.
55 * \param pData Pointer to the memory block to write.
56 * \param pSize Size (in bytes) of the memory block to write.
57 * \return The number of bytes written in the stream. */
58 virtual int Write(const void* /*pData*/, int /*pSize*/) = 0;
59
60 /** Read bytes from the stream and store them in the memory block.
61 * \param pData Pointer to the memory block where the read bytes are stored.
62 * \param pSize Number of bytes read from the stream.
63 * \return The actual number of bytes successfully read from the stream. */
64 virtual int Read(void* /*pData*/, int /*pSize*/) const = 0;
65
66 /** Read a string from the stream.
67 * The default implementation is written in terms of Read() but does not cope with DOS line endings.
68 * Subclasses may need to override this if DOS line endings are to be supported.
69 * \param pBuffer Pointer to the memory block where the read bytes are stored.
70 * \param pMaxSize Maximum number of bytes to be read from the stream.
71 * \param pStopAtFirstWhiteSpace Stop reading when any whitespace is encountered. Otherwise read to end of line (like fgets()).
72 * \return pBuffer, if successful, else NULL.
73 * \remark The default implementation terminates the \e pBuffer with a null character and assumes there is enough room for it.
74 * For example, a call with \e pMaxSize = 1 will fill \e pBuffer with the null character only. */
75 virtual char* ReadString(char* pBuffer, int pMaxSize, bool pStopAtFirstWhiteSpace=false);
76
77 /** If not specified by KFbxImporter::Initialize(), the importer will ask
78 * the stream to select an appropriate reader ID to associate with the stream.
79 * FbxIOPluginRegistry can be used to locate id by extension or description.
80 * Return -1 to allow FBX to select an appropriate default. */
81 virtual int GetReaderID() const = 0;
82
83 /** If not specified by KFbxExporter::Initialize(), the exporter will ask
84 * the stream to select an appropriate writer ID to associate with the stream.
85 * KFbxIOPluginRegistry can be used to locate id by extension or description.
86 * Return -1 to allow FBX to select an appropriate default. */
87 virtual int GetWriterID() const = 0;
88
89 /** Adjust the current stream position.
90 * \param pSeekPos Pre-defined position where offset is added (FbxFile::eBegin, FbxFile::eCurrent:, FbxFile::eEnd)
91 * \param pOffset Number of bytes to offset from pSeekPos. */
92 virtual void Seek(const FbxInt64& pOffset, const FbxFile::ESeekPos& pSeekPos)=0;
93
94 /** Get the current stream position.
95 * \return Current number of bytes from the beginning of the stream. */
96 virtual long GetPosition() const = 0;
97
98 /** Set the current stream position.
99 * \param pPosition Number of bytes from the beginning of the stream to seek to. */
100 virtual void SetPosition(long pPosition)=0;
101
102 /** Return 0 if no errors occurred. Otherwise, return 1 to indicate
103 * an error. This method will be invoked whenever FBX needs to verify
104 * that the last operation succeeded. */
105 virtual int GetError() const = 0;
106
107 /** Clear current error condition by setting the current error value to 0. */
108 virtual void ClearError() = 0;
109
110/*****************************************************************************************************************************
111** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
112*****************************************************************************************************************************/
113#ifndef DOXYGEN_SHOULD_SKIP_THIS
114 FbxStream(){};
115 virtual ~FbxStream(){};
116
117 int Write(const char* pData, int pSize){ return Write((void*)pData, pSize); }
118 int Write(const int* pData, int pSize){ return Write((void*)pData, pSize); }
119 int Read(char* pData, int pSize) const { return Read((void*)pData, pSize); }
120 int Read(int* pData, int pSize) const { return Read((void*)pData, pSize); }
121#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
122};
123
124#include <fbxsdk/fbxsdk_nsend.h>
125
126#endif /* _FBXSDK_CORE_STREAM_H_ */
127