Click here to Skip to main content
15,891,431 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.2K   56  
OAG is a library written in C++. With this library, you can create OpenGL based applications.
/** @file FileSystemFilter.h
 *  Implements a filter system to filter calls to Exists() and Open()
 *  in order to improve the sucess rate of file opening ...
 */
#ifndef AI_FILESYSTEMFILTER_H_INC
#define AI_FILESYSTEMFILTER_H_INC

#include "IOSystem.h"
#include "fast_atof.h"
#include "Assert.h"

// ---------------------------------------------------------------------------
/** File system filter  
 */
class FileSystemFilter : public IOSystem
{
public:
	/** Constructor. */
	FileSystemFilter(const std::string& file, IOSystem* old)
		: wrapped  (old)
		, src_file (file)
	{
		ai_assert(NULL != wrapped);

		// Determine base directory
		base = src_file;
		std::string::size_type ss2;
		if (std::string::npos != (ss2 = base.find_last_of("\\/")))	{
			base.erase(ss2,base.length()-ss2);
		}
		else {
			base = "";
		//	return;
		}

		// make sure the directory is terminated properly
		char s;

		if (base.length() == 0) {
			base = ".\\";
		}
		else if ((s = *(base.end()-1)) != '\\' && s != '/')
			base.append("\\");

		//Determine the filename
		filename = GetFileNameFromPath(src_file);

		//DefaultLogger::get()->info("Import root directory is \'" + base + "\'");
	}

	/** Destructor. */
	~FileSystemFilter()
	{
		// haha
	}

	// -------------------------------------------------------------------
	/** Returns the directory separator. */
	char getOsSeparator() const
	{
		return wrapped->getOsSeparator();
	}


	// -------------------------------------------------------------------
	/** Closes the given file and releases all resources associated with it. */
	void Close( IOStream* pFile)
	{
		return wrapped->Close(pFile);
	}

public:
	std::string src_file, base, filename;

private:
	IOSystem* wrapped;

	// -------------------------------------------------------------------
	/** Build a valid path from a given relative or absolute path.
	 */
	void BuildPath (std::string& in) const
	{
		// if we can already access the file, great.
		if (in.length() < 3 || wrapped->Exists(in.c_str())) {
			return;
		}

		// Determine whether this is a relative path. 
		if (in[1] != ':') {
		
			// append base path and try 
			in = base + in;
			if (wrapped->Exists(in.c_str())) {
				return;
			}
		}

		// hopefully the underyling file system has another few tricks to access this file ...
	}
};


#endif //AI_DEFAULTIOSYSTEM_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