- 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
+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_