1 /*-
2  * Copyright (c) 2004 Jacques A. Vidrine
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27 #ifndef CELABO_20040211_VUXML_HH
28 #define CELABO_20040211_VUXML_HH
29 
30 #include <vuxml/config.h>
31 
32 #if !defined(__unused)
33 #if defined(__GNUC__)
34 #define	__unused __attribute__((__unused__))
35 #else
36 #define __unused
37 #endif
38 #endif
39 
40 namespace vuxml {
41 
42 
43 class Logger {
44 public:
45   static std::ostream &log();
46 };
47 #define LOG	(vuxml::Logger::log())
48 
49 
50 typedef std::map<std::string, std::string> Attributes;
51 
52 
53 class except : public std::exception {
54 public:
except(const char * s)55   except(const char *s) throw() : what_(s) {}
~except()56   virtual ~except() throw() {}
what() const57   virtual const char *what() const throw() { return what_; }
58 private:
59   const char *what_;
60 };
61 
62 
63 std::string killspace(const std::string &s);
64 std::string xmlescape(const std::string &s);
65 
66 
67 struct VersionRange {
68   static const char infinity[];
69   static const char zero[];
VersionRangevuxml::VersionRange70   VersionRange() : lo_closed(true), hi_closed(true), lo(zero), hi(infinity) {}
71   bool		lo_closed;
72   bool		hi_closed;
73   std::string	lo;
74   std::string	hi;
75   bool		contains(const std::string &version) const;
76 };
77 
78 
79 struct AffectedSet {
80   std::vector<std::string>	names;
81   std::vector<VersionRange>	ranges;
82 };
83 
84 
85 struct Reference {
Referencevuxml::Reference86   Reference(const std::string type_, const std::string text_) :
87       type(type_), text(text_) {}
88   std::string	type;
89   std::string	text;
90 };
91 
92 
93 class Entry {
94 public:
95 
96   Entry();
97   ~Entry();
98 
99   const std::string	&vid() const;
100   void			 setVid(const std::string &vid);
101 
102   const std::string	&topic() const;
103   void			 setTopic(const std::string &text);
104 
105   const std::string	&description() const;
106   void			 setDescription(const std::string &text);
107   void			 appendDescription(const std::string &text);
108 
109   const std::string	&discoveryDate() const;
110   void			 setDiscoveryDate(const std::string &date);
111 
112   const std::string	&entryDate() const;
113   void			 setEntryDate(const std::string &date);
114 
115   const std::string	&modifiedDate() const;
116   void			 setModifiedDate(const std::string &date);
117 
118   const std::vector<Reference> &references() const;
119   void			 addReference(const Reference &reference);
120   void			 addReference(const std::string &type,
121 			    const std::string &text);
122 
123   const std::vector<AffectedSet> &affected() const;
124   void			 addAffectedSet();
125   void			 addAffectedName(const std::string &name);
126   void			 addAffectedRange(const VersionRange &range);
127 
128 private:
129   std::string		vid_;
130   std::string		topic_;
131   std::string		description_;
132   std::string		discovery_;
133   std::string		entry_;
134   std::string		modified_;
135   std::vector<Reference> references_;
136   std::vector<AffectedSet> affected_;
137 };
138 
139 
140 class EntryProcessor : public std::unary_function<bool, const Entry &> {
141 public:
142   EntryProcessor();
143   virtual ~EntryProcessor();
144   virtual bool operator()(const Entry &entry) = 0;
145   virtual void start();
146   virtual void end();
147 };
148 
149 
150 extern "C" int version_cmp(const char *, const char *);
151 }
152 #endif
153