]> git.mxchange.org Git - simgear.git/blob - simgear/io/DAVMultiStatus.hxx
Fix VS2010 lack of fminf
[simgear.git] / simgear / io / DAVMultiStatus.hxx
1 // DAVMultiStatus.hxx -- parser for WebDAV MultiStatus XML data
2 //
3 // Copyright (C) 2012  James Turner <zakalawe@mac.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19
20 #ifndef SG_IO_DAVMULTISTATUS_HXX
21 #define SG_IO_DAVMULTISTATUS_HXX
22
23 #include <string>
24 #include <vector>
25 #include <memory> // for auto_ptr
26
27 namespace simgear
28 {
29
30 class DAVCollection;
31
32 class DAVResource
33 {
34 public:
35     DAVResource(const std::string& url);
36     virtual ~DAVResource() { }
37   
38     typedef enum {
39         Unknown = 0,
40         Collection = 1
41     } Type;
42         
43     const Type type() const
44         { return _type; }
45     
46     const std::string& url() const
47         { return _url; }
48
49     std::string name() const;
50
51     /**
52      * SVN servers use this field to expose the head revision
53      * of the resource, which is useful
54      */
55     const std::string& versionName() const
56       { return _versionName; }
57
58     void setVersionName(const std::string& aVersion);
59
60     DAVCollection* container() const
61         { return _container; }
62     
63     virtual bool isCollection() const
64         { return false; }
65
66     void setVersionControlledConfiguration(const std::string& vcc);
67     const std::string& versionControlledConfiguration() const
68         { return _vcc; }
69     
70     void setMD5(const std::string& md5Hex);
71     const std::string& md5() const
72         { return _md5; }
73 protected:
74     friend class DAVCollection;
75   
76     Type _type;
77     std::string _url;
78     std::string _versionName;
79     std::string _vcc;
80     std::string _md5;
81     DAVCollection* _container;
82 };
83
84 typedef std::vector<DAVResource*> DAVResourceList;
85
86 class DAVCollection : public DAVResource
87 {
88 public:
89   DAVCollection(const std::string& url);
90   virtual ~DAVCollection();
91   
92   DAVResourceList contents() const;
93   
94   void addChild(DAVResource* res);
95   void removeChild(DAVResource* res);
96   
97   DAVCollection* createChildCollection(const std::string& name);
98   
99   /**
100    * find the collection member with the specified URL, or return NULL
101    * if no such member of this collection exists.
102    */
103   DAVResource* childWithUrl(const std::string& url) const;
104      
105   /**
106    * find the collection member with the specified name, or return NULL
107    */
108   DAVResource* childWithName(const std::string& name) const;
109    
110   /**
111    * wrapper around URL manipulation
112    */
113   std::string urlForChildWithName(const std::string& name) const;
114   
115   virtual bool isCollection() const
116   { return true; }
117 private:
118   DAVResourceList _contents;
119 };
120
121 class DAVMultiStatus
122 {
123 public:
124     DAVMultiStatus();
125     ~DAVMultiStatus();
126     
127     // incremental XML parsing
128     void parseXML(const char* data, int size);
129     
130     void finishParse();
131     
132     bool isValid() const;
133     
134     DAVResource* resource();
135   
136   class DAVMultiStatusPrivate;
137 private:
138     std::auto_ptr<DAVMultiStatusPrivate> _d;
139 };
140
141 } // of namespace simgear
142
143 #endif // of SG_IO_DAVMULTISTATUS_HXX