Click here to Skip to main content
15,885,988 members
Articles / Desktop Programming / MFC

OAG Library (OpenGL) Part 1 - Setting Up the Library for an MFC Application

Rate me:
Please Sign up or sign in to vote.
4.40/5 (11 votes)
7 Aug 2011CPOL3 min read 56.1K   56  
OAG is a library written in C++. With this library, you can create OpenGL based applications.
/** @file IOSystem.h
 *  @brief File system wrapper for C++. Inherit this class to supply
 *  custom file handling logic to the Import library.
*/

#ifndef AI_IOSYSTEM_H_INC
#define AI_IOSYSTEM_H_INC

#ifdef _MSC_VER

#ifndef _WINDOWS_
#include <windows.h>
#endif

#endif

#include <vector>
using namespace std;
#include <algorithm>
#include "SystemTypes.h"

class IOStream;

// ---------------------------------------------------------------------------
/** @class IOSystem
 *  @brief Interface to the file system.
 *
 *  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.
 *
 *  @see Importer::SetIOHandler()
 */
class IOSystem
{
public:

	// -------------------------------------------------------------------
	/** @brief Default constructor.
	 *
	 *  Create an instance of your derived class and assign it to an 
	 *  #Assimp::Importer instance by calling Importer::SetIOHandler().
	 */
	IOSystem(){};

	// -------------------------------------------------------------------
	/** @brief Virtual destructor.
	 *
	 *  It is safe to be called from within DLL Assimp, we're constructed
	 *  on Assimp's heap.
	 */
	virtual ~IOSystem(){};


public:

	// -------------------------------------------------------------------
	/** @brief For backward compatibility
	 *  @see Exists(const char*)
	 */
	//AI_FORCE_INLINE bool Exists( const std::string& pFile) const;
	virtual bool Exists( const std::string& pFile) const;

	// -------------------------------------------------------------------
	/** @brief Tests for the existence of a file at the given path. 
	 *
	 * @param pFile Path to the file
	 * @return true if there is a file with this path, else false.
	 */

	virtual bool Exists( const char* pFile){ return false; };



	// -------------------------------------------------------------------
	/**	@brief Returns the system specific directory separator
	 *	@return	System specific directory separator
	 */
	virtual char getOsSeparator() const = 0;


	// -------------------------------------------------------------------
	/** @brief Open a new file with a given path.
	 *
	 *  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"){ return NULL;  };

	// -------------------------------------------------------------------
	/** @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.
	 *  @param pFile The file instance previously created by Open().
	 */
	virtual void Close( IOStream* pFile){};

	//---------------------------------------------------------------------
	/*returns the extension of a file
	@param pFile The file to gets the extension
	*/
	std::string GetExtension (const std::string& pFile);

	//---------------------------------------------------------------------
	/*returns the extension of a file
	@param pPath The path to gets the filename
	*/
	std::string GetFileNameFromPath(const std::string& pPath);

};

//// ----------------------------------------------------------------------------
//AI_FORCE_INLINE IOSystem::IOSystem() 
//{
//	// empty
//}
//
//// ----------------------------------------------------------------------------
//AI_FORCE_INLINE IOSystem::~IOSystem() 
//{
//	// empty
//}

// ----------------------------------------------------------------------------
// 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.
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
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());
}

// ----------------------------------------------------------------------------
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());
}

inline std::string IOSystem::GetExtension(const std::string &pFile)
{
	std::string::size_type pos = pFile.find_last_of('.');

	// no file extension at all
	if( pos == std::string::npos)
		return "";

	std::string ret = pFile.substr(pos+1);
	std::transform(ret.begin(),ret.end(),ret.begin(),::tolower); // thanks to Andy Maloney for the hint
	return ret;
}

inline std::string IOSystem::GetFileNameFromPath(const std::string &pFile)
{
	std::string base;
	base = pFile;

	std::string::size_type ss2;
	if (std::string::npos != (ss2 = base.find_last_of("\\/")))
		base.erase(0,ss2+1);

	return base;
}

#endif //AI_IOSYSTEM_H_INC

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Brazil Brazil
I live in Matão, a small city in Brazil. I studied as Programmer in a College for Software Development in Database.
After finishing the College I have been working with java, c# and Computer Graphics with searches for OpenGL.

Comments and Discussions