Removed direct STL dependency from the Assimp interface, should hopefully avoid problems with binary incompatible STLs. Some API changes, e.g. in the logger.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@321 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
aramis_acg
2009-01-23 21:06:43 +00:00
parent b5ab82922d
commit 03fcec7fe3
26 changed files with 542 additions and 289 deletions

View File

@@ -149,7 +149,7 @@ public:
{}
// -------------------------------------------------------------------
bool Exists( const std::string& pFile) const
bool Exists( const char* pFile) const
{
CIOSystemWrapper* pip = const_cast<CIOSystemWrapper*>(this);
IOStream* p = pip->Open(pFile);
@@ -161,17 +161,16 @@ public:
}
// -------------------------------------------------------------------
std::string getOsSeparator() const
char getOsSeparator() const
{
// FIXME
return "/";
return '/';
}
// -------------------------------------------------------------------
IOStream* Open(const std::string& pFile,
const std::string& pMode = std::string("rb"))
IOStream* Open(const char* pFile,const char* pMode = "rb")
{
aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile.c_str(),pMode.c_str());
aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,pMode);
if (!p)return NULL;
return new CIOStreamWrapper(p);
}
@@ -278,6 +277,7 @@ const char* aiGetErrorString()
{
return gLastErrorString.c_str();
}
// ------------------------------------------------------------------------------------------------
// Returns the error text of the last failed import process.
int aiIsExtensionSupported(const char* szExtension)
@@ -289,18 +289,18 @@ int aiIsExtensionSupported(const char* szExtension)
boost::mutex::scoped_lock lock(gMutex);
#endif
if (!gActiveImports.empty())
{
return (int)((*(gActiveImports.begin())).second->IsExtensionSupported(
std::string ( szExtension )));
if (!gActiveImports.empty()) {
return (int)((*(gActiveImports.begin())).second->IsExtensionSupported( szExtension ));
}
// need to create a temporary Importer instance.
// TODO: Find a better solution ...
Assimp::Importer* pcTemp = new Assimp::Importer();
int i = (int)pcTemp->IsExtensionSupported(std::string ( szExtension ));
int i = (int)pcTemp->IsExtensionSupported(std::string(szExtension));
delete pcTemp;
return i;
}
// ------------------------------------------------------------------------------------------------
// Get a list of all file extensions supported by ASSIMP
void aiGetExtensionList(aiString* szOut)
@@ -312,20 +312,18 @@ void aiGetExtensionList(aiString* szOut)
boost::mutex::scoped_lock lock(gMutex);
#endif
std::string szTemp;
if (!gActiveImports.empty())
{
(*(gActiveImports.begin())).second->GetExtensionList(szTemp);
szOut->Set ( szTemp );
(*(gActiveImports.begin())).second->GetExtensionList(*szOut);
return;
}
// need to create a temporary Importer instance.
// TODO: Find a better solution ...
Assimp::Importer* pcTemp = new Assimp::Importer();
pcTemp->GetExtensionList(szTemp);
szOut->Set ( szTemp );
pcTemp->GetExtensionList(*szOut);
delete pcTemp;
}
// ------------------------------------------------------------------------------------------------
void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
C_STRUCT aiMemoryInfo* in)

View File

@@ -53,7 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor.
DefaultIOSystem::DefaultIOSystem()
@@ -70,9 +69,9 @@ DefaultIOSystem::~DefaultIOSystem()
// ------------------------------------------------------------------------------------------------
// Tests for the existence of a file at the given path.
bool DefaultIOSystem::Exists( const std::string& pFile) const
bool DefaultIOSystem::Exists( const char* pFile) const
{
FILE* file = ::fopen( pFile.c_str(), "rb");
FILE* file = ::fopen( pFile, "rb");
if( !file)
return false;
@@ -82,13 +81,16 @@ bool DefaultIOSystem::Exists( const std::string& pFile) const
// ------------------------------------------------------------------------------------------------
// Open a new file with a given path.
IOStream* DefaultIOSystem::Open( const std::string& strFile, const std::string& strMode)
IOStream* DefaultIOSystem::Open( const char* strFile, const char* strMode)
{
FILE* file = ::fopen( strFile.c_str(), strMode.c_str());
ai_assert(NULL != strFile);
ai_assert(NULL != strMode);
FILE* file = ::fopen( strFile, strMode);
if( NULL == file)
return NULL;
return new DefaultIOStream( file, strFile);
return new DefaultIOStream(file, (std::string) strFile);
}
// ------------------------------------------------------------------------------------------------
@@ -100,20 +102,18 @@ void DefaultIOSystem::Close( IOStream* pFile)
// ------------------------------------------------------------------------------------------------
// Returns the operation specific directory separator
std::string DefaultIOSystem::getOsSeparator() const
char DefaultIOSystem::getOsSeparator() const
{
#ifndef _WIN32
std::string sep = "/";
return '/';
#else
std::string sep = "\\";
return '\\';
#endif
return sep;
}
// ------------------------------------------------------------------------------------------------
// IOSystem default implementation (ComparePaths isn't a pure virtual function)
bool IOSystem::ComparePaths (const std::string& one,
const std::string& second)
bool IOSystem::ComparePaths (const char* one, const char* second) const
{
return !ASSIMP_stricmp(one,second);
}
@@ -123,20 +123,19 @@ bool IOSystem::ComparePaths (const std::string& one,
// ------------------------------------------------------------------------------------------------
// Convert a relative path into an absolute path
inline void MakeAbsolutePath (const std::string& in, char* _out)
inline void MakeAbsolutePath (const char* in, char* _out)
{
#ifdef _WIN32
::_fullpath(_out, in.c_str(),PATHLIMIT);
::_fullpath(_out, in,PATHLIMIT);
#else
// use realpath
realpath(in.c_str(), _out);
realpath(in, _out);
#endif
}
// ------------------------------------------------------------------------------------------------
// DefaultIOSystem's more specialized implementation
bool DefaultIOSystem::ComparePaths (const std::string& one,
const std::string& second)
bool DefaultIOSystem::ComparePaths (const char* one, const char* second) const
{
// chances are quite good both paths are formatted identically,
// so we can hopefully return here already

View File

@@ -44,8 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../include/IOSystem.h"
namespace Assimp
{
namespace Assimp {
// ---------------------------------------------------------------------------
/** Default implementation of IOSystem using the standard C file functions */
@@ -60,15 +59,15 @@ public:
// -------------------------------------------------------------------
/** Tests for the existence of a file at the given path. */
bool Exists( const std::string& pFile) const;
bool Exists( const char* pFile) const;
// -------------------------------------------------------------------
/** Returns the directory separator. */
std::string getOsSeparator() const;
char getOsSeparator() const;
// -------------------------------------------------------------------
/** Open a new file with a given path. */
IOStream* Open( const std::string& pFile, const std::string& pMode = std::string("rb"));
IOStream* Open( const char* pFile, const char* pMode = "rb");
// -------------------------------------------------------------------
/** Closes the given file and releases all resources associated with it. */
@@ -76,7 +75,7 @@ public:
// -------------------------------------------------------------------
/** Compare two paths */
bool ComparePaths (const std::string& one, const std::string& second);
bool ComparePaths (const char* one, const char* second) const;
};
} //!ns Assimp

View File

@@ -39,6 +39,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file DefaultLogger.cpp
* @brief Implementation of DefaultLogger (and Logger)
*/
#include "AssimpPCH.h"
#include "DefaultIOSystem.h"
@@ -54,7 +58,7 @@ NullLogger DefaultLogger::s_pNullLogger;
Logger *DefaultLogger::m_pLogger = &DefaultLogger::s_pNullLogger;
// ----------------------------------------------------------------------------------
//
// Represents a logstream + its error severity
struct LogStreamInfo
{
unsigned int m_uiErrorSeverity;
@@ -78,7 +82,7 @@ struct LogStreamInfo
// ----------------------------------------------------------------------------------
// Construct a default log stream
LogStream* LogStream::createDefaultStream(DefaultLogStreams streams,
const std::string& name /*= "AssimpLog.txt"*/,
const char* name /*= "AssimpLog.txt"*/,
IOSystem* io /*= NULL*/)
{
switch (streams)
@@ -97,7 +101,7 @@ LogStream* LogStream::createDefaultStream(DefaultLogStreams streams,
case DLS_COUT:
return new StdOStreamLogStream(std::cout);
case DLS_FILE:
return (name.size() ? new FileLogStream(name,io) : NULL);
return (name && *name ? new FileLogStream(name,io) : NULL);
default:
// We don't know this default log stream, so raise an assertion
ai_assert(false);
@@ -110,10 +114,10 @@ LogStream* LogStream::createDefaultStream(DefaultLogStreams streams,
// ----------------------------------------------------------------------------------
// Creates the only singleton instance
Logger *DefaultLogger::create(const std::string &name /*= "AssimpLog.txt"*/,
LogSeverity severity /*= NORMAL*/,
unsigned int defStreams /*= DLS_DEBUGGER | DLS_FILE*/,
IOSystem* io /*= NULL*/)
Logger *DefaultLogger::create(const char* name /*= "AssimpLog.txt"*/,
LogSeverity severity /*= NORMAL*/,
unsigned int defStreams /*= DLS_DEBUGGER | DLS_FILE*/,
IOSystem* io /*= NULL*/)
{
if (m_pLogger && !isNullLogger() )
delete m_pLogger;
@@ -134,12 +138,36 @@ Logger *DefaultLogger::create(const std::string &name /*= "AssimpLog.txt"*/,
m_pLogger->attachStream( LogStream::createDefaultStream(DLS_CERR));
// Stream the log to a file
if (defStreams & DLS_FILE && !name.empty())
if (defStreams & DLS_FILE && name && *name)
m_pLogger->attachStream( LogStream::createDefaultStream(DLS_FILE,name,io));
return m_pLogger;
}
// ----------------------------------------------------------------------------------
void Logger::debug(const std::string &message) {
ai_assert(message.length()<=Logger::MAX_LOG_MESSAGE_LENGTH);
return OnDebug(message.c_str());
}
// ----------------------------------------------------------------------------------
void Logger::info(const std::string &message) {
ai_assert(message.length()<=Logger::MAX_LOG_MESSAGE_LENGTH);
return OnInfo(message.c_str());
}
// ----------------------------------------------------------------------------------
void Logger::warn(const std::string &message) {
ai_assert(message.length()<=Logger::MAX_LOG_MESSAGE_LENGTH);
return OnWarn(message.c_str());
}
// ----------------------------------------------------------------------------------
void Logger::error(const std::string &message) {
ai_assert(message.length()<=Logger::MAX_LOG_MESSAGE_LENGTH);
return OnError(message.c_str());
}
// ----------------------------------------------------------------------------------
void DefaultLogger::set( Logger *logger )
{
@@ -174,37 +202,45 @@ void DefaultLogger::kill()
// ----------------------------------------------------------------------------------
// Debug message
void DefaultLogger::debug( const std::string &message )
void DefaultLogger::OnDebug( const char* message )
{
if ( m_Severity == Logger::NORMAL )
return;
const std::string msg( "Debug, T" + getThreadID() + ": " + message );
writeToStreams( msg, Logger::DEBUGGING );
char msg[MAX_LOG_MESSAGE_LENGTH*2];
::sprintf(msg,"Debug, T%i: %s", GetThreadID(), message );
WriteToStreams( msg, Logger::DEBUGGING );
}
// ----------------------------------------------------------------------------------
// Logs an info
void DefaultLogger::info( const std::string &message )
void DefaultLogger::OnInfo( const char* message )
{
const std::string msg( "Info, T" + getThreadID() + ": " + message );
writeToStreams( msg , Logger::INFO );
char msg[MAX_LOG_MESSAGE_LENGTH*2];
::sprintf(msg,"Info, T%i: %s", GetThreadID(), message );
WriteToStreams( msg , Logger::INFO );
}
// ----------------------------------------------------------------------------------
// Logs a warning
void DefaultLogger::warn( const std::string &message )
void DefaultLogger::OnWarn( const char* message )
{
const std::string msg( "Warn, T" + getThreadID() + ": "+ message );
writeToStreams( msg, Logger::WARN );
char msg[MAX_LOG_MESSAGE_LENGTH*2];
::sprintf(msg,"Warn, T%i: %s", GetThreadID(), message );
WriteToStreams( msg, Logger::WARN );
}
// ----------------------------------------------------------------------------------
// Logs an error
void DefaultLogger::error( const std::string &message )
void DefaultLogger::OnError( const char* message )
{
const std::string msg( "Error, T"+ getThreadID() + ": " + message );
writeToStreams( msg, Logger::ERR );
char msg[MAX_LOG_MESSAGE_LENGTH*2];
::sprintf(msg,"Error, T%i: %s", GetThreadID(), message );
WriteToStreams( msg, Logger::ERR );
}
// ----------------------------------------------------------------------------------
@@ -289,57 +325,50 @@ DefaultLogger::~DefaultLogger()
// ----------------------------------------------------------------------------------
// Writes message to stream
void DefaultLogger::writeToStreams(const std::string &message,
void DefaultLogger::WriteToStreams(const char *message,
ErrorSeverity ErrorSev )
{
if ( message.empty() )
return;
std::string s;
ai_assert(NULL != message);
// Check whether this is a repeated message
if (message == lastMsg)
if (! ::strncmp( message,lastMsg, lastLen-1))
{
if (!noRepeatMsg)
{
noRepeatMsg = true;
s = "Skipping one or more lines with the same contents\n";
message = "Skipping one or more lines with the same contents\n";
}
else return;
}
else
{
lastMsg = s = message;
noRepeatMsg = false;
// append a new-line character to the message to be printed
lastLen = ::strlen(message);
::memcpy(lastMsg,message,lastLen+1);
::strcat(lastMsg+lastLen,"\n");
s.append("\n");
message = lastMsg;
noRepeatMsg = false;
++lastLen;
}
for ( ConstStreamIt it = m_StreamArray.begin();
it != m_StreamArray.end();
++it)
{
if ( ErrorSev & (*it)->m_uiErrorSeverity )
(*it)->m_pStream->write( s);
(*it)->m_pStream->write( message);
}
}
// ----------------------------------------------------------------------------------
// Returns thread id, if not supported only a zero will be returned.
std::string DefaultLogger::getThreadID()
unsigned int DefaultLogger::GetThreadID()
{
std::string thread_id( "0" );
// fixme: we can get this value via boost::threads
#ifdef WIN32
HANDLE hThread = ::GetCurrentThread();
if ( hThread )
{
std::stringstream thread_msg;
thread_msg << ::GetCurrentThreadId() /*<< " "*/;
return thread_msg.str();
}
else
return thread_id;
return (unsigned int)::GetCurrentThreadId();
#else
return thread_id;
return 0; // not supported
#endif
}

View File

@@ -6,7 +6,6 @@
namespace Assimp {
// ----------------------------------------------------------------------------------
/** @class FileLogStream
* @brief Logstream to write into a file.
@@ -15,32 +14,29 @@ class FileLogStream :
public LogStream
{
public:
FileLogStream( const std::string &strFileName, IOSystem* io = NULL );
FileLogStream( const char* file, IOSystem* io = NULL );
~FileLogStream();
void write( const std::string &message );
void write( const char* message );
private:
IOStream *m_pStream;
};
// ----------------------------------------------------------------------------------
// Constructor
inline FileLogStream::FileLogStream( const std::string &strFileName, IOSystem* io ) :
inline FileLogStream::FileLogStream( const char* file, IOSystem* io ) :
m_pStream(NULL)
{
if ( strFileName.empty() )
if ( !file || 0 == *file )
return;
const static std::string mode = "wt";
// If no IOSystem is specified: take a default one
if (!io)
{
DefaultIOSystem FileSystem;
m_pStream = FileSystem.Open( strFileName, mode );
m_pStream = FileSystem.Open( file, "wt");
}
else m_pStream = io->Open( strFileName, mode );
else m_pStream = io->Open( file, "wt" );
}
// ----------------------------------------------------------------------------------
@@ -51,21 +47,18 @@ inline FileLogStream::~FileLogStream()
delete m_pStream;
}
// ----------------------------------------------------------------------------------
// Write method
inline void FileLogStream::write( const std::string &message )
inline void FileLogStream::write( const char* message )
{
if (m_pStream != NULL)
{
m_pStream->Write(message.c_str(), sizeof(char), message.size());
m_pStream->Write(message, sizeof(char), ::strlen(message));
m_pStream->Flush();
}
}
// ----------------------------------------------------------------------------------
} // !Namespace Assimp
#endif // !! ASSIMP_FILELOGSTREAM_H_INC

View File

@@ -569,13 +569,45 @@ void Importer::FreeScene( )
mScene = NULL;
}
// ------------------------------------------------------------------------------------------------
// Get the current error string, if any
const std::string& Importer::GetErrorString() const
{
return mErrorString;
}
// ------------------------------------------------------------------------------------------------
// Enable extra-verbose mode
void Importer::SetExtraVerbose(bool bDo)
{
bExtraVerbose = bDo;
}
// ------------------------------------------------------------------------------------------------
// Get the current scene
const aiScene* Importer::GetScene() const
{
return mScene;
}
// ------------------------------------------------------------------------------------------------
// Orphan the current scene
aiScene* Importer::GetOrphanedScene()
{
aiScene* s = mScene;
mScene = NULL;
return s;
}
// ------------------------------------------------------------------------------------------------
// Reads the given file and returns its contents if successful.
const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags)
const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
{
// Validate the flags
ai_assert(ValidateFlags(pFlags));
const std::string pFile(_pFile);
// ======================================================================
// Put a large try block around everything to catch all std::exception's
// that might be thrown by STL containers or by new().
@@ -701,17 +733,18 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
// ------------------------------------------------------------------------------------------------
// Helper function to check whether an extension is supported by ASSIMP
bool Importer::IsExtensionSupported(const std::string& szExtension)
bool Importer::IsExtensionSupported(const char* szExtension)
{
return NULL != FindLoader(szExtension);
}
// ------------------------------------------------------------------------------------------------
BaseImporter* Importer::FindLoader (const std::string& szExtension)
BaseImporter* Importer::FindLoader (const char* _szExtension)
{
const std::string szExtension(_szExtension);
for (std::vector<BaseImporter*>::const_iterator
i = this->mImporter.begin();
i != this->mImporter.end();++i)
i = mImporter.begin();
i != mImporter.end();++i)
{
// pass the file extension to the CanRead(..,NULL)-method
if ((*i)->CanRead(szExtension,NULL))return *i;
@@ -721,19 +754,21 @@ BaseImporter* Importer::FindLoader (const std::string& szExtension)
// ------------------------------------------------------------------------------------------------
// Helper function to build a list of all file extensions supported by ASSIMP
void Importer::GetExtensionList(std::string& szOut)
void Importer::GetExtensionList(aiString& szOut)
{
unsigned int iNum = 0;
std::string tmp; // todo: Rewrite baseImporter::GetExtensionList to use aiString, too
for (std::vector<BaseImporter*>::const_iterator
i = this->mImporter.begin();
i != this->mImporter.end();++i,++iNum)
i = mImporter.begin();
i != mImporter.end();++i,++iNum)
{
// insert a comma as delimiter character
if (0 != iNum)
szOut.append(";");
tmp.append(";");
(*i)->GetExtensionList(szOut);
(*i)->GetExtensionList(tmp);
}
szOut.Set(tmp);
return;
}

View File

@@ -437,11 +437,15 @@ void ObjFileParser::getMaterialLib()
while (!isNewLine(*m_DataIt))
m_DataIt++;
// TODO: fix path construction
// CLEANUP ... who is resposible for *two* identical DefaultIOSystems
// where the IOSystem passed to ReadFile() should be used???
// Check for existence
DefaultIOSystem IOSystem;
std::string strMatName(pStart, &(*m_DataIt));
std::string absName = m_strAbsPath + IOSystem.getOsSeparator() + strMatName;
if ( !IOSystem.Exists(absName) )
if ( !IOSystem.Exists( absName.c_str()) )
{
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
return;
@@ -454,7 +458,7 @@ void ObjFileParser::getMaterialLib()
// Load the material library
DefaultIOSystem FileSystem;
IOStream *pFile = FileSystem.Open(absName);
IOStream *pFile = FileSystem.Open(absName.c_str());
if (0L != pFile)
{
// Import material library data from file

View File

@@ -22,7 +22,7 @@ public:
~StdOStreamLogStream();
/** @brief Writer */
void write(const std::string &messgae);
void write(const char* message);
private:
std::ostream& ostream;
};
@@ -40,9 +40,9 @@ inline StdOStreamLogStream::~StdOStreamLogStream()
// ---------------------------------------------------------------------------
// Write method
inline void StdOStreamLogStream::write(const std::string &message)
inline void StdOStreamLogStream::write(const char* message)
{
ostream << message.c_str();
ostream << message;
ostream.flush();
}

View File

@@ -308,7 +308,7 @@ void ValidateDSProcess::Execute( aiScene* pScene)
void ValidateDSProcess::Validate( const aiLight* pLight)
{
if (pLight->mType == aiLightSource_UNDEFINED)
ReportError("aiLight::mType is aiLightSource_UNDEFINED");
ReportWarning("aiLight::mType is aiLightSource_UNDEFINED");
if (!pLight->mAttenuationConstant &&
!pLight->mAttenuationLinear &&
@@ -334,7 +334,7 @@ void ValidateDSProcess::Validate( const aiCamera* pCamera)
ReportError("aiCamera::mClipPlaneFar must be >= aiCamera::mClipPlaneNear");
if (!pCamera->mHorizontalFOV || pCamera->mHorizontalFOV >= (float)AI_MATH_PI)
ReportError("%f is not a valid value for aiCamera::mHorizontalFOV",pCamera->mHorizontalFOV);
ReportWarning("%f is not a valid value for aiCamera::mHorizontalFOV",pCamera->mHorizontalFOV);
}
// ------------------------------------------------------------------------------------------------

View File

@@ -23,7 +23,7 @@ public:
~Win32DebugLogStream();
/** @brief Writer */
void write(const std::string &messgae);
void write(const char* messgae);
};
// ---------------------------------------------------------------------------
@@ -38,9 +38,9 @@ inline Win32DebugLogStream::~Win32DebugLogStream()
// ---------------------------------------------------------------------------
// Write method
inline void Win32DebugLogStream::write(const std::string &message)
inline void Win32DebugLogStream::write(const char* message)
{
OutputDebugString( message.c_str() );
OutputDebugString( message);
}
// ---------------------------------------------------------------------------