1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2017, assimp team
7
8
9All rights reserved.
10
11Redistribution and use of this software in source and binary forms,
12with or without modification, are permitted provided that the following
13conditions are met:
14
15* Redistributions of source code must retain the above
16 copyright notice, this list of conditions and the
17 following disclaimer.
18
19* Redistributions in binary form must reproduce the above
20 copyright notice, this list of conditions and the
21 following disclaimer in the documentation and/or other
22 materials provided with the distribution.
23
24* Neither the name of the assimp team, nor the names of its
25 contributors may be used to endorse or promote products
26 derived from this software without specific prior
27 written permission of the assimp team.
28
29THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40---------------------------------------------------------------------------
41*/
42/** @file IOStream.hpp
43 * @brief File I/O wrappers for C++.
44 */
45
46#pragma once
47#ifndef AI_IOSTREAM_H_INC
48#define AI_IOSTREAM_H_INC
49
50#include "types.h"
51
52#ifndef __cplusplus
53# error This header requires C++ to be used. aiFileIO.h is the \
54 corresponding C interface.
55#endif
56
57namespace Assimp {
58
59// ----------------------------------------------------------------------------------
60/** @brief CPP-API: Class to handle file I/O for C++
61 *
62 * Derive an own implementation from this interface to provide custom IO handling
63 * to the Importer. If you implement this interface, be sure to also provide an
64 * implementation for IOSystem that creates instances of your custom IO class.
65*/
66class ASSIMP_API IOStream
67#ifndef SWIG
68 : public Intern::AllocateFromAssimpHeap
69#endif
70{
71protected:
72 /** Constructor protected, use IOSystem::Open() to create an instance. */
73 IOStream(void);
74
75public:
76 // -------------------------------------------------------------------
77 /** @brief Destructor. Deleting the object closes the underlying file,
78 * alternatively you may use IOSystem::Close() to release the file.
79 */
80 virtual ~IOStream();
81
82 // -------------------------------------------------------------------
83 /** @brief Read from the file
84 *
85 * See fread() for more details
86 * This fails for write-only files */
87 virtual size_t Read(void* pvBuffer,
88 size_t pSize,
89 size_t pCount) = 0;
90
91 // -------------------------------------------------------------------
92 /** @brief Write to the file
93 *
94 * See fwrite() for more details
95 * This fails for read-only files */
96 virtual size_t Write(const void* pvBuffer,
97 size_t pSize,
98 size_t pCount) = 0;
99
100 // -------------------------------------------------------------------
101 /** @brief Set the read/write cursor of the file
102 *
103 * Note that the offset is _negative_ for aiOrigin_END.
104 * See fseek() for more details */
105 virtual aiReturn Seek(size_t pOffset,
106 aiOrigin pOrigin) = 0;
107
108 // -------------------------------------------------------------------
109 /** @brief Get the current position of the read/write cursor
110 *
111 * See ftell() for more details */
112 virtual size_t Tell() const = 0;
113
114 // -------------------------------------------------------------------
115 /** @brief Returns filesize
116 * Returns the filesize. */
117 virtual size_t FileSize() const = 0;
118
119 // -------------------------------------------------------------------
120 /** @brief Flush the contents of the file buffer (for writers)
121 * See fflush() for more details.
122 */
123 virtual void Flush() = 0;
124}; //! class IOStream
125
126// ----------------------------------------------------------------------------------
127inline IOStream::IOStream()
128{
129 // empty
130}
131
132// ----------------------------------------------------------------------------------
133inline IOStream::~IOStream()
134{
135 // empty
136}
137// ----------------------------------------------------------------------------------
138} //!namespace Assimp
139
140#endif //!!AI_IOSTREAM_H_INC
141