00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __T_PROTO_H__
00016 #define __T_PROTO_H__
00017
00018 template<class T> class Proto;
00019
00020
00021 #include <cProtoBase.h>
00022
00023
00024 #include <tResult.h>
00025 #include <tRef.h>
00026
00027 template<class T> class Proto: public ProtoBase
00028 {
00029 public:
00030 Result<T> * operator() (const QueRefProto &_q,class Connection * _c) {return ((Result<T> *)ExecuteQuery(_q,_c,1,new Result<T>));};
00031 Proto<T>();
00032 ~Proto<T>() {};
00033 virtual const char* RootClassName() {return T::RootClassName()?T::RootClassName():T::ClassName();};
00034 virtual const char* BaseClassName() {return T::BaseClassName();};
00035 virtual const char* ClassName() {return T::ClassName();};
00036 virtual const char* ParentClassNames() {return T::ParentClassNames();};
00037 virtual const char* From() {return T::From();};
00038 virtual const char* GroupBy() {return T::GroupBy();};
00039 virtual const char* Having() {return T::Having();};
00040 virtual const char* OrderBy() const {return T::OrderBy();};
00041 virtual class Object * New() const {return (Object *)T::_New();};
00042 virtual class RefBase *NewRef() {return new Ref<T>;};
00043 protected:
00044 virtual void _MapKey(int i, const char *&attr, unsigned char Object::*&mem, const char *&col, char &type, unsigned int &len, bool &rw){T::MapKey(i,attr,mem,col,type,len,rw);};
00045 virtual void _Map(int i, const char *&attr, unsigned char Object::*&mem, const char *&col, char &type, unsigned int &len, bool &rw){T::Map(i,attr,mem,col,type,len,rw);};
00046 virtual const char* _ProtoTWhere() {return T::Where();};
00047 virtual const char* _ProtoTGroupBy() {return T::GroupBy();};
00048 virtual const char* _ProtoTHaving() {return T::Having();};
00049 };
00050
00051 template <class T> Proto<T>::Proto() :
00052 ProtoBase()
00053 {
00054 Register(this, T::ClassName());
00055 _rootPrototype=Find(RootClassName());
00056 if (!_rootPrototype)
00057 _rootPrototype=Find(T::ClassName());
00058
00059
00060 char * _rootpk = NULL;
00061 char * _classpk = NULL;
00062 const char *atr;
00063 unsigned char Object::*mem;
00064 const char *col;
00065 char *trimcol = NULL;
00066 char ctype;
00067 unsigned int clen;
00068 bool crw;
00069 int i = 0;
00070 const char * delim = NULL;
00071 ((Proto<T>*)_rootPrototype)->_MapKey(i,atr,mem,col,ctype,clen,crw);
00072 while (ctype!='?')
00073 {
00074 StrCpy(trimcol,col);
00075 StrPrefixCut(trimcol,'.');
00076 StrCat(_rootpk,4,delim,_rootPrototype->From(),".",trimcol);
00077 StrFree(trimcol);
00078 delim = ", ";
00079 i++;
00080 ((Proto<T>*)_rootPrototype)->_MapKey(i,atr,mem,col,ctype,clen,crw);
00081 };
00082 i = 0;
00083 delim = NULL;
00084 _MapKey(i,atr,mem,col,ctype,clen,crw);
00085 while (ctype!='?')
00086 {
00087 StrCpy(trimcol,col);
00088 StrPrefixCut(trimcol,'.');
00089 StrCat(_classpk,2,delim,trimcol);
00090 StrFree(trimcol);
00091 delim = ", ";
00092 i++;
00093 _MapKey(i,atr,mem,col,ctype,clen,crw);
00094 };
00095 StrCat(_condition,7,
00096 "(",_rootpk,") IN (SELECT ",_classpk," FROM ",From(),")"
00097 );
00098 StrFree(_rootpk);
00099 StrFree(_classpk);
00100
00101 };
00102
00103 #endif //__T_PROTO_H__