miniassimp

view include/miniassimp/DefaultIOStream.h @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2018, assimp team
8 All rights reserved.
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ----------------------------------------------------------------------
41 */
43 /** @file Default file I/O using fXXX()-family of functions */
44 #ifndef AI_DEFAULTIOSTREAM_H_INC
45 #define AI_DEFAULTIOSTREAM_H_INC
47 #include <stdio.h>
48 #include <miniassimp/IOStream.hpp>
49 #include <miniassimp/importerdesc.h>
50 #include <miniassimp/Defines.h>
52 namespace Assimp {
54 // ----------------------------------------------------------------------------------
55 //! @class DefaultIOStream
56 //! @brief Default IO implementation, use standard IO operations
57 //! @note An instance of this class can exist without a valid file handle
58 //! attached to it. All calls fail, but the instance can nevertheless be
59 //! used with no restrictions.
60 class ASSIMP_API DefaultIOStream : public IOStream
61 {
62 friend class DefaultIOSystem;
63 #if __ANDROID__
64 # if __ANDROID_API__ > 9
65 # if defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
66 friend class AndroidJNIIOSystem;
67 # endif // defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
68 # endif // __ANDROID_API__ > 9
69 #endif // __ANDROID__
71 protected:
72 DefaultIOStream() AI_NO_EXCEPT;
73 DefaultIOStream(FILE* pFile, const std::string &strFilename);
75 public:
76 /** Destructor public to allow simple deletion to close the file. */
77 ~DefaultIOStream ();
79 // -------------------------------------------------------------------
80 /// Read from stream
81 size_t Read(void* pvBuffer,
82 size_t pSize,
83 size_t pCount);
86 // -------------------------------------------------------------------
87 /// Write to stream
88 size_t Write(const void* pvBuffer,
89 size_t pSize,
90 size_t pCount);
92 // -------------------------------------------------------------------
93 /// Seek specific position
94 aiReturn Seek(size_t pOffset,
95 aiOrigin pOrigin);
97 // -------------------------------------------------------------------
98 /// Get current seek position
99 size_t Tell() const;
101 // -------------------------------------------------------------------
102 /// Get size of file
103 size_t FileSize() const;
105 // -------------------------------------------------------------------
106 /// Flush file contents
107 void Flush();
109 private:
110 // File data-structure, using clib
111 FILE* mFile;
112 // Filename
113 std::string mFilename;
114 // Cached file size
115 mutable size_t mCachedSize;
116 };
118 // ----------------------------------------------------------------------------------
119 inline
120 DefaultIOStream::DefaultIOStream() AI_NO_EXCEPT
121 : mFile(0)
122 , mFilename("")
123 , mCachedSize(SIZE_MAX) {
124 // empty
125 }
127 // ----------------------------------------------------------------------------------
128 inline
129 DefaultIOStream::DefaultIOStream (FILE* pFile, const std::string &strFilename)
130 : mFile(pFile)
131 , mFilename(strFilename)
132 , mCachedSize(SIZE_MAX) {
133 // empty
134 }
135 // ----------------------------------------------------------------------------------
137 } // ns assimp
139 #endif //!!AI_DEFAULTIOSTREAM_H_INC