zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
File_Ops.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_FILE_OPS_H
19 #define ZENI_FILE_OPS_H
20 
21 #include <Zeni/Error.h>
22 #include <Zeni/Singleton.h>
23 
24 #if defined(ANDROID)
25 #include <sys/types.h>
26 #include <android/asset_manager.h>
27 #include <android/asset_manager_jni.h>
28 #endif
29 
30 namespace Zeni {
31 
32  class ZENI_DLL File_Ops;
33 
34 #ifdef _WINDOWS
35  ZENI_EXT template class ZENI_DLL Singleton<File_Ops>;
36 #endif
37 
38  class ZENI_DLL File_Ops : public Singleton<File_Ops> {
39  friend class Singleton<File_Ops>;
40 
41  static File_Ops * create();
42 
43  File_Ops();
44  ~File_Ops();
45 
46  // Undefined
47  File_Ops(const File_Ops &);
48  File_Ops & operator=(const File_Ops &);
49 
50  public:
51 #ifdef ANDROID
52  static void init_AAssetManager(AAssetManager * const &asset_manager);
53  static AAssetManager * const get_AAssetManager();
54 #endif
55  static FILE * get_asset_FILE(const String &filename, off_t * const &start = 0, off_t * const &length = 0);
56  static String & load_asset(String &memory, const String &filename);
57  static const String & get_uniqname();
58  const String & get_username();
59  String get_appdata_path();
60 
61  static bool create_directory(const String &directory_path);
62  static bool remove_directory(const String &directory_path);
63 
64  static bool file_exists(const String &file_path);
65  static bool delete_file(const String &file_path);
66  static bool copy_file(const String &from, const String &to);
67 
68  // Can be called once only, and only before File_Ops is initialized; May throw File_Ops_Initialized
69  static void preinit(const String &unique_app_identifier);
70 
71  private:
72  static String & get_unique_app_identifier();
73 
74 #ifdef ANDROID
75  static AAssetManager * m_asset_manager;
76 #endif
77 
78  String m_username;
79  String m_appdata_path;
80  };
81 
82  ZENI_DLL File_Ops & get_File_Ops();
83 
84  struct ZENI_DLL File_Ops_Init_Failure : public Error {
85  File_Ops_Init_Failure() : Error("Zeni File_Ops Failed to Initialize Correctly") {}
86  };
87 
88 #ifdef ANDROID
89  struct ZENI_DLL File_Ops_No_AAssetManager : public Error {
90  File_Ops_No_AAssetManager() : Error("Zeni File_Ops No AAssetManager") {}
91  };
92 #endif
93 
94  struct ZENI_DLL File_Ops_Asset_Load_Failure : public Error {
95  File_Ops_Asset_Load_Failure() : Error("Zeni File_Ops Failed to Load Asset") {}
96  };
97 
98  struct ZENI_DLL File_Ops_Initialized : public Error {
99  File_Ops_Initialized() : Error("Zeni File_Ops Already Initialized") {}
100  };
101 
102 }
103 
104 #endif
GLuint start
Definition: glew.h:1239
GLsizei GLsizei * length
Definition: gl2ext.h:792
The Error Class.
Definition: Error.h:52
def file_exists
Definition: utils.py:93
File_Ops & get_File_Ops()
Get access to the singleton.
Definition: File_Ops.cpp:118