Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:30:08

0001 /*
0002 Open Asset Import Library (assimp)
0003 ----------------------------------------------------------------------
0004 
0005 Copyright (c) 2006-2024, assimp team
0006 
0007 All rights reserved.
0008 
0009 Redistribution and use of this software in source and binary forms,
0010 with or without modification, are permitted provided that the
0011 following conditions are met:
0012 
0013 * Redistributions of source code must retain the above
0014   copyright notice, this list of conditions and the
0015   following disclaimer.
0016 
0017 * Redistributions in binary form must reproduce the above
0018   copyright notice, this list of conditions and the
0019   following disclaimer in the documentation and/or other
0020   materials provided with the distribution.
0021 
0022 * Neither the name of the assimp team, nor the names of its
0023   contributors may be used to endorse or promote products
0024   derived from this software without specific prior
0025   written permission of the assimp team.
0026 
0027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0028 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0029 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0030 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0031 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0032 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0033 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0034 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0035 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0036 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038 
0039 ----------------------------------------------------------------------
0040 */
0041 
0042 /**
0043  *  @file
0044  *  @brief Default file I/O using fXXX()-family of functions
0045  */
0046 #pragma once
0047 #ifndef AI_DEFAULTIOSTREAM_H_INC
0048 #define AI_DEFAULTIOSTREAM_H_INC
0049 
0050 #ifdef __GNUC__
0051 #   pragma GCC system_header
0052 #endif
0053 
0054 #include <cstdio>
0055 #include <assimp/IOStream.hpp>
0056 #include <assimp/importerdesc.h>
0057 
0058 namespace Assimp {
0059 
0060 // ----------------------------------------------------------------------------------
0061 //! @class  DefaultIOStream
0062 //! @brief  Default IO implementation, use standard IO operations
0063 //! @note   An instance of this class can exist without a valid file handle
0064 //!         attached to it. All calls fail, but the instance can nevertheless be
0065 //!         used with no restrictions.
0066 class ASSIMP_API DefaultIOStream : public IOStream {
0067     friend class DefaultIOSystem;
0068 #if __ANDROID__
0069 # if __ANDROID_API__ > 9
0070 #  if defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
0071     friend class AndroidJNIIOSystem;
0072 #  endif // defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
0073 # endif // __ANDROID_API__ > 9
0074 #endif // __ANDROID__
0075 
0076 protected:
0077     /// @brief
0078     DefaultIOStream() AI_NO_EXCEPT;
0079 
0080     /// @brief The class constructor with the file name and the stream.
0081     /// @param pFile        The file-streaam
0082     /// @param strFilename  The file name
0083     DefaultIOStream(FILE* pFile, const std::string &strFilename);
0084 
0085 public:
0086     /** Destructor public to allow simple deletion to close the file. */
0087     ~DefaultIOStream () override;
0088 
0089     // -------------------------------------------------------------------
0090     /// Read from stream
0091     size_t Read(void* pvBuffer, size_t pSize, size_t pCount) override;
0092 
0093     // -------------------------------------------------------------------
0094     /// Write to stream
0095     size_t Write(const void* pvBuffer, size_t pSize, size_t pCount) override;
0096 
0097     // -------------------------------------------------------------------
0098     /// Seek specific position
0099     aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override;
0100 
0101     // -------------------------------------------------------------------
0102     /// Get current seek position
0103     size_t Tell() const override;
0104 
0105     // -------------------------------------------------------------------
0106     /// Get size of file
0107     size_t FileSize() const override;
0108 
0109     // -------------------------------------------------------------------
0110     /// Flush file contents
0111     void Flush() override;
0112 
0113 private:
0114     FILE* mFile;
0115     std::string mFilename;
0116     mutable size_t mCachedSize;
0117 };
0118 
0119 // ----------------------------------------------------------------------------------
0120 AI_FORCE_INLINE DefaultIOStream::DefaultIOStream() AI_NO_EXCEPT :
0121         mFile(nullptr),
0122         mFilename(),
0123         mCachedSize(SIZE_MAX) {
0124     // empty
0125 }
0126 
0127 // ----------------------------------------------------------------------------------
0128 AI_FORCE_INLINE DefaultIOStream::DefaultIOStream (FILE* pFile, const std::string &strFilename) :
0129         mFile(pFile),
0130         mFilename(strFilename),
0131         mCachedSize(SIZE_MAX) {
0132     // empty
0133 }
0134 
0135 // ----------------------------------------------------------------------------------
0136 
0137 } // ns assimp
0138 
0139 #endif //!!AI_DEFAULTIOSTREAM_H_INC