hx3d  1
2D/3D Simple Game Framework
file.hpp
1 /*
2  File handling.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_UTILS_FILE
22 #define HX3D_UTILS_FILE
23 
24 #include <string>
25 
26 #include "hx3d/utils/ptr.hpp"
27 #include "hx3d/utils/resource.hpp"
28 
29 namespace hx3d {
30 
34 class File: public Resource {
35 
36 public:
37  File();
38  ~File();
39 
45  std::string toString();
46 
48 
56  static Ptr<File> loadAsciiFile(std::string path);
57 
65  static Ptr<File> loadBinaryFile(std::string path);
66 
73  static void writeInternalAsciiFile(std::string path, std::string content);
74 
82  static Ptr<File> loadInternalAsciiFile(std::string path);
83 
89  size_t getSize() const;
90 
96  char* getData() const;
97 
98 private:
100  char* data;
102  size_t size;
103 
104  #ifdef __ANDROID__
105 
110  static Ptr<File> loadAsciiFileAndroid(std::string path);
116  static Ptr<File> loadBinaryFileAndroid(std::string path);
122  static std::string readAsString(std::string path);
123 
124  static std::string getInternalPath();
125 
126  #elif __APPLE__
127 
128  #include "TargetConditionals.h"
129  #ifdef TARGET_OS_IPHONE
130 
136  static Ptr<File> loadAsciiFileiOS(std::string path);
137 
143  static Ptr<File> loadBinaryFileiOS(std::string path);
144 
150  static std::string readAsString(std::string path);
151  #endif
152  #endif
153 
159  static Ptr<File> loadAsciiFileDesktop(std::string path);
165  static Ptr<File> loadBinaryFileDesktop(std::string path);
166 };
167 
168 } /* hx3d */
169 
170 #endif
std::string toString()
Return the file content as a string.
Definition: file.cpp:90
char * getData() const
Get the file data as an 8-bit array.
Definition: file.cpp:42
hx3d framework namespace
Definition: audio.hpp:26
static Ptr< File > loadAsciiFile(std::string path)
Load an ascii file from a path.
Definition: file.cpp:52
File loading abstraction.
Definition: file.hpp:34
static Ptr< File > loadInternalAsciiFile(std::string path)
Load an internal ascii file.
Definition: file.cpp:72
Resource type: to use in an asset manager.
Definition: resource.hpp:29
static void writeInternalAsciiFile(std::string path, std::string content)
Write to an internal ascii file.
Definition: file.cpp:80
size_t getSize() const
Get the file size.
Definition: file.cpp:46
static Ptr< File > loadBinaryFile(std::string path)
Load a binary file from a path.
Definition: file.cpp:62
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34