wsdlpull svntrunk
Loading...
Searching...
No Matches
TypeContainer.h
Go to the documentation of this file.
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//This class is a recursive storage container for any xml data type
21//It stores the actual values occuring in an XML Schema Instance ,
22//for a given type defined in the SchemaParser
23
24#ifndef _TYPECONTAINERH
25#define _TYPECONTAINERH
26#include <map>
27
29#include "xmlpull/XmlUtils.h"
31
32
33namespace Schema {
34class TypeContainer;
35
36
37typedef struct{
38 std::vector<TypeContainer *>tc;
39 int count;//Count maintains the last accessed container
40 int num;//num is the number of occurrences of this child
42
44{
45 public:
46 TypeContainer(int typeId,const SchemaParser * sp);
47 TypeContainer(ContentModel* cm,const SchemaParser * sp,int typeId);
48//type id is the complex type in which this content model is created
49
51 TypeContainer *getAttributeContainer(std::string attName,
52 bool create=false);
53 TypeContainer *getBaseTypeContainer(bool create=false);
54
55 TypeContainer *getChildContainer(std::string elemName,
56 bool create = false);
57
58 TypeContainer * getChildContainer(ContentModel* cm,
59 bool create=false);
60
61 //If this is a container for simple type this method
62 //returns a void* to the type .The actual type must be found using getTypeId()
63 void *getValue();
64
65 //Set position markers for this TypeContainer and all its' children to the start
66 //TODO add an iterator interface to typecontainer
67 void rewind();
68
69 //This method searches the xml instance for an element whose name is specified
70 //and is a simple type.If the return value is non null then type has the actual
71 //type of the returned value which can be used for type casting
72 void * getValue(const std::string & name,Schema::Type & type);
73
74 const SchemaParser * schemaParser()const;
75 bool isValueValid()const;
76 //return the type which the container instanciates
77 //The typeId is 0 if this is a container for an anonymous content model
78 int getTypeId()const;
79 //return the content model which the container instanciates
80 //The content model is null if this is a container instanciates a schema defined type
81 ContentModel* getContentModel()const;
82
83 //Various set methods
84 void setValue(const std::string & sValue,bool valid=true);
85 void setValue(int iValue,bool valid=true);
86 void setValue(char cValue,bool valid=true);
87 void setValue(long lValue,bool valid=true);
88 void setValue(unsigned long ulValue,bool valid=true);
89 void setValue(float fValue,bool valid=true);
90 void setValue(double dbValue,bool valid=true);
91 void setValue(bool bValue,bool valid=true);
92 void setValue(Qname & qnValue,bool valid=true);
93
94 //if the container actually stores atomic data,return its type
95 void setValAsString(const std::string &v);//set a value without validating
96 void print(std::ostream & os);
97 friend std::ostream &operator<<(std::ostream &os, TypeContainer &tc);
98 static bool printTypeNames_;
99 friend class SchemaValidator;
100 private:
101 //The unique id of the type for which this holds data
102 Schema::Type typeId_;
103 ContentModel* cm_;
104 std::map < std::string, Containers *> particleContainers_;//Type containers for particles
105 std::map<ContentModel*,TypeContainer* >cmContainers_;//Type container for the content models
106 std::map < std::string, TypeContainer *> attributeContainers_;//TypeContainers for attributes
107 const SchemaParser *sParser_;
108 TypeContainer * baseContainer_;
109
110 union
111 {
112 std::string *sValue;
113 int *iValue;
114 unsigned int *uiValue;
115 long *lValue;
116 unsigned long *ulValue;
117 short *shValue;
118 unsigned short *usValue;
119 float *fValue;
120 double *dbValue;
121 bool *bValue;
122 char *cValue;
123
124 // Date *dValue;
125 // DateTime *dtValue;
126 // Time *tValue;
128
129 // Uri *uriValue ;
130 } Value;
131 bool isValueValid_;//is the atomic date type valid
132 std::string strVal;
133 std::vector<TypeContainer*> tcTable;
134
135 void deleteValue();
136 void printComplexType (std::ostream & os);
137 void printSimpleType (std::ostream & os);
138 void printContentModel(std::ostream & os);
139
140 //Set position markers for this TypeContainer to the start
141 void rewindParticleContainers(std::map < std::string, Containers *> &particleContainers);
142};
143
144inline
145void
146TypeContainer::setValue(const std::string & sValue,bool valid)
147{
148 deleteValue();
149 Value.sValue = new std::string(sValue);
150 isValueValid_=valid;
151}
152
153inline
154void
155TypeContainer::setValue(int iValue,bool valid)
156{
157 deleteValue();
158 Value.iValue = new int (iValue);
159 isValueValid_=valid;
160}
161
162inline
163void
164TypeContainer::setValue(char cValue,bool valid)
165{
166 deleteValue();
167 Value.cValue = new char (cValue);
168 isValueValid_=valid;
169}
170
171inline
172void
173TypeContainer::setValue(long lValue,bool valid)
174{
175 deleteValue();
176 Value.lValue = new long (lValue);
177 isValueValid_=valid;
178}
179
180inline
181void
182TypeContainer::setValue(unsigned long ulValue,bool valid)
183{
184 deleteValue();
185 Value.ulValue = new unsigned long (ulValue);
186 isValueValid_=valid;
187}
188
189inline
190void
191TypeContainer::setValue(float fValue,bool valid)
192{
193 deleteValue();
194 Value.fValue = new float;
195 *(Value.fValue) = fValue;
196 isValueValid_=valid;
197}
198
199inline
200void
201TypeContainer::setValue(double dbValue,bool valid)
202{
203 deleteValue();
204 Value.dbValue = new double;
205 *(Value.dbValue) = dbValue;
206 isValueValid_=valid;
207}
208
209inline
210void
211TypeContainer::setValue(bool bValue,bool valid)
212{
213 deleteValue();
214 Value.bValue = new bool;
215 *(Value.bValue) = bValue;
216 isValueValid_=valid;
217}
218
219inline
220void
221TypeContainer::setValue(Qname & qnValue,bool valid)
222{
223 deleteValue();
224 Value.qnValue = new Qname(qnValue);
225 isValueValid_=valid;
226}
227
228inline
229int
231{
232 return typeId_;
233}
234
235inline
238{
239 return cm_;
240}
241
242inline
243void
245{
246 strVal=v;
247}
248/*
249inline
250void
251TypeContainer::setValidity(bool b )
252{
253 isValueValid_ = b;
254}
255*/
256
257
258inline
259bool
261{
262 return isValueValid_;
263}
264}
265#endif /* */
std::ostream & operator<<(std::ostream &os, const ConfigFile &cf)
Definition Qname.h:31
ContentModel * getContentModel() const
static bool printTypeNames_
unsigned int * uiValue
unsigned long * ulValue
void setValAsString(const std::string &v)
bool isValueValid() const
unsigned short * usValue
void setValue(const std::string &sValue, bool valid=true)
std::vector< TypeContainer * > tc
#define WSDLPULL_EXPORT