Audacity 3.2.0
XMLTagHandler.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 XMLTagHandler.h
6
7 Dominic Mazzoni
8 Vaughan Johnson
9 Dmitry Vedenko
10
11 The XMLTagHandler class is an interface which should be implemented by
12 classes which wish to be able to load and save themselves
13 using XML files.
14
15 The XMLValueChecker class implements static bool methods for checking
16 input values from XML files.
17
18**********************************************************************/
19#ifndef __AUDACITY_XML_TAG_HANDLER__
20#define __AUDACITY_XML_TAG_HANDLER__
21
22#include <string_view>
23#include <vector>
24
25#include "XMLWriter.h"
27
28
29class XML_API XMLValueChecker
30{
31public:
32 static bool IsGoodFileName(const FilePath & strFileName, const FilePath & strDirName = {});
33 static bool IsGoodFileString(const FilePath &str);
34 static bool IsGoodSubdirName(const FilePath & strSubdirName, const FilePath & strDirName = {});
35 static bool IsGoodPathName(const FilePath & strPathName);
36 static bool IsGoodPathString(const FilePath &str);
37};
38
39using Attribute = std::pair<std::string_view, XMLAttributeValueView>;
40using AttributesList = std::vector<Attribute>;
41
42class XML_API XMLTagHandler /* not final */ {
43 public:
45 virtual ~XMLTagHandler(){};
46 //
47 // Methods to override
48 //
49
50 // This method will be called on your class if your class has
51 // been registered to handle this particular tag. Parse the
52 // tag and the attribute-value pairs (null-terminated), and
53 // return true on success, and false on failure. If you return
54 // false, you will not get any calls about children.
55 virtual bool HandleXMLTag(const std::string_view& tag, const AttributesList& attrs) = 0;
56
57 // This method will be called when a closing tag is encountered.
58 // It is optional to override this method.
59 virtual void HandleXMLEndTag(const std::string_view& WXUNUSED(tag)) {}
60
61 // This method will be called when element content has been
62 // encountered.
63 // It is optional to override this method.
64 virtual void HandleXMLContent(const std::string_view& WXUNUSED(content)) {}
65
66 // If the XML document has children of your tag, this method
67 // should be called. Typically you should construct a NEW
68 // object for the child, insert it into your own local data
69 // structures, and then return it. If you do not wish to
70 // handle this child, return NULL and it will be ignored.
71 virtual XMLTagHandler *HandleXMLChild(const std::string_view& tag) = 0;
72
73 // These functions receive data from expat. They do charset
74 // conversion and then pass the data to the handlers above.
75 void ReadXMLEndTag(const char *tag);
76 void ReadXMLContent(const char *s, int len);
77 XMLTagHandler *ReadXMLChild(const char *tag);
78};
79
80#endif // define __AUDACITY_XML_TAG_HANDLER__
81
#define str(a)
wxString FilePath
Definition: Project.h:20
std::pair< std::string_view, XMLAttributeValueView > Attribute
Definition: XMLTagHandler.h:39
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
virtual XMLTagHandler * HandleXMLChild(const std::string_view &tag)=0
virtual void HandleXMLEndTag(const std::string_view &WXUNUSED(tag))
Definition: XMLTagHandler.h:59
virtual ~XMLTagHandler()
Definition: XMLTagHandler.h:45
virtual bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs)=0
virtual void HandleXMLContent(const std::string_view &WXUNUSED(content))
Definition: XMLTagHandler.h:64
XMLValueChecker implements static bool methods for checking input values from XML files.
Definition: XMLTagHandler.h:30