- Added missing projects "VFS" & "export" to SVN

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4447 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2011-05-26 11:25:04 +00:00
parent 6e2bdd557c
commit be95a2a7b1
203 changed files with 44525 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
/*
* bfVFS : vfs/Aspects/vfs_logging.h
* - Logging interface and macros that will be used to report errors/warnings to the using program
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef VFS_LOGGING_H
#define VFS_LOGGING_H
#include <vfs/vfs_config.h>
namespace vfs
{
class String;
namespace Aspects
{
enum LogType { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG };
class ILogger
{
public:
virtual void Msg(const wchar_t* msg) = 0;
virtual void Msg(const char* msg) = 0;
};
VFS_API void setLogger(LogType type, ILogger* logger);
VFS_API ILogger* getLogger(LogType type);
VFS_API void setLogger( ILogger* info_logger, ILogger* warning_logger, ILogger* error_logger, ILogger* debug_logger );
void Debug(vfs::String const& msg);
void Debug(const wchar_t* msg);
void Debug(const char* msg);
void Info(vfs::String const& msg);
void Info(const wchar_t* msg);
void Info(const char* msg);
void Warning(vfs::String const& msg);
void Warning(const wchar_t* msg);
void Warning(const char* msg);
void Error(vfs::String const& msg);
void Error(const wchar_t* msg);
void Error(const char* msg);
};
};
#if !defined VFS_DISABLE_LOGGING
# if !defined VFS_LOG_DEBUG
# define VFS_LOG_DEBUG(msg) (vfs::Aspects::Debug(msg))
# endif
# if !defined VFS_LOG_INFO
# define VFS_LOG_INFO(msg) (vfs::Aspects::Info(msg))
# endif
# if !defined VFS_LOG_WARNING
# define VFS_LOG_WARNING(msg) (vfs::Aspects::Warning(msg))
# endif
# if !defined VFS_LOG_ERROR
# define VFS_LOG_ERROR(msg) (vfs::Aspects::Error(msg))
# endif
#else
# if !defined VFS_LOG_DEBUG
# define VFS_LOG_DEBUG(msg)
# endif
# if !defined VFS_LOG_INFO
# define VFS_LOG_INFO(msg)
# endif
# if !defined VFS_LOG_WARNING
# define VFS_LOG_WARNING(msg)
# endif
# if !defined VFS_LOG_ERROR
# define VFS_LOG_ERROR(msg)
# endif
#endif // VFS_DISABLE_LOGGING
#endif // VFS_LOGGING_H
@@ -0,0 +1,40 @@
/*
* bfVFS : vfs/Aspects/vfs_settings.h
* - library runtime settings,
* - e.g., to use Unicode strings or regular for file names
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_SETTIGNS_H_
#define _VFS_SETTIGNS_H_
#include <vfs/vfs_config.h>
namespace vfs
{
class VFS_API Settings
{
public:
static void setUseUnicode(bool useUnicode);
static bool getUseUnicode();
};
}
#endif // _VFS_SETTIGNS_H_
@@ -0,0 +1,87 @@
/*
* bfVFS : vfs/Aspects/vfs_synchronization.h
* - Interface for Mutexes and Locks, implementation can or has to be provided by the using program
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef VFS_SYNCHRONIZATION_H
#define VFS_SYNCHRONIZATION_H
#include <vfs/vfs_config.h>
namespace vfs
{
namespace Aspects
{
class IMutex
{
public:
virtual void lock() {};
virtual void unlock() {};
};
class IMutexFactory
{
public:
virtual IMutex* createMutex() = 0;
};
VFS_API void setMutexFactory(IMutexFactory* mutex_factory);
VFS_API IMutexFactory* getMutexFactory();
class Mutex
{
public:
Mutex();
~Mutex();
void lock();
void unlock();
private:
int _locked;
IMutex* _mutex;
};
class ScopedLock
{
public:
ScopedLock(Mutex& mutex) : _mutex(mutex) {
this->_mutex.lock();
}
~ScopedLock(){
this->_mutex.unlock();
}
private:
Mutex& _mutex;
};
}
}
#ifdef VFS_SYNCHRONIZE
# if !defined VFS_LOCK
# define VFS_LOCK(mutex) vfs::Aspects::ScopedLock _scoped_lock(mutex)
# endif
#else
# if !defined VFS_LOCK
# define VFS_LOCK(mutex)
# endif
#endif
#endif // VFS_SYNCHRONIZATION_H
@@ -0,0 +1,73 @@
/*
* bfVFS : vfs/Core/File/vfs_buffer_file.h
* - Buffer in RAM, implements File interface to unify usage of file and memory
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_MEMORY_FILE_H_
#define _VFS_MEMORY_FILE_H_
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <sstream>
namespace vfs
{
class VFS_API CBufferFile : public vfs::TFileTemplate<vfs::IReadable,vfs::IWritable>
{
typedef vfs::TFileTemplate<vfs::IReadable,vfs::IWritable> tBaseClass;
public :
CBufferFile();
CBufferFile(vfs::Path const& filename);
virtual ~CBufferFile();
virtual vfs::FileAttributes getAttributes();
virtual void close();
virtual vfs::size_t getSize();
virtual bool isOpenRead();
virtual bool openRead();
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead);
virtual vfs::size_t getReadPosition();
virtual void setReadPosition(vfs::size_t positionInBytes);
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
virtual bool isOpenWrite();
virtual bool openWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite);
virtual vfs::size_t getWritePosition();
virtual void setWritePosition(vfs::size_t positionInBytes);
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
virtual bool deleteFile();
// convenience method
void copyToBuffer(vfs::tReadableFile& rFile);
protected:
std::stringstream m_buffer;
bool m_isOpen_read, m_isOpen_write;
};
} // end namespace
#endif // _VFS_MEMORY_FILE_H_
@@ -0,0 +1,76 @@
/*
* bfVFS : vfs/Core/File/vfs_dir_file.h
* - read/read-write files for usage in vfs locations
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_DIR_FILE_H_
#define _VFS_DIR_FILE_H_
#include <vfs/Core/File/vfs_file.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/Interface/vfs_location_interface.h>
#include <vfs/Core/Interface/vfs_directory_interface.h>
namespace vfs
{
class VFS_API CReadOnlyDirFile : public vfs::CReadOnlyFile
{
protected:
typedef vfs::TDirectory<vfs::CReadOnlyDirFile::write_type> tLocation;
public:
CReadOnlyDirFile(vfs::Path const& filename, tLocation *directory);
virtual ~CReadOnlyDirFile();
virtual vfs::FileAttributes getAttributes();
virtual vfs::Path getPath();
virtual bool openRead();
virtual bool _getRealPath(vfs::Path& path);
private:
tLocation* _location;
};
class VFS_API CDirFile : public vfs::CFile
{
typedef vfs::TDirectory<vfs::CFile::write_type> tLocation;
public:
CDirFile(vfs::Path const& filename, tLocation *directory);
virtual ~CDirFile();
virtual vfs::FileAttributes getAttributes();
virtual vfs::Path getPath();
virtual bool deleteFile();
virtual bool openRead();
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false);
virtual bool _getRealPath(vfs::Path& path);
private:
tLocation* _location;
};
} // end namespace
#endif // _VFS_DIR_FILE_H_
+113
View File
@@ -0,0 +1,113 @@
/*
* bfVFS : vfs/Core/File/vfs_file.h
* - File with read/read-write access
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_FILE_H_
#define _VFS_FILE_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Aspects/vfs_synchronization.h>
#ifdef WIN32
# include "windows.h"
#else
# include <fstream>
#endif
typedef std::basic_fstream<wchar_t> wfstream;
namespace vfs
{
/******************************************************************/
/******************************************************************/
template<typename WriteType=vfs::IWriteType>
class VFS_API TFile : public vfs::TFileTemplate<vfs::IReadable,WriteType>
{
typedef vfs::TFileTemplate<vfs::IReadable,WriteType> tBaseClass;
public :
TFile(vfs::Path const& filename);
virtual ~TFile();
virtual vfs::FileAttributes getAttributes();
virtual void close();
virtual vfs::size_t getSize();
virtual bool isOpenRead();
virtual bool openRead();
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead);
virtual vfs::size_t getReadPosition();
virtual void setReadPosition(vfs::size_t positionInBytes);
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
protected:
bool _internalOpenRead(vfs::Path const& path);
protected:
bool m_isOpen_read;
#ifdef WIN32
HANDLE m_file;
#else
FILE* m_file;
#endif
//vfs::Aspects::Mutex m_mutex;
};
/******************************************************************/
/******************************************************************/
// implements the IWritable interface for TFile
class VFS_API CFile : public vfs::TFile<vfs::IWritable>
{
typedef vfs::TFile<vfs::IWritable> tBaseClass;
public :
CFile(vfs::Path const& filename);
virtual ~CFile();
virtual void close();
virtual bool isOpenWrite();
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false);
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite);
virtual vfs::size_t getWritePosition();
virtual void setWritePosition(vfs::size_t positionInBytes);
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
virtual bool deleteFile();
protected:
bool _internalOpenWrite(vfs::Path const& path, bool createWhenNotExist = false, bool truncate = false);
protected:
bool m_isOpen_write;
};
/******************************************************************/
/******************************************************************/
typedef vfs::TFile<vfs::IWriteType> CReadOnlyFile; // needs explicit template instantiation
} // end namespace
#endif // _VFS_FILE_H_
@@ -0,0 +1,78 @@
/*
* bfVFS : vfs/Core/File/vfs_lib_file.h
* - read/read-write files for usage in vfs locations (libraries)
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_LIB_FILE_H_
#define _VFS_LIB_FILE_H_
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/Interface/vfs_location_interface.h>
#include <vfs/Core/Interface/vfs_library_interface.h>
#include <vfs/Tools/vfs_allocator.h>
namespace vfs
{
class ILibrary;
class CLibFile : public vfs::TFileTemplate<vfs::IReadable,vfs::IWriteType>
{
typedef vfs::TFileTemplate<vfs::IReadable,vfs::IWriteType> tBaseClass;
typedef vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType> tLocation;
public:
CLibFile();
static CLibFile* create(vfs::Path const& filename,
tLocation *location,
vfs::ILibrary *library,
vfs::ObjBlockAllocator<CLibFile>* allocator = NULL);
// don't delete objects that YOU have not created with 'new'
// dtor has to remain public to be usable at all
virtual ~CLibFile();
virtual vfs::FileAttributes getAttributes();
virtual void close();
virtual vfs::Path getPath();
virtual bool isOpenRead();
virtual bool openRead();
virtual vfs::size_t read(vfs::Byte* pData, vfs::size_t bytesToRead);
virtual vfs::size_t getReadPosition();
virtual void setReadPosition(vfs::size_t positionInBytes);
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
virtual vfs::size_t getSize();
protected:
bool m_isOpen_read;
ILibrary* m_library;
tLocation* m_location;
private:
static vfs::ObjBlockAllocator<CLibFile>* _lfile_pool;
};
} // end namespace
#endif // _VFS_LIB_FILE_H_
@@ -0,0 +1,63 @@
/*
* bfVFS : vfs/Core/Interface/vfs_directory_interface.h
* - partially implements Location interface for file system directories
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_DIRECTORY_INTERFACE_H_
#define _VFS_DIRECTORY_INTERFACE_H_
#include <vfs/Core/Interface/vfs_location_interface.h>
namespace vfs
{
template<class WriteType>
class TDirectory : public vfs::TLocationTemplate<vfs::IReadable, WriteType>
{
public:
typedef typename vfs::TLocationTemplate<vfs::IReadable, WriteType> tBaseClass;
typedef typename tBaseClass::tFileType tFileType;
typedef typename tBaseClass::tWriteType tWriteType;
TDirectory(vfs::Path const& mountPoint, vfs::Path const& realPath)
: tBaseClass(mountPoint), m_realPath(realPath)
{};
virtual ~TDirectory()
{};
vfs::Path const& getRealPath()
{
return m_realPath;
}
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false) = 0;
virtual bool addFile(typename tBaseClass::tFileType* pFile, bool bDeleteOldFile=false) = 0;
virtual bool createSubDirectory(vfs::Path const& sSubDirPath) = 0;
virtual bool deleteDirectory(vfs::Path const& sDirPath) = 0;
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName) = 0;
protected:
const vfs::Path m_realPath;
private:
void operator=(TDirectory<WriteType> const& t);
};
}
#endif // _VFS_DIRECTORY_INTERFACE_H_
@@ -0,0 +1,257 @@
/*
* bfVFS : vfs/Core/Interface/vfs_file_interface.h
* - generic interface for read/write files
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_FILE_INTERFACE_H_
#define _VFS_FILE_INTERFACE_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_path.h>
#include <typeinfo>
namespace vfs
{
/**
* FileAttributes
*/
class VFS_API FileAttributes
{
public:
enum Attributes {
ATTRIB_INVALID = 0,
ATTRIB_ARCHIVE = 1,
ATTRIB_DIRECTORY = 2,
ATTRIB_HIDDEN = 4,
ATTRIB_NORMAL = 8,
ATTRIB_READONLY = 16,
ATTRIB_SYSTEM = 32,
ATTRIB_TEMPORARY = 64,
ATTRIB_COMPRESSED = 128,
ATTRIB_OFFLINE = 256,
};
enum LocationType {
LT_NONE = 0,
LT_LIBRARY = 1,
LT_DIRECTORY = 2,
LT_READONLY_DIRECTORY = 4,
};
public:
FileAttributes();
FileAttributes(vfs::UInt32 attribs, LocationType location);
vfs::UInt32 getAttrib() const;
vfs::UInt32 getLocation() const;
bool isAttribSet(vfs::UInt32 attribs) const;
bool isAttribNotSet(vfs::UInt32 attribs) const;
bool isLocation(vfs::UInt32 location) const;
private:
void operator=(vfs::FileAttributes const& attr);
const vfs::UInt32 _attribs;
const vfs::UInt32 _location;
};
/**
* IBaseFile
*/
class VFS_API IBaseFile
{
public:
enum ESeekDir
{
SD_BEGIN,
SD_CURRENT,
SD_END,
};
public:
IBaseFile(vfs::Path const& filename);
virtual ~IBaseFile();
virtual vfs::FileAttributes getAttributes() = 0;
vfs::Path const& getName();
virtual vfs::Path getPath();
virtual bool implementsWritable() = 0;
virtual bool implementsReadable() = 0;
virtual void close() = 0;
virtual vfs::size_t getSize() = 0;
virtual bool _getRealPath(vfs::Path& path);
protected:
vfs::Path m_filename;
};
/**
* IReadType , IReadable
*/
class IReadType{};
class IReadable : public vfs::IReadType
{
public:
virtual bool isOpenRead() = 0;
virtual bool openRead() = 0;
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead) = 0;
virtual vfs::size_t getReadPosition() = 0;
virtual void setReadPosition(vfs::size_t positionInBytes) = 0;
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir) = 0;
};
//class NonReadable : public IReadType{};
/**
* IWriteType , IWritable
*/
class IWriteType{};
class IWritable : public vfs::IWriteType
{
public:
virtual bool isOpenWrite() = 0;
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false) = 0;
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite) = 0;
virtual vfs::size_t getWritePosition() = 0;
virtual void setWritePosition(vfs::size_t positionInBytes) = 0;
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir) = 0;
virtual bool deleteFile() = 0;
};
//class NonWritable: public IWriteType{};
/******************************************************************/
/******************************************************************/
/**
* IFileTemplate
*/
template<typename ReadType=vfs::IReadType, typename WriteType=vfs::IWriteType>
class VFS_API TFileTemplate : public vfs::IBaseFile, public ReadType, public WriteType
{
public:
typedef ReadType read_type;
typedef WriteType write_type;
typedef vfs::TFileTemplate<read_type,vfs::IWritable> write_file_type;
typedef vfs::TFileTemplate<vfs::IReadable,write_type> read_file_type;
public:
TFileTemplate(vfs::Path const& fileName)
: vfs::IBaseFile(fileName), ReadType(), WriteType()
{};
virtual ~TFileTemplate()
{};
virtual bool implementsWritable()
{
return typeid(write_type) == typeid(vfs::IWritable);
}
virtual bool implementsReadable()
{
return typeid(read_type) == typeid(vfs::IReadable);
}
};
/**
* TReadableFile
*/
template<class WriteType=vfs::IWriteType>
class TReadableFile : public vfs::TFileTemplate<vfs::IReadable,WriteType>
{
typedef vfs::TFileTemplate<vfs::IReadable,WriteType> tBaseClass;
public:
typedef vfs::TReadableFile<WriteType> read_file_type;
/////////////////////////////////////////
TReadableFile(vfs::Path const& sFilename)
: tBaseClass(sFilename)
{};
virtual ~TReadableFile(){};
/////////////////////////////////////////
read_file_type* operator=(vfs::IBaseFile const& t)
{
return read_file_type::cast(t);
}
/////////////////////////////////////////
static read_file_type* cast(vfs::IBaseFile* bf)
{
if(bf && bf->implementsReadable())
{
return static_cast<read_file_type*>(bf);
}
return NULL;
}
protected:
TReadableFile();
};
/**
* TWritableFile
*/
template<class ReadType=vfs::IReadType>
class TWritableFile : public vfs::TFileTemplate<ReadType,vfs::IWritable>
{
typedef vfs::TFileTemplate<ReadType,vfs::IWritable> tBaseClass;
public:
typedef vfs::TWritableFile<ReadType> write_file_type;
/////////////////////////////////////////
TWritableFile(vfs::Path const& sFilename)
: tBaseClass(sFilename)
{};
virtual ~TWritableFile(){};
/////////////////////////////////////////
write_file_type& operator=(vfs::IBaseFile const& t)
{
return *write_file_type::cast(t);
}
/////////////////////////////////////////
static write_file_type* cast(IBaseFile* bf)
{
if(bf && bf->implementsWritable())
{
return static_cast<write_file_type*>(bf);
}
return NULL;
}
protected:
TWritableFile();
};
/******************************************************************/
/******************************************************************/
/**
* typedef's
*/
typedef vfs::TReadableFile<vfs::IWriteType> tReadableFile;
typedef vfs::TWritableFile<vfs::IReadable> tWritableFile;
} // end namespace
#endif // _VFS_FILE_INTERFACE_H_
@@ -0,0 +1,88 @@
/*
* bfVFS : vfs/Core/Interface/vfs_iterator_interface.h
* - generic interface to iterate over files in locations
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_ITERATOR_INTERFACE_H_
#define _VFS_ITERATOR_INTERFACE_H_
namespace vfs
{
template<typename T>
class VFS_API TIterator
{
public:
class IImplementation
{
friend class TIterator<T>;
public:
virtual ~IImplementation() {};
virtual T* value() = 0;
virtual void next() = 0;
protected:
virtual IImplementation* clone() = 0;
};
public:
TIterator() : _obj(NULL), _iter_impl(NULL) {};
TIterator(IImplementation* impl) : _obj(NULL), _iter_impl(impl)
{
if(_iter_impl)
{
_obj = _iter_impl->value();
}
}
~TIterator()
{
if(_iter_impl) delete _iter_impl;
};
TIterator& operator=(TIterator const& t)
{
_obj = t._obj;
_iter_impl = NULL;
if(t._iter_impl)
{
_iter_impl = t._iter_impl->clone();
}
return *this;
}
//////////////////////////////
T* value() { return _obj; };
bool end() { return _obj == NULL; };
void next()
{
if(_iter_impl)
{
_iter_impl->next();
_obj = _iter_impl->value();
if(!_obj)
{
delete _iter_impl;
_iter_impl = NULL;
}
}
}
private:
T* _obj;
IImplementation* _iter_impl;
};
}
#endif // _VFS_ITERATOR_INTERFACE_H_
@@ -0,0 +1,59 @@
/*
* bfVFS : vfs/Core/Interface/vfs_library_interface.h
* - partially implements Location interface for archive files
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_LIBRARY_INTERFACE_H_
#define _VFS_LIBRARY_INTERFACE_H_
#include <vfs/Core/Interface/vfs_location_interface.h>
namespace vfs
{
class VFS_API ILibrary : public vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType>
{
typedef vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType> tBaseClass;
public:
ILibrary(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile = false);
virtual ~ILibrary();
virtual bool init() = 0;
virtual void closeLibrary() = 0;
virtual void close(tFileType *fileHandle) = 0;
virtual bool openRead(tFileType *fileHandle) = 0;
virtual vfs::size_t read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead) = 0;
virtual vfs::size_t getReadPosition(tFileType *fileHandle) = 0;
virtual void setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes) = 0;
virtual void setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir) = 0;
virtual vfs::size_t getSize(tFileType *pFileHandle) = 0;
vfs::Path const& getName();
protected:
bool m_ownLibFile;
vfs::tReadableFile* m_libraryFile;
};
}
#endif // _VFS_LIBRARY_INTERFACE_H_
@@ -0,0 +1,160 @@
/*
* bfVFS : vfs/Core/Interface/vfs_location_interface.h
* - generic Location interface that allows retrieval of a file from a real location
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_LOCATION_INTERFACE_H_
#define _VFS_LOCATION_INTERFACE_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_debug.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/Interface/vfs_iterator_interface.h>
#include <map>
#include <list>
#include <typeinfo>
namespace vfs
{
class VFS_API IBaseLocation
{
public:
typedef TIterator<vfs::IBaseFile> Iterator;
virtual ~IBaseLocation()
{};
virtual bool implementsWritable() = 0;
virtual bool implementsReadable() = 0;
virtual vfs::Path const& getPath() = 0;
virtual bool fileExists(vfs::Path const& sFileName) = 0;
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0;
virtual Iterator begin() = 0;
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs) = 0;
};
/**
* TLocation
*/
template<typename ReadType, typename WriteType>
class VFS_API TLocationTemplate : public IBaseLocation
{
public:
typedef vfs::TLocationTemplate<ReadType,WriteType> tLocationType;
typedef vfs::TFileTemplate<ReadType,WriteType> tFileType;
typedef ReadType tReadType;
typedef WriteType tWriteType;
typedef std::list<std::pair<tFileType*,vfs::Path> > tListFilesWithPath;
public:
TLocationTemplate(vfs::Path const& mountPoint)
: m_mountPoint(mountPoint)
{};
virtual ~TLocationTemplate()
{};
// has to be virtual , or the types of the caller (not the real object) will be tested
virtual bool implementsWritable()
{
return typeid(tWriteType) == typeid(vfs::IWritable);
}
virtual bool implementsReadable()
{
return typeid(tReadType) == typeid(vfs::IReadable);
}
vfs::Path const& getMountPoint()
{
return m_mountPoint;
}
/**
* TLocationTemplate interface
*/
virtual vfs::Path const& getPath()
{
return m_mountPoint;
}
virtual bool fileExists(vfs::Path const& sFileName) = 0;
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0;
virtual tFileType* getFileTyped(vfs::Path const& rFileName) = 0;
protected:
vfs::Path m_mountPoint;
};
/**************************************************************************************/
/**************************************************************************************/
template<typename WriteType=vfs::IWriteType>
class TReadLocation : public TLocationTemplate<IReadable,WriteType>
{
public:
typedef TReadLocation<WriteType> tLocationType;
static tLocationType* cast(vfs::IBaseLocation* bl)
{
if(bl && bl->implementsReadable())
{
return static_cast<tLocationType*>(bl);
}
return NULL;
}
public:
TReadLocation(vfs::Path const& sLocalPath)
: vfs::TLocationTemplate<IReadable,WriteType>(sLocalPath)
{};
virtual ~TReadLocation(){};
};
template<typename ReadType=vfs::IReadType>
class TWriteLocation : public vfs::TLocationTemplate<ReadType,vfs::IWritable>
{
public:
typedef TWriteLocation<ReadType> tLocationType;
static tLocationType* cast(vfs::IBaseLocation* bl)
{
if(bl && bl->implementsWritable())
{
return static_cast<tLocationType*>(bl);
}
return NULL;
}
public:
TWriteLocation(vfs::Path const& sLocalPath)
: vfs::TLocationTemplate<ReadType,vfs::IWritable>(sLocalPath)
{};
virtual ~TWriteLocation(){};
};
/**************************************************************************************/
/**************************************************************************************/
typedef TReadLocation<vfs::IWriteType> tReadLocation;
typedef TWriteLocation<vfs::IReadType> tWriteLocation;
} // end namespace
#endif // _VFS_LOCATION_INTERFACE_H_
@@ -0,0 +1,85 @@
/*
* bfVFS : vfs/Core/Location/vfs_directory_tree.h
* - class for directories in a File System, implements Directory interface
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_DIRECTORY_H_
#define _VFS_DIRECTORY_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/Interface/vfs_directory_interface.h>
#include <map>
#include <vector>
namespace vfs
{
/**
* IDirectory<read,write>
*/
template<typename WriteType>
class TDirectoryTree : public vfs::TDirectory<WriteType>
{
typedef std::map<vfs::Path, vfs::TDirectory<typename TDirectoryTree<WriteType>::tWriteType>*, vfs::Path::Less> tDirCatalogue;
class IterImpl;
public:
typedef vfs::TDirectory<WriteType> tBaseClass;
typedef typename tBaseClass::tWriteType tWriteType;
typedef typename tBaseClass::tFileType tFileType;
typedef TIterator<vfs::IBaseFile> Iterator;
TDirectoryTree(vfs::Path const& sMountPoint, vfs::Path const& sRealPath);
virtual ~TDirectoryTree();
bool init();
/**
* TDirectory interface
*/
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
virtual bool addFile(tFileType* pFile, bool bDeleteOldFile=false);
virtual bool createSubDirectory(vfs::Path const& sSubDirPath);
virtual bool deleteDirectory(vfs::Path const& sDirPath);
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName);
/**
* TLocation interface
*/
virtual bool fileExists(vfs::Path const& sFileName);
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName);
virtual tFileType* getFileTyped(vfs::Path const& sFileName);
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
virtual Iterator begin();
protected:
tDirCatalogue m_catDirs;
};
typedef TDirectoryTree<vfs::IWritable> CDirectoryTree;
typedef TDirectoryTree<vfs::IWriteType> CReadOnlyDirectoryTree;
} // end namespace
#endif // _VFS_DIRECTORY_H_
@@ -0,0 +1,66 @@
/*
* bfVFS : vfs/Core/Location/vfs_lib_dir.h
* - class for readonly (sub)directories in archives/libraries
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_LIB_DIR_H_
#define _VFS_LIB_DIR_H_
#include <vfs/Core/Interface/vfs_directory_interface.h>
namespace vfs
{
class CLibDirectory : public vfs::TDirectory<vfs::IWriteType>
{
typedef vfs::TDirectory<vfs::IWriteType> tBaseClass;
typedef std::map<vfs::Path, tFileType*, vfs::Path::Less> tFileCatalogue;
class IterImpl;
public:
CLibDirectory(vfs::Path const& sLocalPath, vfs::Path const& sRealPath);
virtual ~CLibDirectory();
/**
* TDirectory interface
*/
virtual tFileType* addFile(vfs::Path const& filename, bool deleteOldFile=false);
virtual bool addFile(tFileType* file, bool deleteOldFile=false);
virtual bool deleteFileFromDirectory(vfs::Path const& filename);
virtual bool createSubDirectory(vfs::Path const& subDirPath);
virtual bool deleteDirectory(vfs::Path const& dirPath);
/**
* TLocation interface
*/
virtual bool fileExists(vfs::Path const& filename);
virtual vfs::IBaseFile* getFile(vfs::Path const& filename);
virtual tFileType* getFileTyped(vfs::Path const& filename);
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
virtual Iterator begin();
protected:
tFileCatalogue m_files;
};
} // -end- namespace
#endif // _VFS_LIB_DIR_H_
@@ -0,0 +1,88 @@
/*
* bfVFS : vfs/Core/Location/vfs_uncompressed_lib_base.h
* - partially implements library interface for uncompressed archive files
* - initialization is done in format-specific sub-classes
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_UNCOMPRESSED_LIB_BASE_H_
#define _VFS_UNCOMPRESSED_LIB_BASE_H_
#include <vfs/Core/Interface/vfs_library_interface.h>
#include <vfs/Core/Interface/vfs_directory_interface.h>
#include <sstream>
namespace vfs
{
class VFS_API CUncompressedLibraryBase : public vfs::ILibrary
{
protected:
typedef std::map<vfs::Path, vfs::TDirectory<vfs::ILibrary::tWriteType>*, vfs::Path::Less> tDirCatalogue;
struct SFileData
{
SFileData(vfs::size_t const& fileSize, vfs::size_t const& fileOffset)
: _fileSize(fileSize), _fileOffset(fileOffset), _currentReadPosition(0)
{};
vfs::size_t _fileSize, _fileOffset, _currentReadPosition;
};
typedef std::map<tFileType*, SFileData> tFileData;
class IterImpl;
public:
CUncompressedLibraryBase(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile = false);
virtual ~CUncompressedLibraryBase();
/**
* TLocation interface
*/
virtual bool fileExists(vfs::Path const& filename);
virtual vfs::IBaseFile* getFile(vfs::Path const& filename);
virtual tFileType* getFileTyped(vfs::Path const& filename);
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
/**
* ILibrary interface
*/
virtual bool init() = 0;
virtual void closeLibrary();
virtual void close(tFileType *fileHandle);
virtual bool openRead(tFileType *fileHandle);
virtual vfs::size_t read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead);
virtual vfs::size_t getReadPosition(tFileType *fileHandle);
virtual void setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes);
virtual void setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir);
virtual vfs::size_t getSize(tFileType *fileHandle);
virtual Iterator begin();
protected:
tDirCatalogue m_dirs;
tFileData m_fileData;
vfs::UInt32 m_numberOfOpenedFiles;
private:
SFileData& _fileDataFromHandle(tFileType* handle);
};
} // end namespace
#endif // _VFS_UNCOMPRESSED_LIB_BASE_H_
+90
View File
@@ -0,0 +1,90 @@
/*
* bfVFS : vfs/Core/vfs.h
* - primary interface for the using program, get files from the VFS internal storage
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_H_
#define _VFS_H_
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/Interface/vfs_location_interface.h>
#include <vfs/Core/Interface/vfs_iterator_interface.h>
#include <vfs/Core/vfs_vloc.h>
#include <vfs/Core/vfs_vfile.h>
#include <map>
namespace vfs
{
class CProfileStack;
class VFS_API CVirtualFileSystem
{
typedef std::map<vfs::Path,CVirtualLocation*,vfs::Path::Less> tVFS;
class CRegularIterator;
class CMatchingIterator;
public:
typedef TIterator<vfs::tReadableFile> Iterator;
~CVirtualFileSystem();
static CVirtualFileSystem* getVFS();
static void shutdownVFS();
vfs::CProfileStack* getProfileStack();
vfs::CVirtualLocation* getVirtualLocation(vfs::Path const& sPath, bool bCreate = false);
bool addLocation(vfs::IBaseLocation* pLocation, vfs::CVirtualProfile *pProfile);
bool fileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
bool fileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName);
vfs::IBaseFile* getFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
vfs::IBaseFile* getFile(vfs::Path const& rLocalFilePath, vfs::String const& sProfileName);
vfs::tReadableFile* getReadFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
vfs::tReadableFile* getReadFile(vfs::Path const& rLocalFilePath, vfs::String const& sProfileName);
vfs::tWritableFile* getWriteFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
vfs::tWritableFile* getWriteFile(vfs::Path const& rLocalFilePath, vfs::String const& sProfileName);
bool removeFileFromFS(vfs::Path const& sFilePath);
bool removeDirectoryFromFS(vfs::Path const& sDir);
bool createNewFile(vfs::Path const& sFileName);
Iterator begin();
Iterator begin(vfs::Path const& sPattern);
private:
vfs::CProfileStack m_oProfileStack;
tVFS m_mapFS;
private:
CVirtualFileSystem();
static CVirtualFileSystem* m_pSingleton;
};
VFS_API bool canWrite();
} // end namespace
VFS_API vfs::CVirtualFileSystem* getVFS();
#endif // _VFS_H_
+90
View File
@@ -0,0 +1,90 @@
/*
* bfVFS : vfs/Core/vfs_dfebug.h
* - Exception class and throw macros, used to notify the using program of unexpected situations
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_DEBUG_H_
#define _VFS_DEBUG_H_
#include <vfs/Aspects/vfs_logging.h>
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_path.h>
#include <list>
#ifdef _MSC_VER
class VFS_API std::exception;
#endif
namespace vfs
{
class VFS_API Exception : public std::exception
{
public:
Exception(vfs::String const& text, vfs::String const& function, int line, const char* file);
Exception(vfs::String const& text, vfs::String const& function, int line, const char* file, std::exception& ex);
virtual ~Exception() throw();
virtual const char* what() const throw();
vfs::String getLastEntryString() const;
vfs::String getExceptionString() const;
struct SEntry
{
vfs::String time;
vfs::String message;
vfs::String function;
int line;
vfs::String file;
};
typedef std::list<SEntry> CALLSTACK;
CALLSTACK m_CallStack;
};
}
#ifdef WIN32
#define _FUNCTION_FORMAT_ __FUNCTION__
#else
//#define _FUNCTION_FORMAT_ __FUNCTION__
#define _FUNCTION_FORMAT_ __PRETTY_FUNCTION__
#endif
#define VFS_THROW(message) throw vfs::Exception((message), _FUNCTION_FORMAT_, __LINE__, __FILE__)
#define VFS_RETHROW(message,ex) throw vfs::Exception((message), _FUNCTION_FORMAT_, __LINE__, __FILE__, (ex))
#define VFS_THROW_IFF(boolexpr,message) if(!(boolexpr)){VFS_THROW((message));}
#define VFS_TRYCATCH_RETHROW(expr,message) \
{ \
try { (expr); } \
catch(std::exception &ex){ throw vfs::Exception((message),_FUNCTION_FORMAT_,__LINE__,__FILE__, ex); } \
}
#define VFS_IGNOREEXCEPTION(expr, log) \
{ \
try{ (expr); } \
catch(std::exception& ex){ \
if(log) VFS_LOG_ERROR(ex.what()); } \
}
#endif // _VFS_DEBUG_H_
+65
View File
@@ -0,0 +1,65 @@
/*
* bfVFS : vfs/Core/vfs_file_raii.h
* - RAII classes to open files for reading/writing
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_FILE_RAII_H_
#define _VFS_FILE_RAII_H_
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/vfs_vfile.h>
namespace vfs
{
class VFS_API COpenReadFile
{
public:
COpenReadFile(vfs::Path const& sPath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP);
COpenReadFile(vfs::tReadableFile *pFile);
~COpenReadFile();
vfs::tReadableFile* operator->();
vfs::tReadableFile& file();
void release();
private:
vfs::tReadableFile* m_pFile;
};
class VFS_API COpenWriteFile
{
public:
COpenWriteFile( vfs::Path const& sPath,
bool bCreate = false,
bool bTruncate = false,
vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
COpenWriteFile(vfs::tWritableFile *pFile);
~COpenWriteFile();
vfs::tWritableFile* operator->();
vfs::tWritableFile& file();
void release();
private:
vfs::tWritableFile* m_pFile;
};
} // end namespace
#endif // _VFS_FILE_RAII_H_
+82
View File
@@ -0,0 +1,82 @@
/*
* bfVFS : vfs/Core/vfs_init.h
* - initialization functions/classes
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_INIT_H_
#define _VFS_INIT_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_profile.h>
#include <vfs/Tools/vfs_property_container.h>
namespace vfs_init
{
class VFS_API Location
{
public:
Location();
bool m_optional;
vfs::String m_type;
vfs::Path m_path, m_vfs_path;
vfs::Path m_mount_point;
};
class VFS_API Profile
{
public:
Profile();
~Profile();
void addLocation(Location* loc, bool own = false);
////////////////////////////////////////////////
typedef std::list<std::pair<bool,Location*> > t_locations;
t_locations locations;
vfs::String m_name;
vfs::Path m_root;
bool m_writable;
};
class VFS_API VfsConfig
{
public:
typedef std::list<std::pair<bool,Profile*> > t_profiles;
~VfsConfig();
t_profiles profiles;
void addProfile(Profile* prof, bool own = false);
void appendConfig(VfsConfig& conf);
};
////////////////////////////////////////////////////////////////////////////
VFS_API bool initWriteProfile(vfs::CVirtualProfile &rProf);
VFS_API bool initVirtualFileSystem(vfs::Path const& vfs_ini);
VFS_API bool initVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list);
VFS_API bool initVirtualFileSystem(vfs::PropertyContainer& props);
VFS_API bool initVirtualFileSystem(vfs_init::VfsConfig const& conf);
};
#endif // _VFS_INIT_H_
+107
View File
@@ -0,0 +1,107 @@
/*
* bfVFS : vfs/Core/os_functions.h
* - abstractions for OS dependant code
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_OS_FUNCTIONS_H_
#define _VFS_OS_FUNCTIONS_H_
#ifdef WIN32
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/dir.h>
#include <unistd.h>
#include <stdio.h>
#endif
#include <vfs/vfs_config.h>
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_path.h>
namespace vfs
{
namespace OS
{
class VFS_API CIterateDirectory
{
public:
enum EFileAttribute
{
FA_DIRECTORY,
FA_FILE
};
public:
CIterateDirectory(vfs::Path const& sPath, vfs::String const& searchPattern);
~CIterateDirectory();
bool nextFile(vfs::String &fileName, CIterateDirectory::EFileAttribute &attrib);
private:
#ifdef WIN32
HANDLE fSearchHandle;
union
{
WIN32_FIND_DATAA fFileInfoA;
WIN32_FIND_DATAW fFileInfoW;
};
#else
struct direct **files;
int count, current_pos;
#endif
bool fFirstRequest;
};
class FileAttributes
{
public:
enum Attributes
{
ATTRIB_INVALID = 0,
ATTRIB_ARCHIVE = 1,
ATTRIB_DIRECTORY = 2,
ATTRIB_HIDDEN = 4,
ATTRIB_NORMAL = 8,
ATTRIB_READONLY = 16,
ATTRIB_SYSTEM = 32,
ATTRIB_TEMPORARY = 64,
ATTRIB_COMPRESSED = 128,
ATTRIB_OFFLINE = 256,
};
bool getFileAttributes(vfs::Path const& sDir, vfs::UInt32& uiAttribs);
};
VFS_API bool checkRealDirectory(vfs::Path const& sDir);
VFS_API bool createRealDirectory(vfs::Path const& sDir);
VFS_API bool deleteRealFile(vfs::Path const& sDir);
VFS_API void getExecutablePath(vfs::Path& sDir, vfs::Path& sFile);
VFS_API void getCurrentDirectory(vfs::Path& sDir);
VFS_API void setCurrectDirectory(vfs::Path const& sPath);
VFS_API bool getEnv(vfs::String const& key, vfs::String& value);
}; // end namespace OS
} // end namespace vfs
#endif // _VFS_OS_FUNCTIONS_H_
+99
View File
@@ -0,0 +1,99 @@
/*
* bfVFS : vfs/Core/vfs_path.h
* - Path class, stores and validates a file/directory path string, offers meaningful path operations
* - path comparison functions (operator overloading)
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_PATH_H_
#define _VFS_PATH_H_
#include <vfs/vfs_config.h>
#include <vfs/Core/vfs_types.h>
namespace vfs
{
class VFS_API Path
{
public:
class VFS_API Less{
public:
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
};
class Equal{
public:
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
};
public:
Path();
Path(const char* sPath);
Path(std::string const& sPath);
Path(const wchar_t* sPath);
Path(vfs::String const& sPath);
const vfs::String::char_t* c_str() const;
const vfs::String::str_t& c_wcs() const;
const vfs::String::str_t& operator()() const;
std::string to_string() const;
Path& operator+=(Path const& p);
Path& operator+=(vfs::String const& p);
bool empty() const;
vfs::String::size_t length() const;
void doCheck();
bool expandEnv();
void splitLast(vfs::Path &rsHead, vfs::Path &rsLast) const;
void splitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const;
bool extension(vfs::String &sExt) const;
bool operator==(vfs::Path const& p2);
private:
vfs::String::str_t _path;
struct SeparatorPosition
{
SeparatorPosition() : first(vfs::npos), last(vfs::npos) {}
vfs::size_t first, last;
} _sep;
};
}
template<>
VFS_API BuildString& BuildString::add<vfs::Path>(vfs::Path const& value);
template<>
VFS_API BuildString& BuildString::operator<< <vfs::Path>(vfs::Path const& value);
// add only valid Path objects
VFS_API vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2);
VFS_API bool operator==(vfs::Path const& p1, vfs::Path const& p2);
// compare path with string (that can be an invalid path)
// use with care as these strings can be different from the internal representation although they seem to be equal
VFS_API bool operator==(vfs::Path const& p1, vfs::String const& p2);
VFS_API bool operator==(vfs::Path const& p1, vfs::String::str_t const& p2);
VFS_API bool operator==(vfs::Path const& p1, const vfs::String::char_t* p2);
#endif // _VFS_PATH_H_
+92
View File
@@ -0,0 +1,92 @@
/*
* bfVFS : vfs/Core/vfs_profile.h
* - Virtual Profile, container for real file system locations or archives
* - Profile Stack, orders profiles in a linear fashion (top-bottom)
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_PROFILE_H_
#define _VFS_PROFILE_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/Interface/vfs_location_interface.h>
#include <map>
#include <set>
namespace vfs
{
class VFS_API CVirtualProfile
{
typedef std::map<vfs::Path,vfs::IBaseLocation*, vfs::Path::Less> tLocations;
typedef std::set<vfs::IBaseLocation*> tUniqueLoc;
class IterImpl;
class FileIterImpl;
public:
typedef TIterator<vfs::IBaseLocation> Iterator;
typedef TIterator<vfs::IBaseFile> FileIterator;
CVirtualProfile(vfs::String const& profile_name, vfs::Path profile_root, bool writable = false);
~CVirtualProfile();
const vfs::String cName;
const vfs::Path cRoot;
const bool cWritable;
Iterator begin();
FileIterator files(vfs::Path const& sPattern);
void addLocation(vfs::IBaseLocation* pLoc);
vfs::IBaseLocation* getLocation(vfs::Path const& sPath) const;
vfs::IBaseFile* getFile(vfs::Path const& sPath) const;
private:
void operator=(vfs::CVirtualProfile const& vprof);
tLocations m_mapLocations;
tUniqueLoc m_setLocations;
};
class VFS_API CProfileStack
{
class IterImpl;
public:
typedef vfs::TIterator<CVirtualProfile> Iterator;
CProfileStack();
~CProfileStack();
CVirtualProfile* getWriteProfile();
CVirtualProfile* getProfile(vfs::String const& sName) const;
CVirtualProfile* topProfile() const;
/**
* All files from the top profile will be removed from the VFS and the profile object will be deleted.
*/
bool popProfile();
void pushProfile(CVirtualProfile* pProfile);
Iterator begin();
private:
typedef std::list<vfs::CVirtualProfile*> t_profiles;
t_profiles m_profiles;
};
} // end namespace
#endif
+233
View File
@@ -0,0 +1,233 @@
/*
* bfVFS : vfs/Core/vfs_string.h
* - string class that allows conversions to/from Unicode representation (uses wchar_t internally)
* - comparison, concatenation, stream output class/functions
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_STRING_H_
#define _VFS_STRING_H_
#include <vfs/vfs_config.h>
#include <string>
#include <sstream>
namespace vfs
{
// simple UTF8 wrapper, uses utf8 implementation from http://utfcpp.sourceforge.net/
class VFS_API String
{
friend VFS_API bool operator<(vfs::String const& s1, vfs::String const& s2);
public:
typedef std::wstring str_t;
typedef str_t::value_type char_t;
typedef str_t::value_type* ptr_t;
typedef str_t::size_type size_t;
////////////////////////////////////////////////////////////////////
static bool less(const vfs::String::char_t* s1, const vfs::String::char_t* s2);
static bool equal(const vfs::String::char_t* s1, const vfs::String::char_t* s2);
// case sensitive
static bool lessCase(const vfs::String::char_t* s1, const vfs::String::char_t* s2);
static bool equalCase(const vfs::String::char_t* s1, const vfs::String::char_t* s2);
template<bool (*funName)(const vfs::String::char_t* s1, const vfs::String::char_t* s2)>
class Op{
public:
bool operator()(const vfs::String& s1, const vfs::String& s2) const
{
return funName(s1.c_str(),s2.c_str());
}
};
typedef Op<vfs::String::less> Less;
typedef Op<vfs::String::lessCase> LessCase;
typedef Op<vfs::String::equal> Equal;
typedef Op<vfs::String::equalCase> EqualCase;
public:
String();
String(const char* str);
String(std::string const& str);
String(const wchar_t* str);
String(std::wstring const& str);
////////////////////////////////////////////////////////////////////
static vfs::String::str_t as_utf16(const char* str);
static void as_utf16(const char* str, vfs::String::str_t &str16);
static vfs::String::str_t as_utf16(std::string const& str);
static void as_utf16(std::string const& str, vfs::String::str_t &str16);
// fast conversion without creating an internal copy
static std::string as_utf8(vfs::String const& str);
static std::string as_utf8(std::wstring const& str);
// if 'strlen' is 0, length is determined automatically
static std::string as_utf8(const wchar_t* str, vfs::String::size_t strlength=0);
//
static std::string narrow(wchar_t const* str, vfs::String::size_t length);
static vfs::String::size_t narrow(wchar_t const* src_str, vfs::String::size_t src_len, char* dst_str, vfs::String::size_t dst_len);
static vfs::String::size_t narrow(std::wstring const& src, std::string& dst);
//
static std::wstring widen(char const* str, vfs::String::size_t length);
static vfs::String::size_t widen(char const* src_str, vfs::String::size_t src_len, wchar_t* dst_str, vfs::String::size_t dst_len);
static vfs::String::size_t widen(std::string const& src, std::wstring& dst);
// convenience method, for the case it should be used in generic code (overloading)
static std::string as_utf8(std::string const& str);
////////////////////////////////////////////////////////////////////
// convert string to UTF8 encoding
inline std::string utf8() const { return as_utf8(_str); }
// returns const reference to copy or compare string
inline std::wstring const& c_wcs() const { return _str; }
inline const wchar_t* c_str() const { return _str.c_str(); }
// returns reference to modify string
inline std::wstring& r_wcs() { return _str; }
////////////////////////////////////////////////////////////////////
bool empty() const;
vfs::String::size_t length() const;
////////////////////////////////////////////////////////////////////
vfs::String operator+(vfs::String const& str);
vfs::String operator+=(vfs::String const& str);
private:
str_t _str;
};
} // namespace vfs
namespace vfs
{
VFS_API bool operator<(vfs::String const& s1, vfs::String const& s2);
}
VFS_API std::wostream& operator<<(std::wostream& out, vfs::String const& str);
VFS_API std::wostream& operator<<(std::wostream& out, vfs::String::str_t const& str);
VFS_API std::wostream& operator<<(std::wostream& out, const vfs::String::char_t* str);
namespace vfs
{
// explicit compare
namespace StrCmp
{
// case IN-sensitive
VFS_API bool Equal(const char* s1, const char* s2);
VFS_API bool Equal(std::string const& s1, std::string const& s2);
VFS_API bool Equal(std::string const& s1, const char* s2);
VFS_API bool Equal(const char* s1, std::string const& s2);
//
VFS_API bool Equal(const wchar_t* s1, const wchar_t* s2);
VFS_API bool Equal(std::wstring const& s1, std::wstring const& s2);
VFS_API bool Equal(std::wstring const& s1, const wchar_t* s2);
VFS_API bool Equal(const wchar_t* s1, std::wstring const& s2);
//
VFS_API bool Equal(vfs::String const& s1, vfs::String const& s2);
VFS_API bool Equal(vfs::String const& s1, std::wstring const& s2);
VFS_API bool Equal(std::wstring const& s1, vfs::String const& s2);
VFS_API bool Equal(vfs::String const& s1, const wchar_t* s2);
VFS_API bool Equal(const wchar_t* s1, vfs::String const& s2);
// case Sensitive
VFS_API bool EqualCase(const char* s1, const char* s2);
VFS_API bool EqualCase(std::string const& s1, std::string const& s2);
VFS_API bool EqualCase(std::string const& s1, const char* s2);
VFS_API bool EqualCase(const char* s1, std::string const& s2);
//
VFS_API bool EqualCase(const wchar_t* s1, const wchar_t* s2);
VFS_API bool EqualCase(std::wstring const& s1, std::wstring const& s2);
VFS_API bool EqualCase(std::wstring const& s1, const wchar_t* s2);
VFS_API bool EqualCase(const wchar_t* s1, std::wstring const& s2);
//
VFS_API bool EqualCase(vfs::String const& s1, vfs::String const& s2);
VFS_API bool EqualCase(vfs::String const& s1, std::wstring const& s2);
VFS_API bool EqualCase(std::wstring const& s1, vfs::String const& s2);
VFS_API bool EqualCase(vfs::String const& s1, const wchar_t* s2);
VFS_API bool EqualCase(const wchar_t* s1, vfs::String const& s2);
}
} // namespace vfs
class VFS_API BuildString
{
public:
enum _cget{cget};
enum _wget{wget};
BuildString()
{}
std::string operator<<(_cget)
{
return vfs::String::as_utf8(_strstr.str());
}
std::wstring operator<<(_wget)
{
return _strstr.str();
}
BuildString(BuildString const& bs)
{
_strstr.str(bs._strstr.str());
}
template<typename T>
BuildString(T const& t)
{
add(t);
}
template<typename T>
BuildString& add(T const& value)
{
_strstr << value;
return *this;
}
template<typename T>
BuildString& operator<<(T const& value)
{
_strstr << value;
return *this;
}
vfs::String::str_t get()
{
return _strstr.str();
}
private:
std::basic_stringstream<vfs::String::char_t> _strstr;
};
typedef BuildString _BS;
template<>
VFS_API BuildString& BuildString::add<vfs::String>(vfs::String const& value);
template<>
VFS_API BuildString& BuildString::add<std::string>(std::string const& value);
template<>
VFS_API BuildString& BuildString::add<const char*>(const char* const& value);
template<>
VFS_API BuildString& BuildString::operator<< <vfs::String>(vfs::String const& value);
template<>
VFS_API BuildString& BuildString::operator<< <std::string>(std::string const& value);
template<>
VFS_API BuildString& BuildString::operator<< <const char*>(const char* const& value);
#endif // _VFS_STRING_H_
+93
View File
@@ -0,0 +1,93 @@
/*
* bfVFS : vfs/Core/vfs_types.h
* - basic integer types, "incomplete" list of useful constant strings
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_TYPES_H_
#define _VFS_TYPES_H_
#include <vfs/Core/vfs_string.h>
#ifdef __linux__
# include <stdint.h>
#endif
namespace vfs
{
#ifdef WIN32
typedef unsigned __int64 UInt64;
typedef unsigned __int32 UInt32;
typedef unsigned __int16 UInt16;
typedef unsigned __int8 UInt8;
typedef unsigned __int8 UByte;
typedef __int64 Int64;
typedef __int32 Int32;
typedef __int16 Int16;
typedef __int8 Int8;
typedef __int8 Byte;
#elif __linux__
typedef uint64_t UInt64;
typedef uint32_t UInt32;
typedef uint16_t UInt16;
typedef uint8_t UInt8;
typedef uint8_t UByte;
typedef int64_t Int64;
typedef int32_t Int32;
typedef int16_t Int16;
typedef int8_t Int8;
typedef char Byte;
#endif
typedef ::size_t size_t;
typedef ::off_t offset_t;
extern const vfs::size_t npos;
}
namespace vfs
{
namespace Const
{
inline const vfs::String::str_t EMPTY() { return L""; };
//inline const vfs::String::char_t EMPTY_CHAR() { return L''; };
inline const vfs::String::str_t DOT() { return L"."; };
inline const vfs::String::char_t DOT_CHAR() { return L'.'; };
inline const vfs::String::str_t DOTDOT() { return L".."; };
inline const vfs::String::str_t DOTSVN() { return L".svn"; };
inline const vfs::String::str_t STAR() { return L"*"; };
inline const vfs::String::str_t DSTAR() { return L"**"; };
#ifdef WIN32
inline const vfs::String::str_t SEPARATOR() { return L"\\"; };
inline const vfs::String::char_t SEPARATOR_CHAR() { return L'\\'; };
#else
inline const vfs::String::str_t SEPARATOR() { return L"/"; };
inline const vfs::String::char_t SEPARATOR_CHAR() { return L'/'; };
#endif
}
}
#endif // _VFS_TYPES_H_
+70
View File
@@ -0,0 +1,70 @@
/*
* bfVFS : vfs/Core/vfs_vfile.h
* - Virtual File, handles access to files from different VFS profiles
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_VFILE_H_
#define _VFS_VFILE_H_
#include <vfs/Core/vfs_profile.h>
#include <vfs/Tools/vfs_allocator.h>
#include <vector>
#define VFILE_BLOCK_CREATE
namespace vfs
{
class VFS_API CVirtualFile
{
public:
enum ESearchFile
{
SF_TOP,
SF_FIRST_WRITABLE,
SF_STOP_ON_WRITABLE_PROFILE,
};
public:
CVirtualFile();
~CVirtualFile();
void destroy();
static CVirtualFile* create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack);
vfs::Path const& path();
void add(vfs::IBaseFile *pFile, vfs::String sProfileName, bool bReplace = false);
bool remove(vfs::IBaseFile *pFile);
//////////////////////////////////////////////////
vfs::IBaseFile* file(ESearchFile eSearch);
vfs::IBaseFile* file(vfs::String const& sProfileName);
//////////////////////////////////////////////////
private:
vfs::Path _path;
vfs::String _top_pname;
vfs::IBaseFile* _top_file;
CProfileStack* _pstack;
private:
vfs::UInt32 _myID;
#ifdef VFILE_BLOCK_CREATE
static ObjBlockAllocator<vfs::CVirtualFile>* _vfile_pool;
#endif
};
} // end namspace
#endif // _VFS_VFILE_H_
+67
View File
@@ -0,0 +1,67 @@
/*
* bfVFS : vfs/Core/vfs_vloc.h
* - Virtual Location, stores Virtual Files
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_VLOC_H_
#define _VFS_VLOC_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/Interface/vfs_iterator_interface.h>
#include <map>
namespace vfs
{
class CVirtualFile;
class VFS_API CVirtualLocation
{
class VFileIterator;
typedef std::map<vfs::Path, CVirtualFile*, vfs::Path::Less> tVFiles;
public:
typedef vfs::TIterator<CVirtualFile> Iterator;
CVirtualLocation(vfs::Path const& sPath);
~CVirtualLocation();
const vfs::Path cPath;
void setIsExclusive(bool exclusive);
bool getIsExclusive();
void addFile(vfs::IBaseFile* pile, vfs::String const& profileName);
vfs::IBaseFile* getFile(vfs::Path const& filename, vfs::String const& profileName = "") const;
vfs::CVirtualFile* getVirtualFile(vfs::Path const& filename);
bool removeFile(vfs::IBaseFile* file);
Iterator iterate();
private:
void operator=(vfs::CVirtualLocation const& vloc);
bool m_exclusive;
tVFiles m_VFiles;
};
} // end namespace
#endif // _VFS_VLOC_H_
@@ -0,0 +1,52 @@
/*
* bfVFS : vfs/Ext/7z/vfs_7z_library.h
* - implements Library interface, creates library object from uncompressed 7-zip archive files
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_7Z_LIBRARY_H_
#define _VFS_7Z_LIBRARY_H_
#ifdef VFS_WITH_7ZIP
#include <vfs/Core/Location/vfs_uncompressed_lib_base.h>
#include <vfs/Core/File/vfs_lib_file.h>
namespace vfs
{
class VFS_API CUncompressed7zLibrary : public vfs::CUncompressedLibraryBase
{
public:
CUncompressed7zLibrary(tReadableFile *libraryFile,
vfs::Path const& mountPoint,
bool ownFile = false,
vfs::ObjBlockAllocator<vfs::CLibFile>* allocator=NULL);
virtual ~CUncompressed7zLibrary();
virtual bool init();
private:
vfs::ObjBlockAllocator<vfs::CLibFile>* _allocator;
};
} // end namespace
#endif // VFS_WITH_7ZIP
#endif // _VFS_7Z_LIBRARY_H_
@@ -0,0 +1,89 @@
/*
* bfVFS : vfs/Ext/7z/vfs_create_7z_library.h
* - writes uncompressed 7z archive file
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_CREATE_7Z_LIBRARY_H_
#define _VFS_CREATE_7Z_LIBRARY_H_
#ifdef VFS_WITH_7ZIP
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <sstream>
#include <map>
#include <list>
namespace vfs
{
class VFS_API CCreateUncompressed7zLibrary
{
public:
CCreateUncompressed7zLibrary();
virtual ~CCreateUncompressed7zLibrary();
bool addFile(vfs::tReadableFile* pFile);
bool writeLibrary(vfs::Path const& sLibName);
bool writeLibrary(vfs::tWritableFile* pFile);
protected:
bool writeSignatureHeader(std::ostream& out);
bool writeNextHeader(std::ostream& out);
bool writeMainStreamsInfo(std::ostream &out);
bool writePackInfo(std::ostream& out);
bool writeUnPackInfo(std::ostream& out);
bool writeSubStreamsInfo(std::ostream& out);
bool writeFolder(std::ostream& out);
bool writeFilesInfo(std::ostream& out);
private:
vfs::size_t writeFileName(std::ostream& out, vfs::String const& filename);
protected:
vfs::tWritableFile* m_pLibFile;
struct SFileInfo
{
SFileInfo()
: name(L""), CRC(0), offset(0), size(0), time_creation(0), time_last_access(0), time_write(0)
{};
//////
vfs::String::str_t name;
vfs::UInt32 CRC;
vfs::UInt64 offset;
vfs::UInt64 size;
vfs::UInt64 time_creation,time_last_access,time_write;
};
typedef std::map<vfs::String::str_t,SFileInfo> tDirInfo;
std::list<SFileInfo> m_lFileInfo;
tDirInfo m_mapDirInfo;
// keeping pointers to files to write their contents lates is not enough,
// as the file may only exist for a short time
std::stringstream m_ssFileStream;
std::stringstream m_ssInfoStream;
};
} // end namespace
#endif // VFS_WITH_7ZIP
#endif // _VFS_CREATE_7Z_LIBRARY_H_
@@ -0,0 +1,47 @@
/*
* bfVFS : vfs/Ext/slf/vfs_slf_library.h
* - implements Library interface, creates library object from SLF archive files
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_SLF_LIBRARY_H_
#define _VFS_SLF_LIBRARY_H_
#ifdef VFS_WITH_SLF
#include <vfs/Core/Location/vfs_uncompressed_lib_base.h>
namespace vfs
{
class VFS_API CSLFLibrary : public vfs::CUncompressedLibraryBase
{
public:
CSLFLibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false);
virtual ~CSLFLibrary();
virtual bool init();
};
} // end namespace
#endif // VFS_WITH_SLF
#endif // _VFS_SLF_LIBRARY_H_
+94
View File
@@ -0,0 +1,94 @@
/*
* bfVFS : vfs/Tools/vfs_allocator.h
* - allocator class to reserve memory blockwise for a larger amount of objects (that have constant size)
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_ALLOCATOR_H_
#define _VFS_ALLOCATOR_H_
#include <vfs/vfs_config.h>
#include <vector>
namespace vfs
{
// needs to be destructible
class VFS_API IAllocator
{
public:
virtual ~IAllocator() {};
};
template<typename T>
class VFS_API ObjBlockAllocator : public IAllocator
{
public:
ObjBlockAllocator(unsigned int blockSize=1024)
: IAllocator(), BLOCK_SIZE(blockSize), _ObjNew(0) {};
const unsigned int BLOCK_SIZE;
///
T* New(unsigned int *ID = NULL)
{
unsigned int block_id = _ObjNew/BLOCK_SIZE;
unsigned int file_id = _ObjNew % BLOCK_SIZE;
if(block_id >= _ObjPool.size())
{
tBlock* b = new tBlock();
b->resize(BLOCK_SIZE);
_ObjPool.push_back(b);
}
tBlock* block = _ObjPool[block_id];
T* obj = &(*block)[file_id];
if(ID)
{
*ID = _ObjNew;
}
_ObjNew++;
return obj;
}
///
virtual ~ObjBlockAllocator()
{
for(unsigned int i = 0; i < _ObjPool.size(); ++i)
{
delete _ObjPool[i];
}
}
private:
void operator=(ObjBlockAllocator<T> const& t);
typedef std::vector<T> tBlock;
std::vector<tBlock*> _ObjPool;
unsigned int _ObjNew;
};
class VFS_API ObjectAllocator
{
public:
static void registerAllocator(IAllocator* allocator);
static void clear();
private:
static std::vector<IAllocator*> _valloc;
};
} // namespace vfs
#endif // _VFS_ALLOCATOR_H_
@@ -0,0 +1,51 @@
/*
* bfVFS : vfs/Tools/vfs_file_logger.h
* - implements Logging iterface in the Aspects module by using the vfs::Log class
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_FILE_LOGGER_H_
#define _VFS_FILE_LOGGER_H_
#include <vfs/Core/vfs_path.h>
#include <vfs/Tools/vfs_log.h>
#include <vfs/Tools/vfs_hp_timer.h>
#include <vfs/Aspects/vfs_logging.h>
namespace vfs
{
class VFS_API FileLogger : public vfs::Aspects::ILogger
{
public:
FileLogger(vfs::Path const& log_file, bool append = false, vfs::Log::EFlushMode flush_mode = vfs::Log::FLUSH_ON_ENDL);
FileLogger(vfs::tWritableFile* file, bool append = false, vfs::Log::EFlushMode flush_mode = vfs::Log::FLUSH_ON_ENDL);
~FileLogger();
virtual void Msg(const wchar_t* msg);
virtual void Msg(const char* msg);
void Msg(vfs::String const& msg);
private:
Log& m_log;
HPTimer m_clock;
};
}
#endif // _VFS_FILE_LOGGER_H_
+61
View File
@@ -0,0 +1,61 @@
/*
* bfVFS : vfs/Tools/vfs_hp_timer.h
* - high performance/precision timer, used by profiler
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_HP_TIMER_
#define _VFS_HP_TIMER_
#include <vfs/vfs_config.h>
#ifdef WIN32
#include <Windows.h>
#elif __linux__
#include <sys/time.h>
#endif
namespace vfs
{
class VFS_API HPTimer
{
public:
HPTimer();
~HPTimer();
void startTimer();
void stopTimer();
long long ticks();
double running();
double getElapsedTimeInSeconds();
protected:
bool is_running;
#ifdef WIN32
LARGE_INTEGER ticksPerSecond;
LARGE_INTEGER tick,tick2;
#elif __linux__
timeval t1,t2;
#endif
};
}
#endif // _VFS_HP_TIMER_
+164
View File
@@ -0,0 +1,164 @@
/*
* bfVFS : vfs/Tools/vfs_log.h
* - simple file logger
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_LOG_H_
#define _VFS_LOG_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_file_raii.h>
#include <vfs/Core/File/vfs_file.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Tools/vfs_tools.h>
#include <vfs/Aspects/vfs_synchronization.h>
namespace vfs
{
class VFS_API IRefCountable
{
public:
IRefCountable() : _ref_count(1) {}
virtual ~IRefCountable() {}
virtual int Reserve() { return Register(); }
virtual int Release() { return UnRegister(); }
virtual int RefCount() { return GetRefCount(); }
protected:
int Register() {
return ++_ref_count;
}
int UnRegister() {
int tmp_count = --_ref_count;
if(_ref_count <= 0) {
delete this;
}
return tmp_count;
}
int GetRefCount() {
return _ref_count;
}
private:
int _ref_count;
};
class VFS_API Log : public IRefCountable
{
public:
enum EFlushMode
{
FLUSH_ON_DELETE,
FLUSH_ON_ENDL,
FLUSH_BUFFER,
FLUSH_IMMEDIATELY,
};
enum _endl{endl};
public:
Log(vfs::Path const& fileName, bool use_vfs_file, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
Log(vfs::tWritableFile* file, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
virtual ~Log();
// reimplemented for synchronization
virtual int Reserve();
virtual int Release();
virtual int RefCount();
// don't explicitely call destroy if you haven't explicitely created the object
void destroy();
void releaseFile();
static Log* create(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
static Log* create(vfs::tWritableFile* file, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
static void flushReleaseAll();
static void flushDeleteAll();
static vfs::String const& getSharedString();
static void setSharedString(vfs::String const& str);
Log& operator<<(vfs::UInt64 const& t);
Log& operator<<(vfs::UInt32 const& t);
Log& operator<<(vfs::UInt16 const& t);
Log& operator<<(vfs::UInt8 const& t);
Log& operator<<(vfs::Int64 const& t);
Log& operator<<(vfs::Int32 const& t);
Log& operator<<(vfs::Int16 const& t);
Log& operator<<(vfs::Int8 const& t);
#ifdef _MSC_VER
Log& operator<<(DWORD const& t);
#endif
Log& operator<<(float const& t);
Log& operator<<(double const& t);
Log& operator<<(const char* t);
Log& operator<<(const wchar_t* t);
Log& operator<<(std::string const& t);
Log& operator<<(std::wstring const& t);
Log& operator<<(vfs::String const& t);
Log& operator<<(void* const& t);
Log& operator<<(vfs::Log::_endl const& endl);
void setAppend(bool append = true);
void setBufferSize(vfs::UInt32 bufferSize);
void lock();
void unlock();
void flush();
EFlushMode flushMode();
void flushMode(EFlushMode fmode);
private:
void _test_flush(bool force=false);
template<typename T_>
Log& pushNumber(T_ const& t)
{
_buffer << toString<char>(t);
_buffer_size += sizeof(T_);
_test_flush();
return *this;
}
private:
vfs::Path _filename;
vfs::tWritableFile* _file;
bool _own_file;
bool _first_write;
EFlushMode _flush_mode;
bool _append;
::size_t _buffer_size, _buffer_test_size;
std::stringstream _buffer;
vfs::Aspects::Mutex _mutex;
private:
static std::list<Log*>& _logs();
static vfs::String _shared_id_str;
};
} // end namespace vfs
#endif // _VFS_LOG_H_
@@ -0,0 +1,80 @@
/*
* bfVFS : vfs/Tools/vfs_parser_tools.h
* - read file line-wise,
* - split string into tokens,
* - simple pattern matching
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_PARSER_TOOLS_H_
#define _VFS_PARSER_TOOLS_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <list>
namespace vfs
{
class VFS_API CReadLine
{
static const vfs::size_t BUFFER_SIZE = 1024;
public:
CReadLine(vfs::tReadableFile& rFile);
~CReadLine();
bool fillBuffer();
bool fromBuffer(std::string& line);
bool getLine(std::string& line);
private:
vfs::Byte _buffer[BUFFER_SIZE+1];
vfs::tReadableFile& _file;
vfs::size_t _bytes_left;
vfs::size_t _buffer_pos;
vfs::size_t _buffer_last;
bool _eof;
void operator=(CReadLine const& rl);
};
/**************************************************************/
/**************************************************************/
class VFS_API CTokenizer
{
public:
CTokenizer(vfs::String const& str);
~CTokenizer();
bool next(vfs::String& token, vfs::String::char_t delimeter = L',');
private:
const vfs::String m_list;
vfs::String::size_t m_current, m_next;
void operator=(CTokenizer const& str);
};
VFS_API bool matchPattern(vfs::String const& sPattern, vfs::String const& sStr);
VFS_API bool matchPattern(vfs::String const& sPattern, vfs::String::str_t const& sStr);
} // namespace vfs
#endif // _VFS_PARSER_TOOLS_H_
+107
View File
@@ -0,0 +1,107 @@
/*
* bfVFS : vfs/Tools/vfs_profiler.h
* - basic profiler class and macros to measure execution time of code blocks
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_PROFILER_H_
#define _VFS_PROFILER_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/vfs_path.h>
#include <vfs/Tools/vfs_hp_timer.h>
#include <string>
#include <vector>
#define DO_PROFILE 1
#if DO_PROFILE
# define REGISTERMARKER(id,name) static vfs::Profiler::tMarkerID id = vfs::Profiler::getProfiler().registerMarker(name)
# define STARTMARKER(id) (vfs::Profiler::getProfiler().startMarker(id))
# define STOPMARKER(id,success) (vfs::Profiler::getProfiler().stopMarker(id,success))
# define DUMPPROFILERSTATSTOFILE(file) vfs::Profiler::getProfiler().printProfilerState(file)
#else
# define REGISTERMARKER(id,name)
# define STARTMARKER(id)
# define STOPMARKER(id,success)
# define DUMPPROFILERSTATSTOFILE(file)
#endif
namespace vfs
{
class VFS_API Profiler
{
public:
typedef unsigned int tMarkerID;
static Profiler& getProfiler();
void clear();
tMarkerID registerMarker(const char *marker);
void startMarker(tMarkerID id);
void stopMarker(tMarkerID id, bool success);
bool printProfilerState(vfs::Path const& file);
private:
Profiler();
struct MARKER
{
MARKER() : call_count(0), success_count(0), fail_count(0), time(0.0) {};
std::string markername;
unsigned long call_count;
unsigned long success_count;
unsigned long fail_count;
long double time;
HPTimer timer;
};
std::vector<MARKER> m_vMarker;
unsigned int _nextMarker;
};
class VFS_API ProfileMarker
{
public:
ProfileMarker(Profiler::tMarkerID id, bool default_exit=true)
: _id(id), _exit_success(default_exit)
{
STARTMARKER(_id);
}
~ProfileMarker()
{
STOPMARKER(_id,_exit_success);
}
void exit(bool success)
{
_exit_success = success;
}
private:
Profiler::tMarkerID _id;
bool _exit_success;
};
VFS_API void DumpProfileState(vfs::Path const& path);
} // namespace vfs
#endif // _VFS_PROFILER_H_
@@ -0,0 +1,138 @@
/*
* bfVFS : vfs/Tools/vfs_property_container.h
* - <string,string> key-value map with capability to convert values to other types
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_PROPERTY_CONTAINER_H_
#define _VFS_PROPERTY_CONTAINER_H_
#include <vfs/Core/vfs_types.h>
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <map>
#include <string>
#include <list>
#include <set>
#include <ostream>
namespace vfs
{
class PropertyContainer
{
public:
class TagMap
{
typedef std::map<vfs::String,vfs::String> tTagMap;
public:
TagMap();
vfs::String const& container(vfs::String::char_t* container = NULL);
vfs::String const& section(vfs::String::char_t* section = NULL);
vfs::String const& sectionID(vfs::String::char_t* section_id = NULL);
vfs::String const& key(vfs::String::char_t* key = NULL);
vfs::String const& keyID(vfs::String::char_t* key_id = NULL);
private:
tTagMap _map;
};
public:
VFS_API PropertyContainer(){};
VFS_API ~PropertyContainer(){};
VFS_API void clearContainer();
VFS_API bool initFromIniFile(vfs::Path const& sFileName);
VFS_API bool initFromIniFile(vfs::tReadableFile *pFile);
VFS_API bool writeToIniFile(vfs::Path const& sFileName, bool bCreateNew = false);
// these functions are not implemented
bool initFromXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
bool writeToXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
VFS_API void printProperties(std::ostream &out);
VFS_API bool hasProperty(vfs::String const& sSection, vfs::String const& sKey);
//
VFS_API vfs::String const& getStringProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::String const& sDefaultValue=L"");
VFS_API bool getStringProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::String& sValue, vfs::String const& sDefaultValue=L"");
VFS_API bool getStringProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::String::char_t* sValue, vfs::size_t len, vfs::String const& sDefaultValue=L"");
//
VFS_API vfs::Int64 getIntProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::Int64 iDefaultValue);
VFS_API vfs::Int64 getIntProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue);
//
VFS_API vfs::UInt64 getUIntProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::UInt64 iDefaultValue);
VFS_API vfs::UInt64 getUIntProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue);
//
VFS_API double getFloatProperty(vfs::String const& sSection, vfs::String const& sKey, double fDefaultValue);
VFS_API double getFloatProperty(vfs::String const& sSection, vfs::String const& sKey, double fDefaultValue, double fMinValue, double fMaxValue);
//
VFS_API bool getBoolProperty(vfs::String const& sSection, vfs::String const& sKey, bool bDefaultValue);
//
VFS_API bool getStringListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<vfs::String> &lValueList, vfs::String sDefaultValue);
VFS_API bool getIntListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue);
VFS_API bool getUIntListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue);
VFS_API bool getFloatListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<double> &lValueList, double fDefaultValue);
VFS_API bool getBoolListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<bool> &lValueList, bool bDefaultValue);
//
VFS_API void setStringProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::String const& sValue);
//
VFS_API void setIntProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::Int64 const& iValue);
VFS_API void setUIntProperty(vfs::String const& sSection, vfs::String const& sKey, vfs::UInt64 const& iValue);
VFS_API void setFloatProperty(vfs::String const& sSection, vfs::String const& sKey, double const& fValue);
VFS_API void setBoolProperty(vfs::String const& sSection, vfs::String const& sKey, bool const& bValue);
//
VFS_API void setStringListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<vfs::String> const& slValue);
VFS_API void setIntListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<vfs::Int64> const& ilValue);
VFS_API void setUIntListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<vfs::UInt64> const& ilValue);
VFS_API void setFloatListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<double> const& flValue);
VFS_API void setBoolListProperty(vfs::String const& sSection, vfs::String const& sKey, std::list<bool> const& blValue);
private:
enum EOperation
{
Error, Set, Add,
};
bool extractSection(vfs::String::str_t const& readStr, vfs::size_t startPos, vfs::String::str_t& sSection);
EOperation extractKeyValue(vfs::String::str_t const &readStr, vfs::size_t startPos, vfs::String::str_t& sKey, vfs::String::str_t& sValue);
private:
class Section
{
friend class PropertyContainer;
typedef std::map<vfs::String,vfs::String, vfs::String::Less> tProps;
public:
bool has(vfs::String const& key);
bool add(vfs::String const& key, vfs::String const& value);
bool value(vfs::String const& key, vfs::String& value);
vfs::String& value(vfs::String const& key);
void print(std::ostream& out, vfs::String::str_t sPrefix = L"");
void clear();
private:
tProps mapProps;
};
typedef std::map<vfs::String, Section, vfs::String::Less> tSections;
bool getValueForKey(vfs::String const& sSection, vfs::String const& sKey, vfs::String &sValue);
Section& section(vfs::String const& sSection);
tSections m_mapProps;
};
} // namespace vfs
#endif // _VFS_PROPERTY_CONTAINER_H_
+101
View File
@@ -0,0 +1,101 @@
/*
* bfVFS : vfs/Tools/vfs_tools.h
* - simple from/to string (list) conversion functions,
* - remove leading/trailing whitspace characters in a string
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_TOOLS_H_
#define _VFS_TOOLS_H_
#include <vfs/vfs_config.h>
#include <vfs/Core/vfs_types.h>
#include <list>
namespace vfs
{
template<typename CharType, typename ValueType>
std::basic_string<CharType> toString(ValueType const& rVal)
{
std::basic_stringstream<CharType> tss;
if( !(tss << std::fixed << rVal))
{
return std::basic_string<CharType>();
}
return tss.str();
}
template<typename T_>
bool convertTo(vfs::String const& sStr, T_ &rVal)
{
std::wstringstream ss;
ss.str(sStr.c_wcs());
if(!(ss >> rVal))
{
return false;
}
return true;
}
template<typename T_>
vfs::String toStringList(std::list<T_> const& rValList)
{
std::wstringstream ss;
typename std::list<T_>::const_iterator cit = rValList.begin();
if(cit != rValList.end())
{
ss << *cit;
cit++;
for(;cit != rValList.end(); ++cit)
{
ss << L" , " << *cit;
}
}
if(!ss)
{
return L"";
}
return ss.str();
}
template<>
VFS_API vfs::String toStringList<vfs::String>(std::list<vfs::String> const& rValList);
////////////////////////////////////////////////////////////////////////////////////////////
// remove leading and trailing white characters;
template<typename StringType>
VFS_API StringType trimString(StringType const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
// explicit instantiations : std::string, std::wstring, vfs::String
template<>
VFS_API std::string trimString<std::string>(std::string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
template<>
VFS_API std::wstring trimString<std::wstring>(std::wstring const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
template<>
VFS_API vfs::String trimString<vfs::String>(vfs::String const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
} // namespace vfs
#endif // _TOOLS_H_
+62
View File
@@ -0,0 +1,62 @@
/*
* bfVFS : vfs_config.h
* - define basic library macros, especially the DLL interface macros
*
* Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com
*
* This file is part of the bfVFS library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VFS_CONFIG_H_
#define _VFS_CONFIG_H_
#ifdef WIN32
#ifdef _MSC_VER
# ifndef PRINT_DLL_INTERFACE_WARNING
# pragma warning ( disable : 4251 )
# endif
#endif
#endif
#if defined(_WIN32) && defined(_MSC_VER)
// VFS_STATIC overrides VFS_EXPORT
# ifdef VFS_STATIC
# define VFS_API
# endif
# ifndef VFS_STATIC
# ifdef VFS_EXPORT
# define VFS_API __declspec(dllexport)
# else
# define VFS_API __declspec(dllimport)
# endif
# endif
#else
# define VFS_API
#endif
#define VFS_VERSION_MAJOR 1
#define VFS_VERSION_MINOR 0
#define VFS_VERSION_PATCH 0
#if defined VFS_NO_LOGGING
# define LOG_INFO(x)
# define LOG_WARNING(y)
# define LOG_ERROR(z)
#endif
#endif // _VFS_CONFIG_H_