LMMS
Loading...
Searching...
No Matches
XmlElement.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the Water library.
5 Copyright (c) 2016 ROLI Ltd.
6 Copyright (C) 2017-2022 Filipe Coelho <falktx@falktx.com>
7
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
10
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 OF THIS SOFTWARE.
22
23 ==============================================================================
24*/
25
26#ifndef WATER_XMLELEMENT_H_INCLUDED
27#define WATER_XMLELEMENT_H_INCLUDED
28
30#include "../memory/HeapBlock.h"
31#include "../text/Identifier.h"
32
33namespace water {
34
35//==============================================================================
54#define __forEachXmlChildElement(parentXmlElement, childElementVariableName) \
55\
56 for (water::XmlElement* childElementVariableName = (parentXmlElement).getFirstChildElement(); \
57 childElementVariableName != nullptr; \
58 childElementVariableName = childElementVariableName->getNextElement())
59
83#define __forEachXmlChildElementWithTagName(parentXmlElement, childElementVariableName, requiredTagName) \
84\
85 for (water::XmlElement* childElementVariableName = (parentXmlElement).getChildByName (requiredTagName); \
86 childElementVariableName != nullptr; \
87 childElementVariableName = childElementVariableName->getNextElementWithTagName (requiredTagName))
88
89
90//==============================================================================
145{
146public:
147 //==============================================================================
149 explicit XmlElement (const String& tagName);
150
152 explicit XmlElement (const char* tagName);
153
155 explicit XmlElement (const Identifier& tagName);
156
158 explicit XmlElement (StringRef tagName);
159
161 XmlElement (CharPointer_UTF8 tagNameBegin, CharPointer_UTF8 tagNameEnd);
162
164 XmlElement (const XmlElement&);
165
168
170 ~XmlElement() noexcept;
171
172 //==============================================================================
184 bool isEquivalentTo (const XmlElement* other,
185 bool ignoreOrderOfAttributes) const noexcept;
186
187 //==============================================================================
206 bool allOnOneLine = false,
207 bool includeXmlHeader = true,
208 StringRef encodingType = "UTF-8",
209 int lineWrapLength = 60) const;
210
226 void writeToStream (OutputStream& output,
227 StringRef dtdToUse,
228 bool allOnOneLine = false,
229 bool includeXmlHeader = true,
230 StringRef encodingType = "UTF-8",
231 int lineWrapLength = 60) const;
232
233#if 0
253 bool writeToFile (const File& destinationFile,
254 StringRef dtdToUse,
255 StringRef encodingType = "UTF-8",
256 int lineWrapLength = 60) const;
257#endif
258
259 //==============================================================================
265
267 String getNamespace() const;
268
271
276 bool hasTagName (StringRef possibleTagName) const noexcept;
277
282 bool hasTagNameIgnoringNamespace (StringRef possibleTagName) const;
283
284 //==============================================================================
291
299 const std::string& getAttributeName (int attributeIndex) const noexcept;
300
308 const String& getAttributeValue (int attributeIndex) const noexcept;
309
310 //==============================================================================
311 // Attribute-handling methods..
312
314 bool hasAttribute (StringRef attributeName) const noexcept;
315
320
326 String getStringAttribute (StringRef attributeName, const String& defaultReturnValue) const;
327
336 bool compareAttribute (StringRef attributeName,
337 StringRef stringToCompareAgainst,
338 bool ignoreCase = false) const noexcept;
339
350 int getIntAttribute (StringRef attributeName, int defaultReturnValue = 0) const;
351
362 double getDoubleAttribute (StringRef attributeName, double defaultReturnValue = 0.0) const;
363
374 bool getBoolAttribute (StringRef attributeName, bool defaultReturnValue = false) const;
375
389 void setAttribute (const Identifier& attributeName, const String& newValue);
390
403 void setAttribute (const Identifier& attributeName, int newValue);
404
417 void setAttribute (const Identifier& attributeName, double newValue);
418
424 void removeAttribute (const Identifier& attributeName) noexcept;
425
428
429 //==============================================================================
430 // Child element methods..
431
437
465
474 XmlElement* getNextElementWithTagName (StringRef requiredTagName) const;
475
480
490
498
507 StringRef attributeValue) const noexcept;
508
509 //==============================================================================
523 void addChildElement (XmlElement* newChildElement) noexcept;
524
536 void insertChildElement (XmlElement* newChildElement,
537 int indexToInsertAt) noexcept;
538
551 void prependChildElement (XmlElement* newChildElement) noexcept;
552
568
576 bool replaceChildElement (XmlElement* currentChildElement,
577 XmlElement* newChildNode) noexcept;
578
585 void removeChildElement (XmlElement* childToRemove,
586 bool shouldDeleteTheChild) noexcept;
587
592
597
599 bool containsChildElement (const XmlElement* possibleChild) const noexcept;
600
612
613 //==============================================================================
622
640
647 void setText (const String& newText);
648
663
673 const String& defaultReturnValue) const;
674
679
684
687
689 static bool isValidXmlName (StringRef possibleName) noexcept;
690
691 //==============================================================================
692private:
706
707 friend class XmlDocument;
709 friend class LinkedListPointer<XmlElement>;
711 friend class NamedValueSet;
712
715 LinkedListPointer<XmlAttributeNode> attributes;
717
718 XmlElement (int) noexcept;
719 void copyChildrenAndAttributesFrom (const XmlElement&);
720 void writeElementAsText (OutputStream&, int indentationLevel, int lineWrapLength) const;
722 void reorderChildElements (XmlElement**, int) noexcept;
724};
725
726}
727
728#endif // WATER_XMLELEMENT_H_INCLUDED
#define noexcept
Definition DistrhoDefines.h:72
Definition CharPointer_UTF8.h:45
Definition File.h:50
Definition Identifier.h:44
Definition LinkedListPointer.h:62
Definition OutputStream.h:44
Definition String.h:48
Definition StringRef.h:67
Definition XmlElement.h:145
const std::string & getAttributeName(int attributeIndex) const noexcept
Definition XmlElement.cpp:457
const String & getTagName() const noexcept
Definition XmlElement.h:264
void copyChildrenAndAttributesFrom(const XmlElement &)
Definition XmlElement.cpp:136
XmlElement * getChildByName(StringRef tagNameToLookFor) const noexcept
Definition XmlElement.cpp:613
LinkedListPointer< XmlElement > nextListItem
Definition XmlElement.h:713
friend class NamedValueSet
Definition XmlElement.h:711
XmlElement * getChildElement(int index) const noexcept
Definition XmlElement.cpp:608
bool hasTagName(StringRef possibleTagName) const noexcept
Definition XmlElement.cpp:403
bool compareAttribute(StringRef attributeName, StringRef stringToCompareAgainst, bool ignoreCase=false) const noexcept
Definition XmlElement.cpp:536
XmlElement * createNewChildElement(StringRef tagName)
Definition XmlElement.cpp:668
XmlElement * getChildByAttribute(StringRef attributeName, StringRef attributeValue) const noexcept
Definition XmlElement.cpp:624
bool hasAttribute(StringRef attributeName) const noexcept
Definition XmlElement.cpp:482
void addChildElement(XmlElement *newChildElement) noexcept
Definition XmlElement.cpp:635
String createDocument(StringRef dtdToUse, bool allOnOneLine=false, bool includeXmlHeader=true, StringRef encodingType="UTF-8", int lineWrapLength=60) const
Definition XmlElement.cpp:327
void deleteAllTextElements() noexcept
Definition XmlElement.cpp:909
XmlElement * getNextElement() const noexcept
Definition XmlElement.h:464
void setText(const String &newText)
Definition XmlElement.cpp:852
bool replaceChildElement(XmlElement *currentChildElement, XmlElement *newChildNode) noexcept
Definition XmlElement.cpp:675
void prependChildElement(XmlElement *newChildElement) noexcept
Definition XmlElement.cpp:657
void deleteAllChildElementsWithTagName(StringRef tagName) noexcept
Definition XmlElement.cpp:782
int getIntAttribute(StringRef attributeName, int defaultReturnValue=0) const
Definition XmlElement.cpp:504
void writeElementAsText(OutputStream &, int indentationLevel, int lineWrapLength) const
Definition XmlElement.cpp:243
XmlElement(const String &tagName)
Definition XmlElement.cpp:83
XmlElement * getFirstChildElement() const noexcept
Definition XmlElement.h:436
double getDoubleAttribute(StringRef attributeName, double defaultReturnValue=0.0) const
Definition XmlElement.cpp:512
XmlElement * getNextElementWithTagName(StringRef requiredTagName) const
Definition XmlElement.cpp:429
LinkedListPointer< XmlElement > firstChildElement
Definition XmlElement.h:714
int getNumChildElements() const noexcept
Definition XmlElement.cpp:603
LinkedListPointer< XmlAttributeNode > attributes
Definition XmlElement.h:715
const String & getStringAttribute(StringRef attributeName) const noexcept
Definition XmlElement.cpp:488
String getAllSubText() const
Definition XmlElement.cpp:858
void removeChildElement(XmlElement *childToRemove, bool shouldDeleteTheChild) noexcept
Definition XmlElement.cpp:692
bool isTextElement() const noexcept
Definition XmlElement.cpp:836
String tagName
Definition XmlElement.h:716
bool isEquivalentTo(const XmlElement *other, bool ignoreOrderOfAttributes) const noexcept
Definition XmlElement.cpp:704
void getChildElementsAsArray(XmlElement **) const noexcept
Definition XmlElement.cpp:817
String getChildElementAllSubText(StringRef childTagName, const String &defaultReturnValue) const
Definition XmlElement.cpp:874
void removeAttribute(const Identifier &attributeName) noexcept
Definition XmlElement.cpp:583
bool hasTagNameIgnoringNamespace(StringRef possibleTagName) const
Definition XmlElement.cpp:424
void reorderChildElements(XmlElement **, int) noexcept
Definition XmlElement.cpp:822
void insertChildElement(XmlElement *newChildElement, int indexToInsertAt) noexcept
Definition XmlElement.cpp:646
friend class XmlDocument
Definition XmlElement.h:707
XmlAttributeNode * getAttribute(StringRef) const noexcept
Definition XmlElement.cpp:473
const String & getAttributeValue(int attributeIndex) const noexcept
Definition XmlElement.cpp:465
XmlElement & operator=(const XmlElement &)
Definition XmlElement.cpp:123
int getNumAttributes() const noexcept
Definition XmlElement.cpp:440
static XmlElement * createTextElement(const String &text)
Definition XmlElement.cpp:882
void addTextElement(const String &text)
Definition XmlElement.cpp:904
String getTagNameWithoutNamespace() const
Definition XmlElement.cpp:419
void writeToStream(OutputStream &output, StringRef dtdToUse, bool allOnOneLine=false, bool includeXmlHeader=true, StringRef encodingType="UTF-8", int lineWrapLength=60) const
Definition XmlElement.cpp:339
const String & getText() const noexcept
Definition XmlElement.cpp:843
static bool isValidXmlName(StringRef possibleName) noexcept
Definition XmlElement.cpp:889
friend class LinkedListPointer< XmlElement >::Appender
Definition XmlElement.h:710
~XmlElement() noexcept
Definition XmlElement.cpp:145
void setAttribute(const Identifier &attributeName, const String &newValue)
Definition XmlElement.cpp:548
bool getBoolAttribute(StringRef attributeName, bool defaultReturnValue=false) const
Definition XmlElement.cpp:520
void removeAllAttributes() noexcept
Definition XmlElement.cpp:597
String getNamespace() const
Definition XmlElement.cpp:414
bool containsChildElement(const XmlElement *possibleChild) const noexcept
Definition XmlElement.cpp:795
XmlElement * findParentElementOf(const XmlElement *childToSearchFor) noexcept
Definition XmlElement.cpp:800
void deleteAllChildElements() noexcept
Definition XmlElement.cpp:777
#define WATER_DELETED_FUNCTION
Definition juce_Uuid.h:141
Definition AudioSampleBuffer.h:33
#define false
Definition ordinals.h:83
Definition XmlElement.h:694
Identifier name
Definition XmlElement.h:700
LinkedListPointer< XmlAttributeNode > nextListItem
Definition XmlElement.h:699
XmlAttributeNode(const XmlAttributeNode &) noexcept
Definition XmlElement.cpp:64
String value
Definition XmlElement.h:701
const char * text
Definition swell-functions.h:167
#define void
Definition unzip.h:396
#define const
Definition zconf.h:137