浏览代码

refactoring file:: api
use std::string by default

dmuratshin 9 年之前
父节点
当前提交
6964d2dc32

+ 19 - 19
oxygine/src/core/file.cpp

@@ -100,7 +100,7 @@ namespace oxygine
             _nfs.unmount(fs);
         }
 
-        handle open(const char* file_, const char* mode, error_policy ep)
+        handle open(const std::string& file_, const char* mode, error_policy ep)
         {
 
 #ifdef OX_DEBUG
@@ -110,7 +110,7 @@ namespace oxygine
             //OX_ASSERT(_openedFiles == 0);
             LOGD("open file: %s %s %d", file_, mode, _openedFiles);
             char file[512];
-            path::normalize(file_, file);
+            path::normalize(file_.c_str(), file);
             LOGD("q1");
 
 
@@ -146,23 +146,23 @@ namespace oxygine
             return fh->tell();
         }
 
-        bool deleteFile(const char* path, error_policy ep)
+        bool deleteFile(const std::string& path, error_policy ep)
         {
-            bool ok = _nfs.deleteFile(path) == FileSystem::status_ok;
+            bool ok = _nfs.deleteFile(path.c_str()) == FileSystem::status_ok;
             if (!ok)
             {
-                handleErrorPolicy(ep, "can't delete file: %s", path);
+                handleErrorPolicy(ep, "can't delete file: %s", path.c_str());
             }
 
             return ok;
         }
 
-        bool rename(const char* src, const char* dest, error_policy ep)
+        bool rename(const std::string& src, const std::string& dest, error_policy ep)
         {
-            bool ok = _nfs.renameFile(src, dest) == FileSystem::status_ok;
+            bool ok = _nfs.renameFile(src.c_str(), dest.c_str()) == FileSystem::status_ok;
             if (!ok)
             {
-                handleErrorPolicy(ep, "can't rename file: %s to %s", src, dest);
+                handleErrorPolicy(ep, "can't rename file: %s to %s", src.c_str(), dest.c_str());
             }
 
             return ok;
@@ -177,11 +177,11 @@ namespace oxygine
             return fh->read(dest, destSize);
         }
 
-        bool read(const char* file_, buffer& dest, error_policy ep)
+        bool read(const std::string& file_, buffer& dest, error_policy ep)
         {
-            LOGD("open file: %s %s %d", file_, mode, _openedFiles);
+            LOGD("open file: %s %s %d", file_.c_str(), mode, _openedFiles);
             char file[512];
-            path::normalize(file_, file);
+            path::normalize(file_.c_str(), file);
 
             dest.data.clear();
             bool ok = _nfs.read(file, dest, ep) == FileSystem::status_ok;
@@ -212,12 +212,12 @@ namespace oxygine
             fh->write(data, size);
         }
 
-        void write(const char* file, const buffer& data, error_policy ep)
+        void write(const std::string& file, const buffer& data, error_policy ep)
         {
             write(file, data.getData(), data.getSize(), ep);
         }
 
-        void write(const char* file, const void* data, unsigned int size, error_policy ep)
+        void write(const std::string& file, const void* data, unsigned int size, error_policy ep)
         {
             autoClose ac(open(file, "wb", ep));
             if (!ac.getHandle())
@@ -232,22 +232,22 @@ namespace oxygine
         }
 
 
-        bool exists(const char* file_)
+        bool exists(const std::string& file_)
         {
             char file[512];
-            path::normalize(file_, file);
+            path::normalize(file_.c_str(), file);
 
             return _nfs.isExists(file);
         }
 
-        bool makeDirectory(const char* path)
+        bool makeDirectory(const std::string& path)
         {
-            return _nfs.makeDirectory(path) == FileSystem::status_ok;
+            return _nfs.makeDirectory(path.c_str()) == FileSystem::status_ok;
         }
 
-        void deleteDirectory(const char* path)
+        void deleteDirectory(const std::string& path)
         {
-            _nfs.deleteDirectory(path);
+            _nfs.deleteDirectory(path.c_str());
         }
 
         file::STDFileSystem& fs()

+ 10 - 9
oxygine/src/core/file.h

@@ -3,6 +3,7 @@
 #include <vector>
 #include "Object.h"
 #include "FileSystem.h"
+#include <string>
 
 namespace oxygine
 {
@@ -50,7 +51,7 @@ namespace oxygine
         };
 
         /**Opens file for binary reading (mode = "rb") or binary writing (mode = "wb"). If file is missing returns zero.*/
-        handle open(const char* file, const char* mode, error_policy ep = ep_show_error);
+        handle open(const std::string& file, const char* mode, error_policy ep = ep_show_error);
 
         /**Closes opened file handle*/
         void close(handle);
@@ -62,7 +63,7 @@ namespace oxygine
         unsigned int read(handle, void* dest, unsigned int size);
 
         /**Reads bytes into destination buffer with stdio flags = "rb". Clears existing buffer*/
-        bool read(const char* file, buffer& dest, error_policy ep = ep_show_error);
+        bool read(const std::string& file, buffer& dest, error_policy ep = ep_show_error);
 
         /**Reads bytes into destination buffer with stdio flags = "wb"*/
         unsigned int read(handle, buffer& dest);
@@ -71,26 +72,26 @@ namespace oxygine
         void write(handle, const void* data, unsigned int size);
 
         /**Writes bytes to file*/
-        void write(const char* file, const buffer& data, error_policy ep = ep_show_error);
-        void write(const char* file, const void* data, unsigned int size, error_policy ep = ep_show_error);
+        void write(const std::string& file, const buffer& data, error_policy ep = ep_show_error);
+        void write(const std::string& file, const void* data, unsigned int size, error_policy ep = ep_show_error);
 
         /**Is file exists?*/
-        bool exists(const char* file);
+        bool exists(const std::string& file);
 
         /**returns opened file size*/
         unsigned int size(handle);
 
         /**Deletes file*/
-        bool deleteFile(const char* path, error_policy ep = ep_show_warning);
+        bool deleteFile(const std::string& path, error_policy ep = ep_show_warning);
 
         /**Renames file*/
-        bool rename(const char* src, const char* dest, error_policy ep = ep_show_warning);
+        bool rename(const std::string& src, const std::string& dest, error_policy ep = ep_show_warning);
 
         /**Makes directory. Not recursive*/
-        bool makeDirectory(const char* path);
+        bool makeDirectory(const std::string& path);
 
         /**Deletes empty directory*/
-        void deleteDirectory(const char* path);
+        void deleteDirectory(const std::string& path);
 
         /**Returns primary read only FileSystem*/
         file::STDFileSystem& fs();

+ 1 - 1
oxygine/src/res/ResAnim.cpp

@@ -55,7 +55,7 @@ namespace oxygine
     void ResAnim::init(const std::string& file, int columns, int rows, float scaleFactor)
     {
         file::buffer bf;
-        file::read(file.c_str(), bf);
+        file::read(file, bf);
         MemoryTexture mt;
         mt.init(bf, true);
         init(&mt, columns, rows, scaleFactor);

+ 1 - 1
oxygine/src/res/ResAtlas.cpp

@@ -28,7 +28,7 @@ namespace oxygine
 
         LOGD("loading atlas: %s", file.c_str());
         file::buffer bf;
-        file::read(file.c_str(), bf);
+        file::read(file, bf);
         LOGD("atlas file loaded: %s", file.c_str());
         mt->init(bf, true, nt->getFormat());
         im = mt->lock();

+ 1 - 1
oxygine/src/res/ResAtlasGeneric.cpp

@@ -289,7 +289,7 @@ namespace oxygine
 
 
             file::buffer bf;
-            file::read(walker.getPath("file").c_str(), bf);
+            file::read(walker.getPath("file"), bf);
 
             mt.init(bf, true, tf);
             im = mt.lock();

+ 1 - 1
oxygine/src/res/ResBuffer.cpp

@@ -37,7 +37,7 @@ namespace oxygine
 
     void ResBuffer::_load(LoadResourcesContext*)
     {
-        file::read(_path.c_str(), _buffer);
+        file::read(_path, _buffer);
     }
 
     void ResBuffer::_unload()

+ 2 - 2
oxygine/src/res/ResFontBM.cpp

@@ -121,7 +121,7 @@ namespace oxygine
         spMemoryTexture mt = new MemoryTexture;
 
         file::buffer bf;
-        file::read(p.file.c_str(), bf);
+        file::read(p.file, bf);
 
         mt->init(bf, !_premultipliedAlpha, _format);
         CreateTextureTask opt;
@@ -460,7 +460,7 @@ namespace oxygine
 
         std::string path = _file;
         file::buffer fb;
-        file::read(path.c_str(), fb);
+        file::read(path, fb);
 
         if (fb.empty())
             return;

+ 3 - 3
oxygine/src/res/ResStarlingAtlas.cpp

@@ -25,7 +25,7 @@ namespace oxygine
         std::string xml_path = context.walker.getPath("file");
 
         file::buffer fb;
-        file::read(xml_path.c_str(), fb);
+        file::read(xml_path, fb);
 
         pugi::xml_document doc;
         doc.load_buffer_inplace(&fb.data[0], fb.data.size());
@@ -56,7 +56,7 @@ namespace oxygine
             unsigned char buff[64];
             unsigned int size = 0;
             {
-                file::autoClose ac(file::open(_imagePath.c_str(), "rb"));
+                file::autoClose ac(file::open(_imagePath, "rb"));
                 size = file::read(ac.getHandle(), buff, sizeof(buff));
             }
 
@@ -74,7 +74,7 @@ namespace oxygine
 
                 ImageData im;
                 file::buffer bf;
-                file::read(_imagePath.c_str(), bf);
+                file::read(_imagePath, bf);
 
                 mt->init(bf, true, _texture->getFormat());
                 im = mt->lock();

+ 1 - 1
oxygine/src/res/Resources.cpp

@@ -175,7 +175,7 @@ namespace oxygine
 
         FS_LOG("step0");
         file::buffer fb;
-        file::read(xmlFile.c_str(), fb);
+        file::read(xmlFile, fb);
 
         FS_LOG("step1");