resource_format_xml.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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-2015 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. #include "io/resource_loader.h"
  32. #include "io/resource_saver.h"
  33. #include "os/file_access.h"
  34. class ResourceInteractiveLoaderXML : public ResourceInteractiveLoader {
  35. String local_path;
  36. String res_path;
  37. FileAccess *f;
  38. struct Tag {
  39. String name;
  40. HashMap<String,String> args;
  41. };
  42. _FORCE_INLINE_ Error _parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end);
  43. List<StringName> ext_resources;
  44. int resources_total;
  45. int resource_current;
  46. String resource_type;
  47. mutable int lines;
  48. uint8_t get_char() const;
  49. int get_current_line() const;
  50. friend class ResourceFormatLoaderXML;
  51. List<Tag> tag_stack;
  52. List<RES> resource_cache;
  53. Tag* parse_tag(bool* r_exit=NULL,bool p_printerr=true);
  54. Error close_tag(const String& p_name);
  55. _FORCE_INLINE_ void unquote(String& p_str);
  56. Error goto_end_of_tag();
  57. Error parse_property_data(String &r_data);
  58. Error parse_property(Variant& r_v, String &r_name);
  59. Error error;
  60. RES resource;
  61. public:
  62. virtual void set_local_path(const String& p_local_path);
  63. virtual Ref<Resource> get_resource();
  64. virtual Error poll();
  65. virtual int get_stage() const;
  66. virtual int get_stage_count() const;
  67. void open(FileAccess *p_f);
  68. String recognize(FileAccess *p_f);
  69. void get_dependencies(FileAccess *p_f,List<String> *p_dependencies);
  70. ~ResourceInteractiveLoaderXML();
  71. };
  72. class ResourceFormatLoaderXML : public ResourceFormatLoader {
  73. public:
  74. virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path);
  75. virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
  76. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  77. virtual bool handles_type(const String& p_type) const;
  78. virtual String get_resource_type(const String &p_path) const;
  79. virtual void get_dependencies(const String& p_path,List<String> *p_dependencies);
  80. };
  81. ////////////////////////////////////////////////////////////////////////////////////////////
  82. class ResourceFormatSaverXMLInstance {
  83. String local_path;
  84. bool takeover_paths;
  85. bool relative_paths;
  86. bool bundle_resources;
  87. bool skip_editor;
  88. FileAccess *f;
  89. int depth;
  90. Map<RES,int> resource_map;
  91. List<RES> saved_resources;
  92. List<RES> external_resources;
  93. void enter_tag(const char* p_tag,const String& p_args=String());
  94. void exit_tag(const char* p_tag);
  95. void _find_resources(const Variant& p_variant,bool p_main=false);
  96. void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL);
  97. void escape(String& p_str);
  98. void write_tabs(int p_diff=0);
  99. void write_string(String p_str,bool p_escape=true);
  100. public:
  101. Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
  102. };
  103. class ResourceFormatSaverXML : public ResourceFormatSaver {
  104. public:
  105. virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
  106. virtual bool recognize(const RES& p_resource) const;
  107. virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
  108. };
  109. #endif // RESOURCE_FORMAT_XML_H