Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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/XmlUtils.h"
00029 #include "schemaparser/SchemaParser.h"
00030 
00031 #ifndef WSDLPULL_EXPORT
00032 #if (defined _MSC_VER) && (defined _MT)
00033 #define WSDLPULL_EXPORT __declspec (dllimport)
00034 #else
00035 #define WSDLPULL_EXPORT 
00036 #endif
00037 #endif
00038 
00039 namespace Schema {
00040 class TypeContainer;
00041 
00042 
00043 typedef struct
00044 {
00045   std::vector<TypeContainer *>tc;
00046   int count;//Count maintains the last accessed container
00047   int num;//num is the number of occurrences of this child
00048 } Containers;
00049 
00050 class WSDLPULL_EXPORT TypeContainer
00051 {
00052  public:
00053   TypeContainer(int  typeId,const SchemaParser * sp);
00054   TypeContainer::TypeContainer(ContentModel* cm,
00055                                const SchemaParser * sp);
00056   ~TypeContainer();
00057   TypeContainer *getAttributeContainer(std::string attName, 
00058                                        bool create=false);
00059   TypeContainer *getBaseTypeContainer(bool create=false);
00060 
00061   TypeContainer *getChildContainer(std::string elemName, 
00062                                    bool create = false);
00063 
00064   TypeContainer * getChildContainer(ContentModel* cm,
00065                                     bool create=false);
00066 
00067   //If this is a container for simple type this method 
00068   //returns a void* to the type .The actual type  must be found using getTypeId()
00069   void *getValue();
00070 
00071   //Set position markers for this TypeContainer and all its' children to the start
00072   //TODO add an iterator interface to typecontainer
00073   void rewind();
00074 
00075   //This method searches the xml instance for an element whose name is specified
00076   //and is a simple type.If the return value is non null then type has the actual
00077   //type of the returned value which can be used for type casting
00078   void * getValue(const std::string & name,Schema::Type & type);
00079 
00080   const SchemaParser * schemaParser()const;
00081   bool isValueValid()const;
00082   //return the type which the container instanciates
00083   //The typeId is 0 if this is a container for an anonymous content model
00084   int getTypeId()const;
00085   //return the content model which the container instanciates
00086   //The content model is null if this is a container instanciates a schema defined type
00087   ContentModel* getContentModel()const;
00088 
00089   //Various set methods
00090   void setValue(const std::string & sValue,bool valid=true);
00091   void setValue(int iValue,bool valid=true);
00092   void setValue(char  cValue,bool valid=true);
00093   void setValue(long lValue,bool valid=true);
00094   void setValue(unsigned long ulValue,bool valid=true);
00095   void setValue(float fValue,bool valid=true);
00096   void setValue(double dbValue,bool valid=true);
00097   void setValue(bool bValue,bool valid=true);
00098   void setValue(Qname & qnValue,bool valid=true);
00099 
00100   //if the container actually stores atomic data,return its type
00101   void setValAsString(const std::string &v);//set a value without validating
00102   void print(std::ostream & os); 
00103   friend  std::ostream &operator<<(std::ostream &os, TypeContainer &tc);
00104   static bool printTypeNames_;
00105  private:
00106   //The unique id of the type for which this holds data
00107   Schema::Type typeId_; 
00108   ContentModel* cm_;
00109   std::map < std::string, Containers *> particleContainers_;//Type containers for particles
00110   std::map<ContentModel*,TypeContainer* >cmContainers_;//Type container for the content models
00111   std::map < std::string, TypeContainer *> attributeContainers_;//TypeContainers for attributes
00112   const SchemaParser *sParser_;
00113   TypeContainer * baseContainer_;
00114 
00115   union
00116   {
00117     std::string *sValue;
00118     int *iValue;
00119     unsigned int *uiValue;
00120     long *lValue;
00121     unsigned long *ulValue;
00122     short *shValue;
00123     unsigned short *usValue;
00124     float *fValue;
00125     double *dbValue;
00126     bool *bValue;
00127     char *cValue;
00128 
00129     //              Date *dValue;
00130     //              DateTime *dtValue;
00131     //              Time *tValue;
00132     Qname *qnValue;
00133 
00134     //      Uri *uriValue ;
00135   } Value;
00136   bool isValueValid_;//is the atomic date type valid
00137   std::string strVal;
00138   std::vector<TypeContainer*> tcTable;
00139 
00140   void deleteValue();
00141   void printComplexType (std::ostream & os);
00142   void printSimpleType (std::ostream & os);
00143   void printContentModel(std::ostream & os);
00144 
00145   //Set position markers for this TypeContainer to the start
00146   void rewindParticleContainers(std::map < std::string, Containers *> &particleContainers);
00147 };
00148 
00149 inline
00150 void
00151 TypeContainer::setValue(const std::string & sValue,bool valid)
00152 {
00153   deleteValue();
00154   Value.sValue = new std::string(sValue);
00155   isValueValid_=valid;
00156 }
00157 
00158 inline
00159 void
00160 TypeContainer::setValue(int iValue,bool valid)
00161 {
00162   deleteValue();
00163   Value.iValue = new int (iValue);
00164   isValueValid_=valid;
00165 }
00166 
00167 inline
00168 void 
00169 TypeContainer::setValue(char cValue,bool valid)
00170 {
00171   deleteValue();
00172   Value.cValue = new char (cValue);
00173   isValueValid_=valid;
00174 }
00175 
00176 inline
00177 void 
00178 TypeContainer::setValue(long lValue,bool valid)
00179 {
00180   deleteValue();
00181   Value.lValue = new long (lValue);
00182   isValueValid_=valid;
00183 }
00184 
00185 inline
00186 void 
00187 TypeContainer::setValue(unsigned long ulValue,bool valid)
00188 {
00189   deleteValue();
00190   Value.ulValue = new unsigned long (ulValue);
00191   isValueValid_=valid;
00192 }
00193 
00194 inline
00195 void 
00196 TypeContainer::setValue(float fValue,bool valid)
00197 {
00198   deleteValue();
00199   Value.fValue = new float;
00200   *(Value.fValue) = fValue;
00201   isValueValid_=valid;
00202 }
00203 
00204 inline
00205 void 
00206 TypeContainer::setValue(double dbValue,bool valid)
00207 {
00208   deleteValue();
00209   Value.dbValue = new double;
00210   *(Value.dbValue) = dbValue;
00211   isValueValid_=valid;
00212 }
00213 
00214 inline
00215 void 
00216 TypeContainer::setValue(bool bValue,bool valid)
00217 {
00218   deleteValue();
00219   Value.bValue = new bool;
00220   *(Value.bValue) = bValue;
00221   isValueValid_=valid;
00222 }
00223 
00224 inline
00225 void 
00226 TypeContainer::setValue(Qname & qnValue,bool valid)
00227 {
00228   deleteValue();
00229   Value.qnValue = new Qname(qnValue);
00230   isValueValid_=valid;
00231 }
00232 
00233 inline
00234 int 
00235 TypeContainer::getTypeId()const
00236 {
00237   return typeId_;
00238 }
00239 
00240 inline 
00241 ContentModel* 
00242 TypeContainer::getContentModel()const
00243 {
00244   return cm_;
00245 }
00246 
00247 inline
00248 void
00249 TypeContainer::setValAsString(const std::string&v)
00250 {
00251   strVal=v;
00252 }
00253 /*
00254 inline
00255 void
00256 TypeContainer::setValidity(bool b )
00257 {
00258   isValueValid_ = b;
00259 }
00260 */
00261 
00262 
00263 inline
00264 bool
00265 TypeContainer::isValueValid()const
00266 {
00267   return isValueValid_;
00268 }
00269 }
00270 #endif                                            /*  */

Generated on Mon Feb 6 23:02:42 2006 for wsdlpull by  doxygen 1.3.9.1