1 /*
2 * wsdlpull - A C++ parser for WSDL (Web services description language)
3 * Copyright (C) 2005-2007 Vivek Krishna
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *
20 */
21 #ifndef _SIMPLETYPEH
22 #define _SIMPLETYPEH
23 #include <list>
24 #include <map>
25 #include <vector>
26
27 #include "schemaparser/XSDType.h"
28 #include "xmlpull/wsdlpull_export.h"
29 #include "xmlpull/Qname.h"
30 #include "xmlpull/XmlUtils.h"
31 #include "schemaparser/SchemaParserException.h"
32
33 namespace Schema {
34 //union to store the values for various facets
35 typedef union
36 {
37 int length;
38 struct
39 {
40 int minlen, maxlen;
41 } lenRange;
42 int numEnums;
43 int wsp;
44 struct
45 {
46 int maxinc, mininc, maxex, minex;
47 } valRange;
48 int tot;
49 int frac;
50 const char *pattern;
51 } facetValueType;
52
53 class WSDLPULL_EXPORT SimpleType:public XSDType
54 {
55 public:
56 /** @name Constructors and Destructors */
57 //@{
58 /**
59 * @param the namespace uri of the simple type
60 */
61 SimpleType(const std::string & ns);
62 ~SimpleType();
63 //@}
64
65 /** @name Various Getter methods*/
66 //@{
67 /**
68 * isList
69 * @return :is this a list type
70 */
71 bool isList() const;
72 /**
73 * isUnion
74 * @return :is this a union type
75 */
76 bool isUnion() const;
77 /**
78 * isSimple
79 * return false
80 */
81 bool isSimple() const;
82
83 //facet and restriction methods
84 bool isvalidFacet(std::string facet);
85 bool isValidInt(int val)const;
86 bool isValidFloat(float val)const;
87 bool isValidString(std::string val)const;
88 bool getFacetValue(int facet, void* &val);
89 const std::list<int>* unionTypes()const;
90
91 //@}
92
93 //@{ Various setter and utility methods
94 void setUnionType(int id);
95 void setListType(int id);
96 void setFacetValue(std::string facet,std::string val);
97 //@}
98
99 //enum for facet Ids
100 enum
101 {
102 NONE = 0,
103 LENGTH = 0x1,
104 MINLEN = 0x2,
105 MAXLEN = 0x4,
106 ENUM =0x8,
107 WSP = 0x10,
108 MAXINC = 0x20,
109 MININC = 0x40,
110 MAXEX =0x80,
111 MINEX = 0x100,
112 TOTALDIGITS = 0x200,
113 FRAC = 0x400,
114 PATTERN = 0x800
115 };
116
117 //whitespace values
118 enum
119 {
120 PRESERVE = 1,
121 REPLACE,
122 COLLAPSE
123 };
124 #ifdef LOGGING
125 void print(std::ostream & out);
126 #endif
127 private:
128 std::vector<int> facetId_;
129 std::map<std::string,int> facets_;
130 std::list < std::string > enumValues_;
131 int *validFacets_;
132 facetValueType facetValue_;
133 void error(std::string msg);
134 bool isList_;
135 bool isUnion_;
136 std::list<int> * uTypes_;
137 };
138
139 inline
140 bool
isList()141 SimpleType::isList() const
142 {
143 return isList_;
144 }
145
146 inline
147 bool
isUnion()148 SimpleType::isUnion() const
149 {
150 return isUnion_;
151 }
152
153 inline
154 void
setListType(int typeId)155 SimpleType::setListType(int typeId)
156 {
157 isList_ = true;
158 setBaseType(typeId);
159 }
160
161 inline
162 void
setUnionType(int typeId)163 SimpleType::setUnionType(int typeId)
164 {
165 isUnion_ = true;
166 if(uTypes_ == 0){
167 uTypes_ = new std::list<int>();
168 }
169 uTypes_->push_back(typeId);
170 }
171
172 inline
173 bool
isSimple()174 SimpleType::isSimple() const
175 {
176 return true;
177 }
178 inline
179 const std::list<int>*
unionTypes()180 SimpleType::unionTypes()const
181 {
182 return uTypes_;
183 }
184 }
185 #endif /* */
186