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