Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

msd_metadata.h

00001 //--------------------------------
00002 // msd_metadata.h
00003 //
00004 // Project: META DATA Classes for PDBe API Framework 
00005 //
00006 // Data Layer
00007 // Last updated: 25 February 2004 10:17
00008 // (C) Siamak Sobhany
00009 //--------------------------------
00010 
00011 #ifndef __MSD_METADATA_H__
00012 #define __MSD_METADATA_H__
00013 
00014 #ifndef __MSD_DATATYPES_H__
00015 #include "msd_datatypes.h"
00016 #endif
00017 #ifndef __MSD_DATA_H__
00018 #include "msd_data.h"
00019 #endif
00020 
00021 struct msd_table 
00022     { char *name;
00023           int ID; 
00024       char *owner; 
00025       char *description; 
00026     }; 
00027     struct TableArray 
00028         {
00029       struct msd_table  ptr[42];
00030       int size; 
00031     }; 
00032 
00036 #define  MakeAPIFunctions(TableName,AttName,TypeName)        \
00037  void Set##TableName##AttName (##TypeName value) {           \
00038              AttName = value;                                \
00039                          };                                              \
00040  TypeName Get##TableName##AttName () const {return AttName;};                    
00041  
00042 
00043 
00044 
00046 // Object Attribute introspection
00047 
00048 //Steps to do if you want to add support for a new type
00049 // 1:  Add an enumeration to CAttribute::AttributeType
00050 // 2:  Add a typedef to CSetAttribute with the signiture of the function pointer for the set operation
00051 // 3:  Add a type from the above typedef to CSetAttribute's FunctionPointers union
00052 // 4:  Add a constructor to CSetAttribute to handle the new function pointer typedef
00053 // 5:  Overload CSetAttribute::SetAttribute so that it takes a first parameter of your new type
00054 // 6:  repeate 2-5 for CGetAttribute
00055 // 7:  Add the appropriate macros to handle your new type :SET_yourtype_GET_ATTRIBUTE,SET_yourtype_SET_ATTRIBUTE,SET_yourtype_ATTRIBUTE
00056 #include <list>
00057 //using std::list;
00058 //
00059 
00060 
00061 //used locally to simplify calling function pointers
00062 #define CallMemberFunction(object,ptrToMember)  ((object)->*(ptrToMember)) 
00063 
00068 class CAttribute
00069 {
00070 public:
00071         enum AttributeType
00072         {
00073                 ATInt,
00074                 ATShort,
00075                 ATDouble,
00076                 ATString,
00077                 ATFloat,
00078                 ATBool,
00079                 ATDate
00080 
00081         };
00082         
00083 
00084 // Function name        : CAttribute
00085 // Description      : The only constructor for CAttribute
00086 // Return type          : 
00087 // Argument         : LPCTSTR sName
00088 // Argument         : AttributeType iType
00089         CAttribute(char* sName,AttributeType iType):m_sName(sName),m_Type(iType){};
00090 
00091         char* GetName(){return m_sName;};
00092         const AttributeType GetType(){return m_Type;};
00093 
00094 protected:
00095         char*           m_sName;
00096         AttributeType   m_Type;
00097         
00098 private:
00099         CAttribute();
00100 };
00101 
00105 template<class DerivedClass> class CSetAttribute : public CAttribute
00106 {
00107 public:
00108         typedef void (DerivedClass::*intfp)(int);
00109     typedef void (DerivedClass::*shortfp)(short);
00110         typedef void (DerivedClass::*doublefp)(double);
00111         typedef void (DerivedClass::*stringfp)(const char*&);
00112         typedef void (DerivedClass::*floatfp)(float);
00113         typedef void (DerivedClass::*boolfp)(bool);
00114         typedef void (DerivedClass::*datefp)(msdbDate);
00115 
00116         union FunctionPointers
00117         {
00118                  intfp IntSetfp;
00119                  doublefp DoubleSetfp;
00120                  stringfp StringSetfp;
00121                  floatfp FloatSetfp;
00122                  boolfp BoolSetfp;
00123                  datefp DateSetfp;
00124         };
00125 
00126         CSetAttribute(char* sName,AttributeType iType,intfp p):CAttribute(sName,iType){m_uFunctionPointer.IntSetfp=p;};
00127         CSetAttribute(char* sName,AttributeType iType,shortfp p):CAttribute(sName,iType){m_uFunctionPointer.ShortSetfp=p;}
00128         CSetAttribute(char* sName,AttributeType iType,doublefp p):CAttribute(sName,iType){m_uFunctionPointer.DoubleSetfp=p;}
00129         CSetAttribute(char* sName,AttributeType iType,stringfp p):CAttribute(sName,iType){m_uFunctionPointer.StringSetfp=p;};
00130         CSetAttribute(char* sName,AttributeType iType,floatfp p):CAttribute(sName,iType){m_uFunctionPointer.FloatSetfp=p;};
00131         CSetAttribute(char* sName,AttributeType iType,boolfp p):CAttribute(sName,iType){m_uFunctionPointer.BoolSetfp=p;};
00132         CSetAttribute(char* sName,AttributeType iType,datefp p):CAttribute(sName,iType){m_uFunctionPointer.DareSetfp=p;};
00133         
00134         void SetAttribute(int Val,DerivedClass* p)
00135         {
00136                 CallMemberFunction(p,m_uFunctionPointer.IntSetfp)(Val);
00137         };
00138         void SetAttribute(short Val,DerivedClass* p)
00139         {
00140                 CallMemberFunction(p,m_uFunctionPointer.ShortSetfp)(Val);
00141         };
00142         void SetAttribute(double Val,DerivedClass* p)
00143         {
00144                 CallMemberFunction(p,m_uFunctionPointer.DoubleSetfp)(Val);
00145         };
00146         void SetAttribute(char* Val,DerivedClass* p)
00147         {
00148                 CallMemberFunction(p,m_uFunctionPointer.StringSetfp)(Val);
00149         };
00150         void SetAttribute(float Val,DerivedClass* p)
00151         {
00152                 CallMemberFunction(p,m_uFunctionPointer.FloatSetfp)(Val);
00153         };
00154         void SetAttribute(bool Val,DerivedClass* p)
00155         {
00156                 CallMemberFunction(p,m_uFunctionPointer.BoolSetfp)(Val);
00157         };
00158         void SetAttribute(msdbDate Val,DerivedClass* p)
00159         {
00160                 CallMemberFunction(p,m_uFunctionPointer.DateSetfp)(Val);
00161         };
00162 
00163         CSetAttribute(char* sName,AttributeType iType):CAttribute(sName,iType){};
00164 private:
00165         CSetAttribute();
00166         FunctionPointers  m_uFunctionPointer;
00167 };
00168 
00169 
00170 //class that represents all of the get function pointers in your derived class  
00171 template<class DerivedClass> class CGetAttribute: public CAttribute
00172 {
00173 
00174 public:
00175         typedef int (DerivedClass::*intfp)(void) const;
00176     typedef short (DerivedClass::*shortfp)(void) const;
00177         typedef double (DerivedClass::*doublefp)(void) const;
00178         typedef char* (DerivedClass::*stringfp)(void) const;
00179         typedef float (DerivedClass::*floatfp)(void) const;
00180         typedef bool (DerivedClass::*boolfp)(void) const;
00181         typedef msdbDate (DerivedClass::*datefp)(void) const;
00182 
00183         union FunctionPointers
00184         {
00185                  intfp IntGetfp;
00186                  shortfp ShortGetfp;
00187                  doublefp DoubleGetfp;
00188                  stringfp StringGetfp;
00189                  floatfp FloatGetfp;
00190                  boolfp BoolGetfp;
00191                  datefp DateGetfp;
00192                 
00193         };
00194         CGetAttribute(char* sName,AttributeType iType,intfp p):CAttribute(sName,iType){m_uFunctionPointer.IntGetfp=p;};
00195         CGetAttribute(char* sName,AttributeType iType,shortfp p):CAttribute(sName,iType){m_uFunctionPointer.ShortGetfp=p;};
00196         CGetAttribute(char* sName,AttributeType iType,doublefp p):CAttribute(sName,iType){m_uFunctionPointer.DoubleGetfp=p;};
00197         CGetAttribute(char* sName,AttributeType iType,stringfp p):CAttribute(sName,iType){m_uFunctionPointer.StringGetfp=p;};
00198         CGetAttribute(char* sName,AttributeType iType,floatfp p):CAttribute(sName,iType){m_uFunctionPointer.FloatGetfp=p;};
00199         CGetAttribute(char* sName,AttributeType iType,boolfp p):CAttribute(sName,iType){m_uFunctionPointer.BoolGetfp=p;};
00200         CGetAttribute(char* sName,AttributeType iType,datefp p):CAttribute(sName,iType){m_uFunctionPointer.DateGetfp=p;};
00201 
00202         void GetAttribute(DerivedClass* p, int& Val)
00203         {
00204                 Val = CallMemberFunction(p,m_uFunctionPointer.IntGetfp )();
00205         };
00206         void GetAttribute(DerivedClass* p, short& Val)
00207         {
00208                 Val = CallMemberFunction(p,m_uFunctionPointer.ShortGetfp )();
00209         };
00210         void GetAttribute(DerivedClass* p, double& Val)
00211         {
00212                 Val = CallMemberFunction(p,m_uFunctionPointer.DoubleGetfp )();
00213         };
00214         void GetAttribute(DerivedClass* p, char*& Val)
00215         {
00216                 Val = CallMemberFunction(p,m_uFunctionPointer.StringGetfp )();
00217         };
00218         void GetAttribute(DerivedClass* p, float& Val)
00219         {
00220                 Val = CallMemberFunction(p,m_uFunctionPointer.FloatGetfp )();
00221         };
00222         void GetAttribute(DerivedClass* p, bool& Val)
00223         {
00224                 Val = CallMemberFunction(p,m_uFunctionPointer.BoolGetfp )();
00225         };
00226         void GetAttribute(DerivedClass* p, msdbDate& Val)
00227         {
00228                 Val = CallMemberFunction(p,m_uFunctionPointer.DateGetfp )();
00229         };
00230 
00231         CGetAttribute(char* sName,AttributeType iType):CAttribute(sName,iType){};
00232 private:
00233         CGetAttribute();
00234         FunctionPointers  m_uFunctionPointer;
00235 };
00236 
00237 
00238 //classes that wish to expose their attributes must inherit from this class
00239 // to implement, inherit from CExposeAttributes<yourclass>
00240 // each attribute you want to expose must have a get and set function
00241 // in your class's constructor, identify all attributes by using the appropriate macro
00242 //   eg:  SET_INT_ATTRIBUTE(youclass,name of your attribute, function name for the set function, function name for the get function)
00243 //   if you only have a get function, then you can expose that by using SET_INT_GET_ATTRIBUTE(youclass,name of your attribute,function name for the get function)
00244 //##ModelId=3DCBF9AF02E6
00248 template<class DerivedClass> class CExposeAttributes 
00249 {
00250         typedef std::list< CGetAttribute<DerivedClass> > GET_ATTRIBUTE_LIST;
00251         typedef std::list< CSetAttribute<DerivedClass> > SET_ATTRIBUTE_LIST;
00252         typedef typename GET_ATTRIBUTE_LIST::iterator GET_ATTRIBUTE_LIST_ITERATOR;
00253         typedef typename SET_ATTRIBUTE_LIST::iterator SET_ATTRIBUTE_LIST_ITERATOR;
00254         
00255 
00256 public:
00257         GET_ATTRIBUTE_LIST GetGetAttributes();
00258         SET_ATTRIBUTE_LIST GetSetAttributes();
00259 
00260         CGetAttribute<DerivedClass>* GetNextGetAttribute(bool bBegin=false)
00261         {
00262                 if (m_Gets.empty())
00263                         return NULL;
00264 
00265                 if (bBegin)
00266                 {
00267                         m_iGets = m_Gets.begin();
00268                         return &(*m_iGets);
00269                 }
00270 
00271                 m_iGets++;
00272                 if (m_iGets == m_Gets.end()) 
00273                         return NULL;
00274 
00275                 return &(*m_iGets);
00276         };
00277         CSetAttribute<DerivedClass>* GetNextSetAttribute(bool bBegin=false)
00278         {
00279                 if (m_Sets.empty())
00280                         return NULL;
00281 
00282                 if (bBegin)
00283                 {
00284                         m_iSets = m_Sets.begin();
00285                         return &(*m_iSets);
00286                 }
00287 
00288                 m_iSets++;
00289                 if (m_iSets == m_Sets.end()) 
00290                         return NULL;
00291 
00292                 return &(*m_iSets);
00293         };
00294         virtual void AddGetAttribute(const CGetAttribute<DerivedClass>& oAtt){m_Gets.push_back(oAtt);};
00295         virtual void AddSetAttribute(const CSetAttribute<DerivedClass>& oAtt){m_Sets.push_back(oAtt);};
00296 protected:
00297         GET_ATTRIBUTE_LIST m_Gets;
00298     GET_ATTRIBUTE_LIST_ITERATOR m_iGets;
00299         SET_ATTRIBUTE_LIST m_Sets;
00300         SET_ATTRIBUTE_LIST_ITERATOR m_iSets;
00301 };
00302         
00303 
00304 //int macros
00305 #define SET_INT_GET_ATTRIBUTE(classname,name,memberfunction) \
00306         {CGetAttribute<classname> oAtt(name,CAttribute::ATInt,memberfunction); \
00307         AddGetAttribute(oAtt);}
00308 #define SET_INT_SET_ATTRIBUTE(classname,name,memberfunction) \
00309         {CSetAttribute<classname> oAtt(name,CAttribute::ATInt,memberfunction); \
00310         AddSetAttribute(oAtt);}
00311 #define SET_INT_ATTRIBUTE(classname,name,setfunction,getfunction) SET_INT_SET_ATTRIBUTE(classname,name,setfunction) SET_INT_GET_ATTRIBUTE(classname,name,getfunction)
00312 
00313 
00314 //double macros
00315 #define SET_DOUBLE_GET_ATTRIBUTE(classname,name,memberfunction) \
00316         {CGetAttribute<classname> oAtt(name,CAttribute::ATDouble,memberfunction); \
00317         AddGetAttribute(oAtt);}
00318 #define SET_DOUBLE_SET_ATTRIBUTE(classname,name,memberfunction) \
00319         {CSetAttribute<classname> oAtt(name,CAttribute::ATDouble,memberfunction); \
00320         AddSetAttribute(oAtt);}
00321 #define SET_DOUBLE_ATTRIBUTE(classname,name,setfunction,getfunction) SET_DOUBLE_SET_ATTRIBUTE(classname,name,setfunction) SET_DOUBLE_GET_ATTRIBUTE(classname,name,getfunction)
00322 
00323 //short macros
00324 #define SET_SHORT_GET_ATTRIBUTE(classname,name,memberfunction) \
00325         {CGetAttribute<classname> oAtt(name,CAttribute::ATShort,memberfunction); \
00326         AddGetAttribute(oAtt);}
00327 #define SET_SHORT_SET_ATTRIBUTE(classname,name,memberfunction) \
00328         {CSetAttribute<classname> oAtt(name,CAttribute::ATShort,memberfunction); \
00329         AddSetAttribute(oAtt);}
00330 #define SET_SHORT_ATTRIBUTE(classname,name,setfunction,getfunction) SET_SHORT_SET_ATTRIBUTE(classname,name,setfunction) SET_SHORT_GET_ATTRIBUTE(classname,name,getfunction)
00331 
00332 
00333 //char String macros
00334 #define SET_STRING_GET_ATTRIBUTE(classname,name,memberfunction) \
00335         {CGetAttribute<classname> oAtt(name,CAttribute::ATString,memberfunction); \
00336         AddGetAttribute(oAtt);}
00337 #define SET_STRING_SET_ATTRIBUTE(classname,name,memberfunction) \
00338         {CSetAttribute<classname> oAtt(name,CAttribute::ATString,memberfunction); \
00339         AddSetAttribute(oAtt);}
00340 #define SET_STRING_ATTRIBUTE(classname,name,setfunction,getfunction) SET_STRING_SET_ATTRIBUTE(classname,name,setfunction) SET_STRING_GET_ATTRIBUTE(classname,name,getfunction)
00341 
00342 //Float macros
00343 #define SET_FLOAT_GET_ATTRIBUTE(classname,name,memberfunction) \
00344         {CGetAttribute<classname> oAtt(name,CAttribute::ATFloat,memberfunction); \
00345         AddGetAttribute(oAtt);}
00346 #define SET_FLOAT_SET_ATTRIBUTE(classname,name,memberfunction) \
00347         {CSetAttribute<classname> oAtt(name,CAttribute::ATFloat,memberfunction); \
00348         AddSetAttribute(oAtt);}
00349 #define SET_FLOAT_ATTRIBUTE(classname,name,setfunction,getfunction) SET_FLOAT_SET_ATTRIBUTE(classname,name,setfunction) SET_FLOAT_GET_ATTRIBUTE(classname,name,getfunction)
00350 
00351 //bool macros
00352 #define SET_BOOL_GET_ATTRIBUTE(classname,name,memberfunction) \
00353         {CGetAttribute<classname> oAtt(name,CAttribute::ATBool,memberfunction); \
00354         AddGetAttribute(oAtt);}
00355 #define SET_BOOL_SET_ATTRIBUTE(classname,name,memberfunction) \
00356         {CSetAttribute<classname> oAtt(name,CAttribute::ATBool,memberfunction); \
00357         AddSetAttribute(oAtt);}
00358 #define SET_BOOL_ATTRIBUTE(classname,name,setfunction,getfunction) SET_BOOL_SET_ATTRIBUTE(classname,name,setfunction) SET_BOOL_GET_ATTRIBUTE(classname,name,getfunction)
00359 
00360 //Date macros
00361 #define SET_DATE_GET_ATTRIBUTE(classname,name,memberfunction) \
00362         {CGetAttribute<classname> oAtt(name,CAttribute::ATDate,memberfunction); \
00363         AddGetAttribute(oAtt);}
00364 #define SET_DATE_SET_ATTRIBUTE(classname,name,memberfunction) \
00365         {CSetAttribute<classname> oAtt(name,CAttribute::ATDate,memberfunction); \
00366         AddSetAttribute(oAtt);}
00367 #define SET_DATE_ATTRIBUTE(classname,name,setfunction,getfunction) SET_DATE_SET_ATTRIBUTE(classname,name,setfunction) SET_DATE_GET_ATTRIBUTE(classname,name,getfunction)
00368 
00369 
00370 
00371 
00372 int WriteTableAttributes(char* schema, char* connstr, char* fname);
00373 int MSDAPIGenerator(char* schema, char* connstr, char* fname);
00374 int SoapDataGenerator(char* schema, char* connstr, char* fname);
00375 void get_info(char * schema, struct TableArray * p2ta, char* liststr);
00376 int GetTablesRelations(char* schema, struct TableArray * p2ta ,char* connstr);
00377 int GetDataModel(char* schema, struct TableArray * p2ta ,char* connstr);
00378 int LoadMetaData(char* schema,char* connstr);
00379 int MSDStructureModel(void);
00380 
00381 #endif //__MSD_METADATA_H__

Generated on Fri Apr 16 13:47:41 2004 for MSDAPI by doxygen 1.3.4-20031005