assimp/code/DefaultIOStream.h

143 lines
4.5 KiB
C
Raw Normal View History

/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
2016-01-01 20:07:24 +00:00
Copyright (c) 2006-2016, assimp team
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
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
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
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
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
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
/** @file Default file I/O using fXXX()-family of functions */
#ifndef AI_DEFAULTIOSTREAM_H_INC
#define AI_DEFAULTIOSTREAM_H_INC
#include <stdio.h>
2016-06-06 20:04:29 +00:00
#include <assimp/IOStream.hpp>
#include <assimp/importerdesc.h>
#include "Defines.h"
2015-05-19 03:57:13 +00:00
namespace Assimp {
// ----------------------------------------------------------------------------------
2015-05-19 03:57:13 +00:00
//! @class DefaultIOStream
//! @brief Default IO implementation, use standard IO operations
//! @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.
class DefaultIOStream : public IOStream
{
2015-05-19 03:57:13 +00:00
friend class DefaultIOSystem;
2015-05-19 03:52:10 +00:00
#if __ANDROID__
#if __ANDROID_API__ > 9
#if defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
friend class AndroidJNIIOSystem;
#endif // defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
#endif // __ANDROID_API__ > 9
2015-05-19 03:52:10 +00:00
#endif // __ANDROID__
protected:
2015-05-19 03:57:13 +00:00
DefaultIOStream();
DefaultIOStream(FILE* pFile, const std::string &strFilename);
public:
2015-05-19 03:57:13 +00:00
/** Destructor public to allow simple deletion to close the file. */
~DefaultIOStream ();
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,
size_t pCount);
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,
size_t pCount);
2015-05-19 03:57:13 +00:00
// -------------------------------------------------------------------
/// Seek specific position
aiReturn Seek(size_t pOffset,
aiOrigin pOrigin);
2015-05-19 03:57:13 +00:00
// -------------------------------------------------------------------
/// Get current seek position
size_t Tell() const;
2015-05-19 03:57:13 +00:00
// -------------------------------------------------------------------
/// Get size of file
size_t FileSize() const;
2015-05-19 03:57:13 +00:00
// -------------------------------------------------------------------
/// Flush file contents
void Flush();
private:
2015-05-19 03:57:13 +00:00
// File datastructure, using clib
FILE* mFile;
// Filename
std::string mFilename;
2015-05-19 03:57:13 +00:00
// Cached file size
mutable size_t cachedSize;
};
// ----------------------------------------------------------------------------------
2015-05-19 03:52:10 +00:00
inline DefaultIOStream::DefaultIOStream () :
2015-05-19 03:57:13 +00:00
mFile (NULL),
mFilename (""),
cachedSize (SIZE_MAX)
{
2015-05-19 03:57:13 +00:00
// empty
}
// ----------------------------------------------------------------------------------
2015-05-19 03:52:10 +00:00
inline DefaultIOStream::DefaultIOStream (FILE* pFile,
2015-05-19 03:57:13 +00:00
const std::string &strFilename) :
mFile(pFile),
mFilename(strFilename),
cachedSize (SIZE_MAX)
{
2015-05-19 03:57:13 +00:00
// empty
}
// ----------------------------------------------------------------------------------
} // ns assimp
#endif //!!AI_DEFAULTIOSTREAM_H_INC