120 lines
2.5 KiB
C++
120 lines
2.5 KiB
C++
#ifndef IFOLDER_H__
|
|
#define IFOLDER_H__
|
|
|
|
#include "../IDataStream.h"
|
|
#include "../LString.h"
|
|
#include "IFile.h"
|
|
#include <map>
|
|
#include "../Error.h"
|
|
#include "../log/CLog.h"
|
|
|
|
namespace LifeCore
|
|
{
|
|
class IFolder
|
|
{
|
|
public:
|
|
IFolder()
|
|
:g_parent(0)
|
|
{folderCount=0;
|
|
fileCount=0;
|
|
}
|
|
virtual ~IFolder(void){}
|
|
virtual IFolder* NewFolder(const String& name) = 0;
|
|
virtual IFile* NewFile(const String& name, int size) = 0;
|
|
|
|
int ID;
|
|
String Name;
|
|
int folderCount, fileCount;
|
|
IFolder* getParent(){return g_parent;}
|
|
void setParent(IFolder* parent){g_parent = parent;}
|
|
String getPath()
|
|
{
|
|
if (g_parent)
|
|
return g_parent->getPath() + _text("/") + this->Name;
|
|
else
|
|
return this->Name;
|
|
}
|
|
void AddFolder(IFolder* f)
|
|
{
|
|
if (f)
|
|
{
|
|
//g_folderCollection.insert(FolderPair(f->Name,f));
|
|
g_folderCollection[f->Name] = f;
|
|
f->setParent(this);
|
|
folderCount++;
|
|
}
|
|
}
|
|
void AddFile(IFile* file)
|
|
{
|
|
g_fileCollection[file->FileName] = file;
|
|
fileCount++;
|
|
//file->setParent(this);
|
|
}
|
|
bool FileExists(const String& name)
|
|
{
|
|
FileMapIterator it = g_fileCollection.find(name);
|
|
|
|
return (it != g_fileCollection.end());
|
|
}
|
|
bool FolderExists(const String& name)
|
|
{
|
|
FolderMapIterator it = g_folderCollection.find(name);
|
|
|
|
return (it != g_folderCollection.end());
|
|
}
|
|
int GetFolder(const String& name, LifeCore::IFolder** output)
|
|
{
|
|
LifeCore::IFolder* f = g_folderCollection[name];
|
|
if(f)
|
|
{
|
|
(*output) = f;
|
|
return SC_OK;
|
|
}
|
|
return SC_FAIL;
|
|
}
|
|
LifeCore::IFolder* GetFolder(int index)
|
|
{
|
|
FolderMap::iterator it = g_folderCollection.begin();
|
|
std::advance(it, index);
|
|
return it->second;
|
|
}
|
|
|
|
IFile* GetFile(int index)
|
|
{
|
|
FileMap::iterator it = g_fileCollection.begin();
|
|
std::advance(it, index);
|
|
return it->second;
|
|
}
|
|
|
|
int GetFile(const String& name, IFile** output)
|
|
{
|
|
IFile* file = g_fileCollection[name];
|
|
if(file)
|
|
{
|
|
(*output) = file;
|
|
return SC_OK;
|
|
}
|
|
(*output) = 0;
|
|
/*String msg = STR("Could not find file ") + name;
|
|
//LOG_ERROR(msg,)
|
|
CLog::me()->Write(msg);
|
|
system("pause");
|
|
exit(0);*/
|
|
return SC_FAIL;
|
|
}
|
|
|
|
protected:
|
|
typedef std::map<String, IFile*> FileMap;
|
|
typedef std::pair<String, IFile*> FilePair;
|
|
typedef std::map<String, IFile*>::const_iterator FileMapIterator;
|
|
|
|
typedef std::map<String, IFolder*> FolderMap;
|
|
typedef std::pair<String, IFolder*> FolderPair;
|
|
typedef std::map<String, IFolder*>::const_iterator FolderMapIterator;
|
|
FileMap g_fileCollection;
|
|
FolderMap g_folderCollection;
|
|
IFolder* g_parent;
|
|
};
|
|
}
|
|
|
|
#endif |