00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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;
00038 int num;
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
00059
00060 void *getValue();
00061
00062
00063
00064 void * getValue(const std::string & name,Schema::Type & type);
00065
00066 const SchemaParser * schemaParser()const;
00067 bool isValueValid()const;
00068
00069
00070 int getTypeId()const;
00071
00072
00073 ContentModel* getContentModel()const;
00074
00075
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
00087 void setValAsString(const std::string &v);
00088 void print(ostream & os);
00089 friend ostream &operator<<(ostream &os, TypeContainer &tc);
00090
00091 private:
00092
00093 Schema::Type typeId_;
00094 ContentModel* cm_;
00095 map < string, Containers *> particleContainers_;
00096 map<ContentModel*,TypeContainer* >cmContainers_;
00097 map < string, TypeContainer *> attributeContainers_;
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
00116
00117
00118 Qname *qnValue;
00119
00120
00121 } Value;
00122 bool isValueValid_;
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
00229
00230
00231
00232
00233
00234
00235
00236
00237 inline
00238 bool
00239 TypeContainer::isValueValid()const
00240 {
00241 return isValueValid_;
00242 }
00243
00244 #endif