2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Default file I/O using fXXX()-family of functions */
|
2019-10-11 11:27:36 +00:00
|
|
|
#pragma once
|
2015-05-19 03:48:29 +00:00
|
|
|
#ifndef AI_DEFAULTIOSTREAM_H_INC
|
|
|
|
#define AI_DEFAULTIOSTREAM_H_INC
|
|
|
|
|
2019-10-11 11:27:36 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# pragma GCC system_header
|
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <stdio.h>
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/IOStream.hpp>
|
|
|
|
#include <assimp/importerdesc.h>
|
2017-02-28 02:31:56 +00:00
|
|
|
#include <assimp/Defines.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2019-10-11 11:27:36 +00:00
|
|
|
namespace Assimp {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
//! @class DefaultIOStream
|
|
|
|
//! @brief Default IO implementation, use standard IO operations
|
2015-05-19 03:48:29 +00:00
|
|
|
//! @note An instance of this class can exist without a valid file handle
|
|
|
|
//! attached to it. All calls fail, but the instance can nevertheless be
|
|
|
|
//! used with no restrictions.
|
2019-10-11 11:27:36 +00:00
|
|
|
class ASSIMP_API DefaultIOStream : public IOStream {
|
2015-05-19 03:57:13 +00:00
|
|
|
friend class DefaultIOSystem;
|
2015-05-19 03:52:10 +00:00
|
|
|
#if __ANDROID__
|
2016-08-12 15:13:18 +00:00
|
|
|
# if __ANDROID_API__ > 9
|
|
|
|
# if defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
|
2015-05-19 03:48:29 +00:00
|
|
|
friend class AndroidJNIIOSystem;
|
2016-08-12 15:13:18 +00:00
|
|
|
# endif // defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
|
|
|
|
# endif // __ANDROID_API__ > 9
|
2015-05-19 03:52:10 +00:00
|
|
|
#endif // __ANDROID__
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
protected:
|
2018-09-21 14:25:27 +00:00
|
|
|
DefaultIOStream() AI_NO_EXCEPT;
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultIOStream(FILE* pFile, const std::string &strFilename);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Destructor public to allow simple deletion to close the file. */
|
|
|
|
~DefaultIOStream ();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/// Read from stream
|
2015-05-19 03:52:10 +00:00
|
|
|
size_t Read(void* pvBuffer,
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t pSize,
|
2016-10-30 08:06:45 +00:00
|
|
|
size_t pCount);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/// Write to stream
|
2015-05-19 03:52:10 +00:00
|
|
|
size_t Write(const void* pvBuffer,
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t pSize,
|
2016-10-30 08:06:45 +00:00
|
|
|
size_t pCount);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/// Seek specific position
|
|
|
|
aiReturn Seek(size_t pOffset,
|
|
|
|
aiOrigin pOrigin);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/// Get current seek position
|
2016-10-30 08:06:45 +00:00
|
|
|
size_t Tell() const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/// Get size of file
|
2016-10-30 08:06:45 +00:00
|
|
|
size_t FileSize() const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/// Flush file contents
|
2016-10-30 08:06:45 +00:00
|
|
|
void Flush();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
FILE* mFile;
|
|
|
|
std::string mFilename;
|
2016-08-12 16:47:37 +00:00
|
|
|
mutable size_t mCachedSize;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------
|
2019-10-11 11:27:36 +00:00
|
|
|
AI_FORCE_INLINE
|
2018-09-21 14:25:27 +00:00
|
|
|
DefaultIOStream::DefaultIOStream() AI_NO_EXCEPT
|
2018-09-21 14:07:09 +00:00
|
|
|
: mFile(nullptr)
|
2021-04-16 21:43:56 +00:00
|
|
|
, mFilename()
|
2018-09-21 14:07:09 +00:00
|
|
|
, mCachedSize(SIZE_MAX) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// empty
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------
|
2019-10-11 11:27:36 +00:00
|
|
|
AI_FORCE_INLINE
|
2018-09-21 14:07:09 +00:00
|
|
|
DefaultIOStream::DefaultIOStream (FILE* pFile, const std::string &strFilename)
|
|
|
|
: mFile(pFile)
|
|
|
|
, mFilename(strFilename)
|
|
|
|
, mCachedSize(SIZE_MAX) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// empty
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // ns assimp
|
|
|
|
|
|
|
|
#endif //!!AI_DEFAULTIOSTREAM_H_INC
|