2009-01-12 22:06:54 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2010-04-10 15:30:22 +00:00
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
2009-01-12 22:06:54 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
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 Development Team.
|
|
|
|
|
|
|
|
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
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
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.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2009-01-13 18:58:07 +00:00
|
|
|
/** @file IOSystem.h
|
|
|
|
* @brief File system wrapper for C++. Inherit this class to supply
|
2009-01-12 22:06:54 +00:00
|
|
|
* custom file handling logic to the Import library.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AI_IOSYSTEM_H_INC
|
|
|
|
#define AI_IOSYSTEM_H_INC
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
2009-01-12 22:06:54 +00:00
|
|
|
# error This header requires C++ to be used. aiFileIO.h is the \
|
|
|
|
corresponding C interface.
|
2008-05-05 12:36:31 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
#include "aiTypes.h"
|
|
|
|
namespace Assimp {
|
2008-05-05 12:36:31 +00:00
|
|
|
class IOStream;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
2009-08-31 15:51:54 +00:00
|
|
|
/** @brief CPP-API: Interface to the file system.
|
2009-01-23 21:06:43 +00:00
|
|
|
*
|
|
|
|
* Derive an own implementation from this interface to supply custom file handling
|
|
|
|
* to the importer library. If you implement this interface, you also want to
|
|
|
|
* supply a custom implementation for IOStream.
|
|
|
|
*
|
2009-08-31 15:51:54 +00:00
|
|
|
* @see Importer::SetIOHandler() */
|
2009-01-23 21:06:43 +00:00
|
|
|
class ASSIMP_API IOSystem : public Intern::AllocateFromAssimpHeap
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-01-23 21:06:43 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** @brief Default constructor.
|
|
|
|
*
|
|
|
|
* Create an instance of your derived class and assign it to an
|
|
|
|
* #Assimp::Importer instance by calling Importer::SetIOHandler().
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
IOSystem();
|
|
|
|
|
2009-01-23 21:06:43 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** @brief Virtual destructor.
|
|
|
|
*
|
|
|
|
* It is safe to be called from within DLL Assimp, we're constructed
|
|
|
|
* on Assimp's heap.
|
|
|
|
*/
|
2008-05-05 12:36:31 +00:00
|
|
|
virtual ~IOSystem();
|
|
|
|
|
2009-01-23 21:06:43 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** @brief For backward compatibility
|
|
|
|
* @see Exists(const char*)
|
|
|
|
*/
|
|
|
|
AI_FORCE_INLINE bool Exists( const std::string& pFile) const;
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
2009-01-12 22:06:54 +00:00
|
|
|
/** @brief Tests for the existence of a file at the given path.
|
2009-01-23 21:06:43 +00:00
|
|
|
*
|
|
|
|
* @param pFile Path to the file
|
|
|
|
* @return true if there is a file with this path, else false.
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual bool Exists( const char* pFile) const = 0;
|
|
|
|
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2009-01-12 22:06:54 +00:00
|
|
|
/** @brief Returns the system specific directory separator
|
2009-01-23 21:06:43 +00:00
|
|
|
* @return System specific directory separator
|
|
|
|
*/
|
|
|
|
virtual char getOsSeparator() const = 0;
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2009-01-12 22:06:54 +00:00
|
|
|
/** @brief Open a new file with a given path.
|
2009-01-23 21:06:43 +00:00
|
|
|
*
|
|
|
|
* When the access to the file is finished, call Close() to release
|
|
|
|
* all associated resources (or the virtual dtor of the IOStream).
|
|
|
|
*
|
|
|
|
* @param pFile Path to the file
|
|
|
|
* @param pMode Desired file I/O mode. Required are: "wb", "w", "wt",
|
|
|
|
* "rb", "r", "rt".
|
|
|
|
*
|
|
|
|
* @return New IOStream interface allowing the lib to access
|
|
|
|
* the underlying file.
|
|
|
|
* @note When implementing this class to provide custom IO handling,
|
|
|
|
* you probably have to supply an own implementation of IOStream as well.
|
|
|
|
*/
|
|
|
|
virtual IOStream* Open(const char* pFile,
|
|
|
|
const char* pMode = "rb") = 0;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2009-01-23 21:06:43 +00:00
|
|
|
/** @brief For backward compatibility
|
|
|
|
* @see Open(const char*, const char*)
|
|
|
|
*/
|
|
|
|
inline IOStream* Open(const std::string& pFile,
|
|
|
|
const std::string& pMode = std::string("rb"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** @brief Closes the given file and releases all resources
|
|
|
|
* associated with it.
|
2009-01-12 22:06:54 +00:00
|
|
|
* @param pFile The file instance previously created by Open().
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
virtual void Close( IOStream* pFile) = 0;
|
2008-11-26 13:17:39 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2009-01-12 22:06:54 +00:00
|
|
|
/** @brief Compares two paths and check whether the point to
|
|
|
|
* identical files.
|
2008-11-26 13:17:39 +00:00
|
|
|
*
|
2011-03-08 16:09:54 +00:00
|
|
|
* The dummy implementation of this virtual member performs a
|
2009-01-12 22:06:54 +00:00
|
|
|
* case-insensitive comparison of the given strings. The default IO
|
|
|
|
* system implementation uses OS mechanisms to convert relative into
|
|
|
|
* absolute paths, so the result can be trusted.
|
2008-11-26 13:17:39 +00:00
|
|
|
* @param one First file
|
|
|
|
* @param second Second file
|
|
|
|
* @return true if the paths point to the same file. The file needn't
|
|
|
|
* be existing, however.
|
|
|
|
*/
|
2009-01-23 21:06:43 +00:00
|
|
|
virtual bool ComparePaths (const char* one,
|
|
|
|
const char* second) const;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** @brief For backward compatibility
|
|
|
|
* @see ComparePaths(const char*, const char*)
|
|
|
|
*/
|
|
|
|
inline bool ComparePaths (const std::string& one,
|
|
|
|
const std::string& second) const;
|
2008-05-05 12:36:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2009-01-23 21:06:43 +00:00
|
|
|
AI_FORCE_INLINE IOSystem::IOSystem()
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2009-01-23 21:06:43 +00:00
|
|
|
AI_FORCE_INLINE IOSystem::~IOSystem()
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
2009-01-23 21:06:43 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// For compatibility, the interface of some functions taking a std::string was
|
|
|
|
// changed to const char* to avoid crashes between binary incompatible STL
|
|
|
|
// versions. This code her is inlined, so it shouldn't cause any problems.
|
2008-05-05 12:36:31 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-01-23 21:06:43 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile,
|
|
|
|
const std::string& pMode)
|
|
|
|
{
|
|
|
|
// NOTE:
|
|
|
|
// For compatibility, interface was changed to const char* to
|
|
|
|
// avoid crashes between binary incompatible STL versions
|
|
|
|
return Open(pFile.c_str(),pMode.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const
|
|
|
|
{
|
|
|
|
// NOTE:
|
|
|
|
// For compatibility, interface was changed to const char* to
|
|
|
|
// avoid crashes between binary incompatible STL versions
|
|
|
|
return Exists(pFile.c_str());
|
|
|
|
}
|
2008-11-26 13:17:39 +00:00
|
|
|
|
2009-01-23 21:06:43 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
inline bool IOSystem::ComparePaths (const std::string& one,
|
|
|
|
const std::string& second) const
|
|
|
|
{
|
|
|
|
// NOTE:
|
|
|
|
// For compatibility, interface was changed to const char* to
|
|
|
|
// avoid crashes between binary incompatible STL versions
|
|
|
|
return ComparePaths(one.c_str(),second.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
} //!ns Assimp
|
|
|
|
|
|
|
|
#endif //AI_IOSYSTEM_H_INC
|