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

Generated on Sun Oct 16 10:11:52 2005 for wsdlpull by  doxygen 1.3.9.1