LibMusicXML 3.22
xml.h
1/*
2 MusicXML Library
3 Copyright (C) Grame 2006-2013
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9 Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
10 research@grame.fr
11*/
12
13#ifndef __xml__
14#define __xml__
15
16#include <string>
17#include <vector>
18
19#ifdef WIN32
20#pragma warning (disable : 4275)
21#endif
22
23#include "exports.h"
24#include "ctree.h"
25#include "smartpointer.h"
26
27namespace MusicXML2
28{
29
34
35class xmlelement;
36class xmlattribute;
37
38typedef SMARTP<xmlattribute> Sxmlattribute;
39typedef SMARTP<xmlelement> Sxmlelement;
40
46//______________________________________________________________________________
47class EXP xmlattribute : public smartable {
49 std::string fName;
51 std::string fValue;
52 protected:
53 xmlattribute() {}
54 virtual ~xmlattribute() {}
55 public:
56 static SMARTP<xmlattribute> create();
57
58 void setName (const std::string& name);
59 void setValue (const std::string& value);
60 void setValue (long value);
61 void setValue (int value);
62 void setValue (float value);
63
64 const std::string& getName () const { return fName; }
66 const std::string& getValue () const { return fValue; }
68 operator int () const;
70 operator long () const;
72 operator float () const;
73};
74
75
84//______________________________________________________________________________
85class EXP xmlelement : public ctree<xmlelement>, public visitable
86{
87 private:
89 std::string fName;
91 std::string fValue;
93 std::vector<Sxmlattribute> fAttributes;
94
95 protected:
96 // the element type
97 int fType;
98 // the input line number for messages to the user
99 int fInputLineNumber;
100
101 xmlelement (int inputLineNumber) : fType(0), fInputLineNumber(inputLineNumber) {}
102 virtual ~xmlelement() {}
103
104 public:
105 typedef ctree<xmlelement>::iterator iterator;
106
107 static SMARTP<xmlelement> create (int inputLineNumber);
108
109 virtual void acceptIn (basevisitor& visitor);
110 virtual void acceptOut (basevisitor& visitor);
111
112 int getInputLineNumber () { return fInputLineNumber; }
113
114 void setValue (unsigned long value);
115 void setValue (long value);
116 void setValue (int value);
117 void setValue (float value);
118 void setValue (const std::string& value);
119 void setName (const std::string& name);
120
121 int getType () const { return fType; }
122 const std::string& getName () const { return fName; }
123
125 const std::string& getValue () const { return fValue; }
126
128 operator long () const;
130 operator int () const;
132 operator float () const;
134 bool operator ==(const xmlelement& elt) const;
135 bool operator !=(const xmlelement& elt) const { return !(*this == elt); }
136
138 long add (const Sxmlattribute& attr);
139
140 // getting information about attributes
141 const std::vector<Sxmlattribute>& attributes() const { return fAttributes; }
142 const Sxmlattribute getAttribute (const std::string& attrname) const;
143 const std::string getAttributeValue (const std::string& attrname) const;
144 long getAttributeLongValue (const std::string& attrname, long defaultvalue) const;
145 int getAttributeIntValue (const std::string& attrname, int defaultvalue) const;
146 float getAttributeFloatValue (const std::string& attrname, float defaultvalue) const;
147
148 // finding sub elements by type
149 ctree<xmlelement>::iterator find(int type);
151
152 // getting sub elements values
153 const std::string getValue (int subElementType);
154 int getIntValue (int subElementType, int defaultvalue);
155 long getLongValue (int subElementType, long defaultvalue);
156 float getFloatValue (int subElementType, float defaultvalue);
158 bool hasSubElement(int subElementType);
160 bool hasSubElement(int subElementType, std::string value);
161
162 // misc
163 bool empty () const { return fValue.empty() && elements().empty(); }
164};
165
167
168}
169
170#endif
the smart pointer implementation
Definition smartpointer.h:58
Definition basevisitor.h:25
treeIterator< treePtr > iterator
the top -> bottom iterator type
Definition ctree.h:129
base class for visitable objects
Definition visitable.h:25
Definition visitor.h:27
A generic xml attribute representation.
Definition xml.h:47
const std::string & getValue() const
returns the attribute value as a string
Definition xml.h:66
A generic xml element representation.
Definition xml.h:86
bool hasSubElement(int subElementType, std::string value)
returns true if subelement with given value exists
const std::string & getValue() const
returns the element value as a string
Definition xml.h:125
bool hasSubElement(int subElementType)
returns true if subelement exists
long add(const Sxmlattribute &attr)
adds an attribute to the element