libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CanvasXML.hpp
Go to the documentation of this file.
1 #ifndef CANVASXML_HPP
2 #define CANVASXML_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "Canvas.hpp"
23 #include "rapidxml/rapidxml_print.hpp"
24 #include "rapidxml/rapidxml_utils.hpp"
25 #include "rapidxml_algaudio.hpp"
26 
27 namespace AlgAudio{
28 
29 namespace Exceptions{
30 struct XMLFileAccess : public Exception{
31  XMLFileAccess(std::string t) : Exception(t) {}
32 };
33 struct XMLParse : public Exception{
34  XMLParse(std::string t) : Exception(t) {}
35 };
36 } // namespace Exceptions
37 
49 class CanvasXML : public std::enable_shared_from_this<CanvasXML>{
50 public:
54  static std::shared_ptr<CanvasXML> CreateFromFile(std::string path);
57  static std::shared_ptr<CanvasXML> CreateFromString(std::string string);
60  static std::shared_ptr<CanvasXML> CreateFromNode(rapidxml::xml_node<>* node);
64  static std::shared_ptr<CanvasXML> CreateFromCanvas(std::shared_ptr<Canvas> canvas);
65 
68  void SaveToFile(std::string path);
70  std::string GetXMLAsString();
71 
78  void CloneToAnotherXMLTree(rapidxml::xml_node<>* node, rapidxml::xml_document<>* doc){
79  rapidxml::clone_node_copying(root, node, doc);
80  }
81 
88  LateReturn<std::shared_ptr<Canvas>> ApplyToCanvas(std::shared_ptr<Canvas> c);
89 
94  LateReturn<std::shared_ptr<Canvas>> CreateNewCanvas(std::shared_ptr<Canvas> parent);
95 
96  ~CanvasXML();
97 private:
98  CanvasXML();
99  std::string doc_text;
100  char* input_buffer = nullptr;
101  rapidxml::xml_document<> doc;
102  rapidxml::xml_node<>* root;
103 
104  // Used temporarily when creating a document from canvas.
105  std::map<std::shared_ptr<Module>, int> modules_to_saveids;
106  int saveid_counter = 0;
107  // Used temporarily when creating a canvas from document.
108  std::map<int, std::shared_ptr<Module>> saveids_to_modules;
109 
110  // Adds data to the xml document.
111  void AppendModule(std::shared_ptr<Module>);
112  void AppendAudioConnection(Canvas::IOID from, Canvas::IOID to);
113  void AppendDataConnection(Canvas::IOID from, Canvas::IOIDWithMode to);
114 
116  LateReturn<> AddModuleFromNode(std::shared_ptr<Canvas> c, rapidxml::xml_node<>* module_node);
117 
119  void UpdateStringFromDoc();
122  bool block_string_updates = false;
123 };
124 
125 } // namespace AlgAudio
126 
127 #endif // CANVASXML_HPP
XMLFileAccess(std::string t)
Definition: CanvasXML.hpp:31
LateReturn< std::shared_ptr< Canvas > > CreateNewCanvas(std::shared_ptr< Canvas > parent)
LateReturn< std::shared_ptr< Canvas > > ApplyToCanvas(std::shared_ptr< Canvas > c)
void clone_node_copying(const xml_node< Ch > *source, xml_node< Ch > *dest, xml_document<> *target_doc)
Definition: rapidxml_algaudio.hpp:30
static std::shared_ptr< CanvasXML > CreateFromNode(rapidxml::xml_node<> *node)
static std::shared_ptr< CanvasXML > CreateFromFile(std::string path)
Definition: CanvasXML.hpp:30
static std::shared_ptr< CanvasXML > CreateFromCanvas(std::shared_ptr< Canvas > canvas)
void SaveToFile(std::string path)
XMLParse(std::string t)
Definition: CanvasXML.hpp:34
Definition: CanvasXML.hpp:33
Definition: Module.hpp:37
static std::shared_ptr< CanvasXML > CreateFromString(std::string string)
Definition: Canvas.hpp:85
void CloneToAnotherXMLTree(rapidxml::xml_node<> *node, rapidxml::xml_document<> *doc)
Definition: CanvasXML.hpp:78
std::string GetXMLAsString()
Definition: Alertable.hpp:26
Definition: Canvas.hpp:149
Definition: CanvasXML.hpp:49
Definition: LateReturn.hpp:35
Definition: Exception.hpp:29