MI - Fimex
XMLInput.h
Go to the documentation of this file.
1 /*
2  * Fimex, XMLInput.h
3  *
4  * (C) Copyright 2011, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  *
23  * Created on: Oct 25, 2011
24  * Author: Heiko Klein
25  */
26 
27 #ifndef XMLINPUT_H_
28 #define XMLINPUT_H_
29 
34 #include <string>
35 #include <boost/shared_ptr.hpp>
36 
37 namespace MetNoFimex
38 {
39 
40 // forward decl.
41 class XMLDoc;
42 
49 class XMLInput
50 {
51 public:
52  virtual ~XMLInput() {}
59  virtual boost::shared_ptr<XMLDoc> getXMLDoc() const = 0;
63  virtual std::string id() const = 0;
67  virtual bool isEmpty() const {return (id().empty());}
68 };
69 
70 class XMLInputFile : public XMLInput
71 {
72 private:
73  std::string filename_;
74 public:
75  XMLInputFile(const std::string& filename) : filename_(filename) {}
76  virtual boost::shared_ptr<XMLDoc> getXMLDoc() const;
77  virtual std::string id() const {return filename_;}
78 };
79 
80 class XMLInputString : public XMLInput
81 {
82 private:
83  std::string content_;
84  std::string url_;
85 public:
91  XMLInputString(const std::string& content, const std::string& url = "") : content_(content), url_(url) {}
92  virtual boost::shared_ptr<XMLDoc> getXMLDoc() const;
93  virtual std::string id() const {return content_.substr(0,((content_.size() > 100) ? 100 : content_.size()));}
94 };
95 
96 class XMLInputURL : public XMLInput
97 {
98 private:
99  std::string url_;
100 public:
101  XMLInputURL(const std::string& url) : url_(url) {}
102  virtual boost::shared_ptr<XMLDoc> getXMLDoc() const;
103  virtual std::string id() const {return url_;}
104 };
105 
106 class XMLInputDoc : public XMLInput
107 {
108 private:
109  std::string id_;
110  boost::shared_ptr<XMLDoc> doc_;
111 public:
112  XMLInputDoc(const std::string& id, boost::shared_ptr<XMLDoc> doc) : id_(id), doc_(doc) {}
113  virtual boost::shared_ptr<XMLDoc> getXMLDoc() const {return doc_;}
114  virtual std::string id() const {return id_;}
115 };
116 
117 }
118 
119 
120 #endif /* XMLINPUT_H_ */
virtual bool isEmpty() const
Definition: XMLInput.h:67
basic_string< char > string
Definition: XMLInput.h:106
XMLInputURL(const std::string &url)
Definition: XMLInput.h:101
XMLInputFile(const std::string &filename)
Definition: XMLInput.h:75
virtual std::string id() const
Definition: XMLInput.h:77
Definition: XMLInput.h:96
virtual boost::shared_ptr< XMLDoc > getXMLDoc() const
Definition: XMLInput.h:113
XMLInputString(const std::string &content, const std::string &url="")
Definition: XMLInput.h:91
Definition: XMLInput.h:80
Definition: C_CDMReader.h:35
virtual ~XMLInput()
Definition: XMLInput.h:52
virtual std::string id() const
Definition: XMLInput.h:103
XMLInputDoc(const std::string &id, boost::shared_ptr< XMLDoc > doc)
Definition: XMLInput.h:112
Definition: XMLInput.h:49
virtual boost::shared_ptr< XMLDoc > getXMLDoc() const =0
virtual std::string id() const
Definition: XMLInput.h:93
virtual std::string id() const
Definition: XMLInput.h:114
virtual std::string id() const =0
Definition: XMLInput.h:70