CkptRawDAO.h

Go to the documentation of this file.
00001 #ifndef RAWDAO_H_
00002 #define RAWDAO_H_
00003 
00004 #include "CkptDAO.h"
00005 #include "CkptByteArray.h"
00006 
00012 class RawOutputDAO : public OutputDAO {
00013  public:
00014   virtual ~RawOutputDAO() {}
00015   #define PROCESS_OUTPUT_PRIM(Prim) \
00016   virtual void processPrim(Prim &t) { \
00017     bArray.write(t); \
00018   };
00019 
00020   //PROCESS_OUTPUT_PRIM(bool)
00021   PROCESS_OUTPUT_PRIM(char)
00022   PROCESS_OUTPUT_PRIM(unsigned char)
00023   PROCESS_OUTPUT_PRIM(int)
00024   PROCESS_OUTPUT_PRIM(unsigned int)
00025   PROCESS_OUTPUT_PRIM(short)
00026   PROCESS_OUTPUT_PRIM(unsigned short)
00027   PROCESS_OUTPUT_PRIM(long)
00028   PROCESS_OUTPUT_PRIM(unsigned long)
00029   PROCESS_OUTPUT_PRIM(float)
00030   PROCESS_OUTPUT_PRIM(double)
00031   PROCESS_OUTPUT_PRIM(std::string)
00032  
00033   virtual void byteCopy(char* data, unsigned int dataSize) {
00034     bArray.write(dataSize);
00035     bArray.writeBytes(data, dataSize);
00036   };
00037   
00038   virtual DAOSerializable* processExternalObj(DAOSerializable* t) {
00039     //std::cout << "[OUTPUT] External object. type=" << t->getClassname() << std::endl;
00040     std::string cName = t->getClassname();
00041     bArray.write(cName);
00042     return t;   
00043   };
00044 
00045   virtual byte_array* getOutputData() { return &bArray; };
00046   
00047 private:
00048   byte_array bArray;
00049 };
00050 class RawInputDAO : public InputDAO{
00056  public:
00057   RawInputDAO() : InputDAO() { }
00058   RawInputDAO(byte_array *bA) : InputDAO(bA) { }
00059   virtual ~RawInputDAO() {}
00060 
00061   #define PROCESS_INPUT_PRIM(Prim, AccessFunc) \
00062   virtual void processPrim(Prim &t) { \
00063     t = bArray->AccessFunc(); \
00064   };
00065   
00066   //PROCESS_INPUT_PRIM(bool, readBool)
00067   PROCESS_INPUT_PRIM(char, readChar)
00068   PROCESS_INPUT_PRIM(unsigned char, readUChar)
00069   PROCESS_INPUT_PRIM(int, readInt)
00070   PROCESS_INPUT_PRIM(unsigned int, readUInt)
00071   PROCESS_INPUT_PRIM(short, readShort)
00072   PROCESS_INPUT_PRIM(unsigned short, readUShort)
00073   PROCESS_INPUT_PRIM(long, readLong)
00074   PROCESS_INPUT_PRIM(unsigned long, readULong)
00075   PROCESS_INPUT_PRIM(float, readFloat)
00076   PROCESS_INPUT_PRIM(double, readDouble)
00077   PROCESS_INPUT_PRIM(std::string, readString)
00078 
00079   virtual void byteCopy(char* data, unsigned int dataSize) {
00080     dataSize = bArray->readUInt();
00081     unsigned int actual = bArray->readBytes(data, dataSize);
00082     assert(actual == dataSize);
00083   };
00084  
00085   virtual DAOSerializable* processExternalObj(DAOSerializable* t) {
00086     std::string cName = bArray->readString();
00087     //std::cout << "[INPUT] External object. type=" << cName << std::endl;
00088     assert(ofMap[cName] != NULL);
00089     return (DAOSerializable*)ofMap[cName]();
00090   };
00091 
00092 };
00093 
00099 class RawDAOFactory : public DAOInterfaceFactory {
00100  public:
00101   DAOInterface* createInputDAO() { 
00102      return new DAOInterface(new RawInputDAO()); 
00103   };
00104   DAOInterface* createInputDAO(byte_array *bA) {
00105      return new DAOInterface(new RawInputDAO(bA));
00106   };
00107   DAOInterface* createOutputDAO() {
00108      return new DAOInterface(new RawOutputDAO);
00109   };
00110 };
00111 
00112 #endif /*RAWDAO_H_*/
00113 

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