From c7767c6c6401aba8bdae6738e2690eff3d78077b Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 5 Feb 2013 02:08:45 +0000 Subject: [PATCH] sys: create an empty File class. --- src/Makefile.am | 4 ++-- src/lol/sys/file.h | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/lol/sys/init.h | 4 ++-- src/lol/sys/sys.h | 1 + src/lolcore.vcxproj | 2 ++ src/sys/file.cpp | 27 +++++++++++++++++++++++ src/sys/init.cpp | 9 ++++---- 7 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 src/lol/sys/file.h create mode 100644 src/sys/file.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 35e08e0a..d178b96c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,7 +42,7 @@ liblol_headers = \ lol/math/remez.h lol/math/math.h lol/math/geometry.h \ \ lol/sys/sys.h \ - lol/sys/init.h lol/sys/thread.h lol/sys/timer.h \ + lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/timer.h \ \ lol/image/image.h \ lol/image/color.h \ @@ -90,7 +90,7 @@ liblol_sources = \ \ mesh/mesh.cpp mesh/mesh.h \ \ - sys/init.cpp sys/timer.cpp \ + sys/init.cpp sys/timer.cpp sys/file.cpp \ sys/threadbase.h \ \ image/image.cpp image/image.h image/image-private.h \ diff --git a/src/lol/sys/file.h b/src/lol/sys/file.h new file mode 100644 index 00000000..d572beb0 --- /dev/null +++ b/src/lol/sys/file.h @@ -0,0 +1,54 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2013 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://www.wtfpl.net/ for more details. +// + +// +// File and buffer reading +// ----------------------- +// + +#if !defined __LOL_SYS_FILE_H__ +#define __LOL_SYS_FILE_H__ + +#include + +namespace lol +{ + +struct FileAccess +{ + enum Value + { + Read = 0, + Write, + } + m_value; + + inline FileAccess(Value v) : m_value(v) {} + inline operator Value() { return m_value; } +}; + +class File +{ +public: + inline File() : m_data(0) {} + inline ~File() {} + + void Open(String const &file, FileAccess mode); + String const &ReadString(); + void Close(); + +private: + class FileData *m_data; +}; + +} /* namespace lol */ + +#endif // __LOL_SYS_FILE_H__ + diff --git a/src/lol/sys/init.h b/src/lol/sys/init.h index b6a83448..27ff4314 100644 --- a/src/lol/sys/init.h +++ b/src/lol/sys/init.h @@ -46,8 +46,8 @@ extern void Init(int argc, char *argv[], String const &projectdir = LOL_CONFIG_PROJECTDIR, String const &solutiondir = LOL_CONFIG_SOLUTIONDIR); -extern void SetDataDir(char const *dir); -extern char const *GetDataDir(); +extern void SetDataDir(String const &dir); +extern String const &GetDataDir(); } /* namespace System */ diff --git a/src/lol/sys/sys.h b/src/lol/sys/sys.h index 95444a06..32755422 100644 --- a/src/lol/sys/sys.h +++ b/src/lol/sys/sys.h @@ -12,6 +12,7 @@ #define __LOL_SYS_SYS_H__ #include +#include #include #include diff --git a/src/lolcore.vcxproj b/src/lolcore.vcxproj index 8640883d..b50fd910 100644 --- a/src/lolcore.vcxproj +++ b/src/lolcore.vcxproj @@ -294,6 +294,7 @@ + @@ -605,6 +606,7 @@ + diff --git a/src/sys/file.cpp b/src/sys/file.cpp new file mode 100644 index 00000000..2fc0ffc7 --- /dev/null +++ b/src/sys/file.cpp @@ -0,0 +1,27 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2013 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" + +namespace lol +{ + +class FileData +{ + friend class File; + +}; + +} /* namespace lol */ + diff --git a/src/sys/init.cpp b/src/sys/init.cpp index 53e99baf..56330a6f 100644 --- a/src/sys/init.cpp +++ b/src/sys/init.cpp @@ -92,7 +92,7 @@ void Init(int argc, char *argv[], } Log::Debug("binary dir: %s\n", &binarydir[0]); - Log::Debug("root dir: %s\n", GetDataDir()); + Log::Debug("root dir: %s\n", &GetDataDir()[0]); } /* @@ -101,17 +101,16 @@ void Init(int argc, char *argv[], String data_dir = ""; -void SetDataDir(char const *dir) +void SetDataDir(String const &dir) { data_dir = dir; } -char const *GetDataDir() +String const &GetDataDir() { - return &data_dir[0]; + return data_dir; } - } /* namespace System */ } /* namespace lol */