Add Dirk Luetjen's ssphys libraries and command-line tool
[vss2svn.git] / ssphys / SSPhysLib / XML.h
blob25837b1d7b374108f38cbaa72375ad34792f94b1
1 // XML.h:structure definitions for SourceSafe files
2 //
3 //////////////////////////////////////////////////////////////////////
5 #if !defined(AFX_XML_H__6602C07F_65ED_4FD7_A730_6D416805378A__INCLUDED_)
6 #define AFX_XML_H__6602C07F_65ED_4FD7_A730_6D416805378A__INCLUDED_
8 #if _MSC_VER > 1000
9 #pragma once
10 #endif // _MSC_VER > 1000
12 typedef std::map<std::string, std::string> AttribMap;
14 // ---------------------------------------------------------------
15 class XMLEntity
17 protected:
18 static bool isSpecialChar (std::string::value_type v)
20 std::string punct = "&<>'\"";
21 std::string::iterator it = punct.begin();
23 while(it != punct.end())
24 if(v == *it++)
25 return true;
27 return false;
30 template <class T>
31 void ToXml (const T& element)
33 std::cout << element;
35 void ToXml (const std::string& element)
37 if (std::find_if (element.begin (), element.end (), isSpecialChar) == element.end ())
38 std::cout << element;
39 else
40 std::cout << "<![CDATA[" << element << "]]>";
42 void ToXml (const char& element)
44 if (std::find_if (&element, &element + strlen (&element), isSpecialChar) == &element+ strlen (&element))
45 std::cout << element;
46 else
47 std::cout << "<![CDATA[" << element << "]]>";
52 // ---------------------------------------------------------------
53 class XMLNode : protected XMLEntity
55 public:
56 XMLNode (XMLNode* pParent, std::string name)
57 : m_pParent (pParent), m_Name (name)
59 std::cout << "<" << name << ">" << std::endl;
62 XMLNode (XMLNode* pParent, std::string name, AttribMap attrib)
63 : m_pParent (pParent), m_Name (name)
65 std::cout << "<" << name;
66 AttribMap::iterator itor = attrib.begin ();
67 for (; itor != attrib.end (); ++itor)
69 std::cout << " " << itor->first << "=\"" << itor->second << "\"";
71 std::cout << ">" << std::endl;
73 ~XMLNode ()
75 std::cout << "</" << m_Name << ">" << std::endl;
78 protected:
79 XMLNode* m_pParent;
80 std::string m_Name;
84 class XMLElement : protected XMLEntity
86 public:
87 template <class T>
88 XMLElement (XMLNode* pParent, std::string name, const T& element)
90 std::cout << "<" << name << ">";
91 ToXml(element);
92 std::cout << "</" << name << ">" << std::endl;
95 template <class T>
96 XMLElement (XMLNode* pParent, std::string name, AttribMap attrib, const T& element)
98 std::cout << "<" << name;
99 AttribMap::iterator itor = attrib.begin ();
100 for (; itor != attrib.end (); ++itor)
102 std::cout << " " << itor->first << "=\"" << itor->second << "\"";
104 std::cout << ">";
105 ToXml(element);
106 std::cout << "</" << name << ">" << std::endl;
110 class XMLValue : protected XMLEntity
112 public:
113 template <class T>
114 XMLValue (XMLNode* pParent, const T& element)
116 ToXml(element);
121 #endif // !defined(AFX_XML_H__6602C07F_65ED_4FD7_A730_6D416805378A__INCLUDED_)