CkptDAO.h

Go to the documentation of this file.
00001 #ifndef CKPTDAO_H_
00002 #define CKPTDAO_H_
00003 
00004 #include "CkptTypeRegistry.h"
00005 #include "CkptByteArray.h"
00006 #include <string>
00007 
00008 class DAOInterface;
00009 
00018 class DAOSerializable {
00019  public:
00020   virtual void serialize(DAOInterface &dao)=0;
00021   virtual char* getClassname()=0;
00022 };
00023 
00024 enum DAOMode { DAO_INPUT, DAO_OUTPUT };
00025 
00036 class CommonDAO {
00037  public:
00038   #define DECLARE_BUILTIN_PRIM(PRIMITIVE_TYPE) \
00039    virtual void processPrim(PRIMITIVE_TYPE &t)=0;
00040 
00041   //DECLARE_BUILTIN_PRIM(bool)
00042   DECLARE_BUILTIN_PRIM(char)
00043   DECLARE_BUILTIN_PRIM(unsigned char)
00044   DECLARE_BUILTIN_PRIM(int)
00045   DECLARE_BUILTIN_PRIM(unsigned int)
00046   DECLARE_BUILTIN_PRIM(short)
00047   DECLARE_BUILTIN_PRIM(unsigned short)
00048   DECLARE_BUILTIN_PRIM(long)
00049   DECLARE_BUILTIN_PRIM(unsigned long)
00050   DECLARE_BUILTIN_PRIM(float)
00051   DECLARE_BUILTIN_PRIM(double)
00052   DECLARE_BUILTIN_PRIM(std::string)
00053   
00054   virtual void byteCopy(char* data, unsigned int dataSize)=0;
00055   virtual DAOSerializable* processExternalObj(DAOSerializable* t)=0;
00056   virtual DAOMode getMode()=0;
00057 };
00058 
00064 class InputDAO : public CommonDAO {
00065  public:
00066   InputDAO() : bArray(NULL) { };
00067   InputDAO(byte_array* bA) : bArray(bA) { };
00068   void setInputData(byte_array* bA) { bArray = bA; };
00069   virtual DAOMode getMode() { return DAO_INPUT; };
00070  protected:
00071   byte_array* bArray;
00072 };
00073 
00079  class OutputDAO : public CommonDAO {
00080  public:
00081    virtual DAOMode getMode() { return DAO_OUTPUT; };
00083    virtual byte_array* getOutputData()=0;
00084 };
00085 
00086 
00097 class DAOInterface {
00098  public:
00099   DAOInterface(CommonDAO *daoImpl) : impl(daoImpl) { };
00100   virtual ~DAOInterface() { delete impl; };
00101   virtual DAOMode getMode() { return impl->getMode(); };
00102 
00103   #define PROCESS_IFACE_PRIM(PRIMITIVE) \
00104   DAOInterface& operator&(PRIMITIVE & t) { \
00105      impl->processPrim(t); \
00106      return *this; \
00107    }; 
00108    
00109   PROCESS_IFACE_PRIM(char)
00110   PROCESS_IFACE_PRIM(unsigned char)
00111   PROCESS_IFACE_PRIM(int)
00112   PROCESS_IFACE_PRIM(unsigned int)
00113   PROCESS_IFACE_PRIM(short)
00114   PROCESS_IFACE_PRIM(unsigned short)
00115   PROCESS_IFACE_PRIM(long)
00116   PROCESS_IFACE_PRIM(unsigned long)
00117   PROCESS_IFACE_PRIM(float)
00118   PROCESS_IFACE_PRIM(double)
00119   PROCESS_IFACE_PRIM(std::string)
00120 
00136   template<class RawObj>
00137   DAOInterface& byteCopy(RawObj *obj, unsigned int dataSize) {
00138     impl->byteCopy((char*)obj, dataSize);
00139     return *this;
00140   };
00141 
00154   DAOInterface& operator&(DAOSerializable &t) {
00155     t.serialize(*this);
00156     return *this;
00157   };
00158 
00159   byte_array* getOutputData() {
00160     if (getMode() == DAO_OUTPUT) return ((OutputDAO*)impl)->getOutputData();
00161     return NULL;
00162   };
00163   
00186   template<class ExtClass>
00187   void invokeExternalSerializer(ExtClass &extObj, void (*eS)(DAOInterface&,ExtClass&)) {
00188      eS(*this, extObj);
00189   }
00190   
00191 
00197   template<class Serializable>
00198   DAOInterface& operator&(Serializable* & t) {
00199     t = (Serializable*)impl->processExternalObj((DAOSerializable*)t);
00200     t->serialize(*this);
00201     return *this;
00202   };
00203 
00204  private:
00205   CommonDAO* impl;
00206 };
00207 
00214 class DAOInterfaceFactory {
00215  public:
00216   virtual DAOInterface* createInputDAO()=0;
00217   virtual DAOInterface* createOutputDAO()=0;
00218 };
00219 
00220 #endif /*CKPTDAO_H_*/
00221 

Generated on Fri Apr 27 17:20:01 2007 for aiscoal by  doxygen 1.5.2