resource_format_xml.h
1 /*************************************************************************/
2 /* resource_format_xml.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef RESOURCE_FORMAT_XML_H
30 #define RESOURCE_FORMAT_XML_H
31 
32 #include "io/resource_loader.h"
33 #include "io/resource_saver.h"
34 #include "os/file_access.h"
35 
36 
37 
39 
40  String local_path;
41  String res_path;
42 
43  FileAccess *f;
44 
45  struct Tag {
46 
47  String name;
49 
50  };
51 
52  _FORCE_INLINE_ Error _parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end);
53 
54 
55  struct ExtResource {
56  String path;
57  String type;
58  };
59 
60 
61  Map<String,String> remaps;
62 
63  Map<int,ExtResource> ext_resources;
64 
65  int resources_total;
66  int resource_current;
67  String resource_type;
68 
69  mutable int lines;
70  uint8_t get_char() const;
71  int get_current_line() const;
72 
73 friend class ResourceFormatLoaderXML;
74  List<Tag> tag_stack;
75 
76  List<RES> resource_cache;
77  Tag* parse_tag(bool* r_exit=NULL,bool p_printerr=true,List<String> *r_order=NULL);
78  Error close_tag(const String& p_name);
79  _FORCE_INLINE_ void unquote(String& p_str);
80  Error goto_end_of_tag();
81  Error parse_property_data(String &r_data);
82  Error parse_property(Variant& r_v, String &r_name);
83 
84  Error error;
85 
86  RES resource;
87 
88 public:
89 
90  virtual void set_local_path(const String& p_local_path);
91  virtual Ref<Resource> get_resource();
92  virtual Error poll();
93  virtual int get_stage() const;
94  virtual int get_stage_count() const;
95 
96  void open(FileAccess *p_f);
97  String recognize(FileAccess *p_f);
98  void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
99  Error rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map);
100 
101 
103 
104 };
105 
107 public:
108 
109  virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL);
110  virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
111  virtual void get_recognized_extensions(List<String> *p_extensions) const;
112  virtual bool handles_type(const String& p_type) const;
113  virtual String get_resource_type(const String &p_path) const;
114  virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false);
115  virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
116 
117 
118 };
119 
120 
122 
123 
125 
126  String local_path;
127 
128 
129 
130  bool takeover_paths;
131  bool relative_paths;
132  bool bundle_resources;
133  bool skip_editor;
134  FileAccess *f;
135  int depth;
136  Set<RES> resource_set;
137  List<RES> saved_resources;
138  Map<RES,int> external_resources;
139 
140  void enter_tag(const char* p_tag,const String& p_args=String());
141  void exit_tag(const char* p_tag);
142 
143  void _find_resources(const Variant& p_variant,bool p_main=false);
144  void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL);
145 
146 
147  void escape(String& p_str);
148  void write_tabs(int p_diff=0);
149  void write_string(String p_str,bool p_escape=true);
150 
151 
152 public:
153 
154  Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
155 
156 
157 };
158 
160 public:
161  static ResourceFormatSaverXML* singleton;
162  virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
163  virtual bool recognize(const RES& p_resource) const;
164  virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
165 
167 };
168 
169 
170 #endif // RESOURCE_FORMAT_XML_H
Definition: reference.h:78
Definition: resource_format_xml.h:159
Definition: variant.h:74
Definition: set.h:44
Definition: resource_format_xml.h:124
Definition: resource_loader.h:57
Definition: resource_format_xml.h:38
Definition: ustring.h:64
Definition: resource_format_xml.h:106
Definition: resource_saver.h:43
Definition: file_access.h:40
Definition: resource_loader.h:38