From be0c3909d1041fa037ef08064ea0d5710b368a18 Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 17 Oct 2009 20:48:50 +0000 Subject: [PATCH] new implementation with Path and Buffer objects git-svn-id: svn://anubis/misc/FileLoader@177 bd8a9e45-a331-0410-811e-c64571078777 --- FileLoader.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/FileLoader.h b/FileLoader.h index df80fbe..f461832 100644 --- a/FileLoader.h +++ b/FileLoader.h @@ -3,14 +3,63 @@ #define FILELOADER_H FILELOADER_H #include +#include class FileLoader { public: - virtual void * loadFile( - const std::string & fullPath, - const std::string & shortPath, - int & size) = 0; + class Path + { + public: + std::string fullPath; + std::string shortPath; + Path(const std::string & full_path, + const std::string & short_path) + : fullPath(full_path), shortPath(short_path) + { + } + }; + + class Buffer + { + public: + char * data; + int size; + Buffer(int sz) + { + size = sz; + data = new char[size]; + _refcnt = new int; + *_refcnt = 1; + } + Buffer(const Buffer & other) + { + data = other.data; + _refcnt = other._refcnt; + (*refcnt)++; + } + Buffer & operator=(Buffer & me, const Buffer & other) + { + me.data = other.data; + me._refcnt = other._refcnt; + (*me_.refcnt)++; + return me; + } + ~Buffer() + { + (*_refcnt)--; + if (*refcnt < 1) + { + delete _refcnt; + delete data; + } + } + protected: + int * _refcnt; + }; + + virtual int getSize(const Path & path) = 0; + virtual Buffer load(const Path & path) = 0; }; #endif