00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __xml__
00026 #define __xml__
00027
00028 #include "exports.h"
00029 #include "bimap.h"
00030 #include "smartpointer.h"
00031 #include <iostream>
00032 #include <string>
00033 #include <vector>
00034
00035 using namespace std;
00036
00037 namespace MusicXML
00038 {
00039
00040 class xmlelement;
00041 class xmlattribute;
00042 class xmlable;
00043 class xmlheader;
00044
00045 typedef SMARTP<xmlattribute> Sxmlattribute;
00046 typedef SMARTP<xmlelement> Sxmlelement;
00047 typedef SMARTP<xmlheader> Sxmlheader;
00048
00049 ostream& operator<< (ostream& os, const Sxmlattribute& attr);
00050 EXP ostream& operator<< (ostream& os, const Sxmlelement& elt);
00051 EXP ostream& operator<< (ostream& os, const Sxmlheader& header);
00052
00061 class xmlendl {
00062 public:
00063 static xmlendl& get() { if (!fInstance) fInstance = new xmlendl; return *fInstance; }
00064
00066 xmlendl& operator++ (int) { fIndent++; return *this; }
00068 xmlendl& operator-- (int) { fIndent--; return *this; }
00070 void reset() { fIndent = 0; }
00071 void print(ostream& os) const { int i = fIndent;
00072 os << std::endl;
00073 while (i-- > 0) os << " "; }
00074 protected:
00075 xmlendl() : fIndent(0) {}
00076 private:
00077 int fIndent;
00078 static xmlendl * fInstance;
00079 };
00080
00086 class xmlattribute : public smartable {
00087 protected:
00088 xmlattribute(string name, string value) : fName(name), fValue(value) {}
00089 xmlattribute(string name, long value) : fName(name) { setValue(value); }
00090 public:
00091 EXP friend SMARTP<xmlattribute> new_xmlattribute(string name, string value);
00092 EXP friend SMARTP<xmlattribute> new_xmlattribute(string name, long value);
00093
00094 void setName (const string& name);
00095 void setValue (const string& value);
00096 void setValue (long value);
00097
00098 const string& getName () const { return fName; }
00099 const string& getValue () const { return fValue; }
00100 void print (ostream& os) const;
00101 private:
00103 string fName;
00105 string fValue;
00106 };
00107
00116 class xmlelement : public smartable {
00117
00118 public:
00119 EXP friend SMARTP<xmlelement> new_xmlelement(string name);
00120 EXP friend SMARTP<xmlelement> new_xmlelement(string name, unsigned long val);
00121 EXP friend SMARTP<xmlelement> new_xmlelement(string name, long val);
00122 EXP friend SMARTP<xmlelement> new_xmlelement(string name, int val);
00123 EXP friend SMARTP<xmlelement> new_xmlelement(string name, float val);
00124 EXP friend SMARTP<xmlelement> new_xmlelement(string name, string val);
00125
00126 void setValue (unsigned long value);
00127 void setValue (long value);
00128 void setValue (int value);
00129 void setValue (float value);
00130 void setValue (const string& value);
00131 void setName (const string& name);
00132
00133 const string& getName () const { return fName; }
00134 const string& getValue () const { return fValue; }
00135
00136 long add (const Sxmlattribute& attr);
00137 long add (const Sxmlelement& elt);
00138
00139 const vector<Sxmlelement>& elements() const { return fElements; }
00140 const vector<Sxmlattribute>& attributes() const { return fAttributes; }
00141
00142 bool empty () const { return fValue.empty() && fElements.empty(); }
00143 void print (ostream& os) const;
00144
00145 protected:
00146 xmlelement(string name) : fName(name) {}
00147 xmlelement(string name, unsigned long value) : fName(name) { setValue(value); }
00148 xmlelement(string name, long value) : fName(name) { setValue(value); }
00149 xmlelement(string name, int value) : fName(name) { setValue(value); }
00150 xmlelement(string name, float value) : fName(name) { setValue(value); }
00151 xmlelement(string name, string value) : fName(name) { setValue(value); }
00152 virtual ~xmlelement() {}
00153
00154 private:
00156 string fName;
00158 string fValue;
00160 vector<Sxmlattribute> fAttributes;
00162 vector<Sxmlelement> fElements;
00163 };
00164
00168 class EXP xmlheader : public smartable {
00169 protected:
00170 xmlheader (int mode, string loc) : fMode(mode), fLocation(loc) {}
00171 virtual ~xmlheader () {}
00172
00173 public:
00174 enum { partwise=1, timewise, last=timewise };
00175
00176 EXP friend SMARTP<xmlheader> new_xmlheader(int mode=partwise, string loc="http://www.musicxml.org/dtds/");
00177
00179 void setMode (int mode);
00181 void setLocation (const string& loc);
00182
00184 int getMode () const { return fMode; }
00186 const string& getLocation () const { return fLocation; }
00188 const string MusicXMLVersion () const { return "0.8"; }
00189 void print (ostream& os) const;
00190
00192 static const string scoreMode (int mode);
00194 static int scoreMode (string mode);
00195
00196 private:
00198 int fMode;
00200 string fLocation;
00201
00202 static bimap<string, int> fMode2String;
00203 static int fModeTbl[];
00204 static string fModeStrings[];
00205 };
00206
00214
00215
00216
00217
00218
00219
00220
00221 }
00222
00223 #endif