TypeContainer.h

Go to the documentation of this file.
00001 /* 
00002  * wsdlpull - A C++ parser  for WSDL  (Web services description language)
00003  * Copyright (C) 2005-2007 Vivek Krishna
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00020 //This class is a recursive storage container for any xml data type
00021 //It stores the actual values occuring in an XML Schema Instance ,
00022 //for a given type defined in the SchemaParser
00023 
00024 #ifndef _TYPECONTAINERH
00025 #define  _TYPECONTAINERH
00026 #include <map>
00027 
00028 #include "xmlpull/wsdlpull_export.h"
00029 #include "xmlpull/XmlUtils.h"
00030 #include "schemaparser/SchemaParser.h"
00031 
00032 
00033 namespace Schema {
00034 class TypeContainer;
00035 
00036 
00037 typedef struct{
00038   std::vector<TypeContainer *>tc;
00039   int count;//Count maintains the last accessed container
00040   int num;//num is the number of occurrences of this child
00041 } Containers;
00042 
00043 class WSDLPULL_EXPORT TypeContainer
00044 {
00045  public:
00046   TypeContainer(int  typeId,const SchemaParser * sp);
00047   TypeContainer(ContentModel* cm,const SchemaParser * sp,int typeId);
00048 //type id is the complex type in which this content model is created
00049 
00050   ~TypeContainer();
00051   TypeContainer *getAttributeContainer(std::string attName, 
00052                                        bool create=false);
00053   TypeContainer *getBaseTypeContainer(bool create=false);
00054 
00055   TypeContainer *getChildContainer(std::string elemName, 
00056                                    bool create = false);
00057 
00058   TypeContainer * getChildContainer(ContentModel* cm,
00059                                     bool create=false);
00060 
00061   //If this is a container for simple type this method 
00062   //returns a void* to the type .The actual type  must be found using getTypeId()
00063   void *getValue();
00064 
00065   //Set position markers for this TypeContainer and all its' children to the start
00066   //TODO add an iterator interface to typecontainer
00067   void rewind();
00068 
00069   //This method searches the xml instance for an element whose name is specified
00070   //and is a simple type.If the return value is non null then type has the actual
00071   //type of the returned value which can be used for type casting
00072   void * getValue(const std::string & name,Schema::Type & type);
00073 
00074   const SchemaParser * schemaParser()const;
00075   bool isValueValid()const;
00076   //return the type which the container instanciates
00077   //The typeId is 0 if this is a container for an anonymous content model
00078   int getTypeId()const;
00079   //return the content model which the container instanciates
00080   //The content model is null if this is a container instanciates a schema defined type
00081   ContentModel* getContentModel()const;
00082 
00083   //Various set methods
00084   void setValue(const std::string & sValue,bool valid=true);
00085   void setValue(int iValue,bool valid=true);
00086   void setValue(char  cValue,bool valid=true);
00087   void setValue(long lValue,bool valid=true);
00088   void setValue(unsigned long  ulValue,bool valid=true);
00089   void setValue(float fValue,bool valid=true);
00090   void setValue(double dbValue,bool valid=true);
00091   void setValue(bool bValue,bool valid=true);
00092   void setValue(Qname & qnValue,bool valid=true);
00093 
00094   //if the container actually stores atomic data,return its type
00095   void setValAsString(const std::string &v);//set a value without validating
00096   void print(std::ostream & os); 
00097   friend  std::ostream &operator<<(std::ostream &os, TypeContainer &tc);
00098   static bool printTypeNames_;
00099   friend class SchemaValidator;
00100  private:
00101   //The unique id of the type for which this holds data
00102   Schema::Type typeId_; 
00103   ContentModel* cm_;
00104   std::map < std::string, Containers *> particleContainers_;//Type containers for particles
00105   std::map<ContentModel*,TypeContainer* >cmContainers_;//Type container for the content models
00106   std::map < std::string, TypeContainer *> attributeContainers_;//TypeContainers for attributes
00107   const SchemaParser *sParser_;
00108   TypeContainer * baseContainer_;
00109 
00110   union
00111   {
00112     std::string *sValue;
00113     int *iValue;
00114     unsigned int *uiValue;
00115     long *lValue;
00116     unsigned long *ulValue;
00117     short *shValue;
00118     unsigned short *usValue;
00119     float *fValue;
00120     double *dbValue;
00121     bool *bValue;
00122     char *cValue;
00123 
00124     //              Date *dValue;
00125     //              DateTime *dtValue;
00126     //              Time *tValue;
00127     Qname *qnValue;
00128 
00129     //      Uri *uriValue ;
00130   } Value;
00131   bool isValueValid_;//is the atomic date type valid
00132   std::string strVal;
00133   std::vector<TypeContainer*> tcTable;
00134 
00135   void deleteValue();
00136   void printComplexType (std::ostream & os);
00137   void printSimpleType (std::ostream & os);
00138   void printContentModel(std::ostream & os);
00139 
00140   //Set position markers for this TypeContainer to the start
00141   void rewindParticleContainers(std::map < std::string, Containers *> &particleContainers);
00142 };
00143 
00144 inline
00145 void
00146 TypeContainer::setValue(const std::string & sValue,bool valid)
00147 {
00148   deleteValue();
00149   Value.sValue = new std::string(sValue);
00150   isValueValid_=valid;
00151 }
00152 
00153 inline
00154 void
00155 TypeContainer::setValue(int iValue,bool valid)
00156 {
00157   deleteValue();
00158   Value.iValue = new int (iValue);
00159   isValueValid_=valid;
00160 }
00161 
00162 inline
00163 void 
00164 TypeContainer::setValue(char cValue,bool valid)
00165 {
00166   deleteValue();
00167   Value.cValue = new char (cValue);
00168   isValueValid_=valid;
00169 }
00170 
00171 inline
00172 void 
00173 TypeContainer::setValue(long lValue,bool valid)
00174 {
00175   deleteValue();
00176   Value.lValue = new long (lValue);
00177   isValueValid_=valid;
00178 }
00179 
00180 inline
00181 void 
00182 TypeContainer::setValue(unsigned long  ulValue,bool valid)
00183 {
00184   deleteValue();
00185   Value.ulValue = new unsigned long (ulValue);
00186   isValueValid_=valid;
00187 }
00188 
00189 inline
00190 void 
00191 TypeContainer::setValue(float fValue,bool valid)
00192 {
00193   deleteValue();
00194   Value.fValue = new float;
00195   *(Value.fValue) = fValue;
00196   isValueValid_=valid;
00197 }
00198 
00199 inline
00200 void 
00201 TypeContainer::setValue(double dbValue,bool valid)
00202 {
00203   deleteValue();
00204   Value.dbValue = new double;
00205   *(Value.dbValue) = dbValue;
00206   isValueValid_=valid;
00207 }
00208 
00209 inline
00210 void 
00211 TypeContainer::setValue(bool bValue,bool valid)
00212 {
00213   deleteValue();
00214   Value.bValue = new bool;
00215   *(Value.bValue) = bValue;
00216   isValueValid_=valid;
00217 }
00218 
00219 inline
00220 void 
00221 TypeContainer::setValue(Qname & qnValue,bool valid)
00222 {
00223   deleteValue();
00224   Value.qnValue = new Qname(qnValue);
00225   isValueValid_=valid;
00226 }
00227 
00228 inline
00229 int 
00230 TypeContainer::getTypeId()const
00231 {
00232   return typeId_;
00233 }
00234 
00235 inline 
00236 ContentModel* 
00237 TypeContainer::getContentModel()const
00238 {
00239   return cm_;
00240 }
00241 
00242 inline
00243 void
00244 TypeContainer::setValAsString(const std::string&v)
00245 {
00246   strVal=v;
00247 }
00248 /*
00249 inline
00250 void
00251 TypeContainer::setValidity(bool b )
00252 {
00253   isValueValid_ = b;
00254 }
00255 */
00256 
00257 
00258 inline
00259 bool
00260 TypeContainer::isValueValid()const
00261 {
00262   return isValueValid_;
00263 }
00264 }
00265 #endif                                            /*  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by  doxygen 1.6.2