openshot-audio  0.1.7
juce_XmlElement.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_XMLELEMENT_H_INCLUDED
30 #define JUCE_XMLELEMENT_H_INCLUDED
31 
32 
33 //==============================================================================
52 #define forEachXmlChildElement(parentXmlElement, childElementVariableName) \
53 \
54  for (juce::XmlElement* childElementVariableName = (parentXmlElement).getFirstChildElement(); \
55  childElementVariableName != nullptr; \
56  childElementVariableName = childElementVariableName->getNextElement())
57 
81 #define forEachXmlChildElementWithTagName(parentXmlElement, childElementVariableName, requiredTagName) \
82 \
83  for (juce::XmlElement* childElementVariableName = (parentXmlElement).getChildByName (requiredTagName); \
84  childElementVariableName != nullptr; \
85  childElementVariableName = childElementVariableName->getNextElementWithTagName (requiredTagName))
86 
87 
88 //==============================================================================
143 {
144 public:
145  //==============================================================================
147  explicit XmlElement (const String& tagName);
148 
150  explicit XmlElement (const char* tagName);
151 
153  explicit XmlElement (const Identifier& tagName);
154 
156  explicit XmlElement (StringRef tagName);
157 
159  XmlElement (String::CharPointerType tagNameBegin, String::CharPointerType tagNameEnd);
160 
162  XmlElement (const XmlElement&);
163 
165  XmlElement& operator= (const XmlElement&);
166 
167  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
169  XmlElement& operator= (XmlElement&&) noexcept;
170  #endif
171 
173  ~XmlElement() noexcept;
174 
175  //==============================================================================
187  bool isEquivalentTo (const XmlElement* other,
188  bool ignoreOrderOfAttributes) const noexcept;
189 
190  //==============================================================================
208  String createDocument (StringRef dtdToUse,
209  bool allOnOneLine = false,
210  bool includeXmlHeader = true,
211  StringRef encodingType = "UTF-8",
212  int lineWrapLength = 60) const;
213 
229  void writeToStream (OutputStream& output,
230  StringRef dtdToUse,
231  bool allOnOneLine = false,
232  bool includeXmlHeader = true,
233  StringRef encodingType = "UTF-8",
234  int lineWrapLength = 60) const;
235 
255  bool writeToFile (const File& destinationFile,
256  StringRef dtdToUse,
257  StringRef encodingType = "UTF-8",
258  int lineWrapLength = 60) const;
259 
260  //==============================================================================
265  const String& getTagName() const noexcept { return tagName; }
266 
268  String getNamespace() const;
269 
271  String getTagNameWithoutNamespace() const;
272 
277  bool hasTagName (StringRef possibleTagName) const noexcept;
278 
283  bool hasTagNameIgnoringNamespace (StringRef possibleTagName) const;
284 
285  //==============================================================================
291  int getNumAttributes() const noexcept;
292 
300  const String& getAttributeName (int attributeIndex) const noexcept;
301 
309  const String& getAttributeValue (int attributeIndex) const noexcept;
310 
311  //==============================================================================
312  // Attribute-handling methods..
313 
315  bool hasAttribute (StringRef attributeName) const noexcept;
316 
320  const String& getStringAttribute (StringRef attributeName) const noexcept;
321 
327  String getStringAttribute (StringRef attributeName, const String& defaultReturnValue) const;
328 
337  bool compareAttribute (StringRef attributeName,
338  StringRef stringToCompareAgainst,
339  bool ignoreCase = false) const noexcept;
340 
351  int getIntAttribute (StringRef attributeName, int defaultReturnValue = 0) const;
352 
363  double getDoubleAttribute (StringRef attributeName, double defaultReturnValue = 0.0) const;
364 
375  bool getBoolAttribute (StringRef attributeName, bool defaultReturnValue = false) const;
376 
390  void setAttribute (const Identifier& attributeName, const String& newValue);
391 
404  void setAttribute (const Identifier& attributeName, int newValue);
405 
418  void setAttribute (const Identifier& attributeName, double newValue);
419 
425  void removeAttribute (const Identifier& attributeName) noexcept;
426 
428  void removeAllAttributes() noexcept;
429 
430  //==============================================================================
431  // Child element methods..
432 
437  XmlElement* getFirstChildElement() const noexcept { return firstChildElement; }
438 
465  inline XmlElement* getNextElement() const noexcept { return nextListItem; }
466 
475  XmlElement* getNextElementWithTagName (StringRef requiredTagName) const;
476 
480  int getNumChildElements() const noexcept;
481 
490  XmlElement* getChildElement (int index) const noexcept;
491 
498  XmlElement* getChildByName (StringRef tagNameToLookFor) const noexcept;
499 
507  XmlElement* getChildByAttribute (StringRef attributeName,
508  StringRef attributeValue) const noexcept;
509 
510  //==============================================================================
524  void addChildElement (XmlElement* newChildElement) noexcept;
525 
537  void insertChildElement (XmlElement* newChildElement,
538  int indexToInsertAt) noexcept;
539 
552  void prependChildElement (XmlElement* newChildElement) noexcept;
553 
568  XmlElement* createNewChildElement (StringRef tagName);
569 
577  bool replaceChildElement (XmlElement* currentChildElement,
578  XmlElement* newChildNode) noexcept;
579 
586  void removeChildElement (XmlElement* childToRemove,
587  bool shouldDeleteTheChild) noexcept;
588 
592  void deleteAllChildElements() noexcept;
593 
597  void deleteAllChildElementsWithTagName (StringRef tagName) noexcept;
598 
600  bool containsChildElement (const XmlElement* possibleChild) const noexcept;
601 
612  XmlElement* findParentElementOf (const XmlElement* childToSearchFor) noexcept;
613 
614  //==============================================================================
637  template <class ElementComparator>
638  void sortChildElements (ElementComparator& comparator,
639  bool retainOrderOfEquivalentItems = false)
640  {
641  const int num = getNumChildElements();
642 
643  if (num > 1)
644  {
645  HeapBlock <XmlElement*> elems ((size_t) num);
646  getChildElementsAsArray (elems);
647  sortArray (comparator, (XmlElement**) elems, 0, num - 1, retainOrderOfEquivalentItems);
648  reorderChildElements (elems, num);
649  }
650  }
651 
652  //==============================================================================
660  bool isTextElement() const noexcept;
661 
678  const String& getText() const noexcept;
679 
686  void setText (const String& newText);
687 
701  String getAllSubText() const;
702 
711  String getChildElementAllSubText (StringRef childTagName,
712  const String& defaultReturnValue) const;
713 
717  void addTextElement (const String& text);
718 
722  void deleteAllTextElements() noexcept;
723 
725  static XmlElement* createTextElement (const String& text);
726 
727  //==============================================================================
728 private:
729  struct XmlAttributeNode
730  {
731  XmlAttributeNode (const XmlAttributeNode&) noexcept;
732  XmlAttributeNode (const Identifier&, const String&) noexcept;
733  XmlAttributeNode (String::CharPointerType, String::CharPointerType);
734 
735  LinkedListPointer<XmlAttributeNode> nextListItem;
736  Identifier name;
737  String value;
738 
739  private:
740  XmlAttributeNode& operator= (const XmlAttributeNode&) JUCE_DELETED_FUNCTION;
741  };
742 
743  friend class XmlDocument;
744  friend class LinkedListPointer<XmlAttributeNode>;
746  friend class LinkedListPointer<XmlElement>::Appender;
747  friend class NamedValueSet;
748 
749  LinkedListPointer<XmlElement> nextListItem;
750  LinkedListPointer<XmlElement> firstChildElement;
751  LinkedListPointer<XmlAttributeNode> attributes;
752  String tagName;
753 
754  XmlElement (int) noexcept;
755  void copyChildrenAndAttributesFrom (const XmlElement&);
756  void writeElementAsText (OutputStream&, int indentationLevel, int lineWrapLength) const;
757  void getChildElementsAsArray (XmlElement**) const noexcept;
758  void reorderChildElements (XmlElement**, int) noexcept;
759  XmlAttributeNode* getAttribute (StringRef) const noexcept;
760 
761  // Sigh.. L"" or _T("") string literals are problematic in general, and really inappropriate
762  // for XML tags. Use a UTF-8 encoded literal instead, or if you're really determined to use
763  // UTF-16, cast it to a String and use the other constructor.
764  XmlElement (const wchar_t*) JUCE_DELETED_FUNCTION;
765 
766  JUCE_LEAK_DETECTOR (XmlElement)
767 };
768 
769 
770 #endif // JUCE_XMLELEMENT_H_INCLUDED
#define noexcept
Definition: juce_CompilerSupport.h:141
#define false
Definition: ordinals.h:83
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
#define const
Definition: juce_LinkedListPointer.h:61
Definition: juce_XmlElement.h:142
Definition: juce_NamedValueSet.h:39
XmlElement * getNextElement() const noexcept
Definition: juce_XmlElement.h:465
#define JUCE_DELETED_FUNCTION
Definition: juce_CompilerSupport.h:133
Definition: juce_OutputStream.h:42
Definition: juce_XmlDocument.h:69
const String & getTagName() const noexcept
Definition: juce_XmlElement.h:265
Definition: juce_HeapBlock.h:90
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
Definition: juce_File.h:45
Definition: juce_Identifier.h:43
Definition: juce_StringRef.h:65