Introduction Manual Class Reference Header Reference

zoidcom_replicator_memblock.h

Go to the documentation of this file.
00001 /****************************************
00002 * zoidcom_replicator_memblock.h
00003 * memory chunk replicator
00004 *
00005 * This file is part of the "Zoidcom Automated Networking System" application library.
00006 * Copyright (C)2002-2007 by Jörg Rüppel. See documentation for copyright and licensing details.
00007 *****************************************/
00008 
00009 
00010 #ifndef _ZOIDREPLICATORMEMBLOCK_H_
00011 #define _ZOIDREPLICATORMEMBLOCK_H_
00012 
00016 #include "zoidcom.h"
00017 
00024 class ZCom_Replicate_Memblock : public ZCom_ReplicatorBasic
00025 {
00026 private:
00027   char*     m_ptr;
00028   char*     m_cmp;
00029   zU16      m_size;
00030 public:
00032   ZCOM_API ZCom_Replicate_Memblock(void *_data, zU16 _size, ZCom_ReplicatorSetup *_setup) : ZCom_ReplicatorBasic(_setup)
00033   {
00034     m_ptr = (char*) _data;
00035     m_cmp = new char[_size];
00036     if (!m_cmp)
00037       return;
00038     m_size = _size;
00039     m_flags |= ZCOM_REPLICATOR_INITIALIZED;
00040   }
00041 
00043   ZCOM_API ZCom_Replicate_Memblock(void *_data, zU16 _size, zU8 _flags, zU8 _rules, zU8 _intercept_id = 0, zS16 _mindelay = -1, zS16 _maxdelay = -1) : ZCom_ReplicatorBasic(NULL)
00044   {
00045     // make sure m_setup will be deleted when the replicator is deleted
00046     _flags |= ZCOM_REPFLAG_SETUPAUTODELETE;
00047 
00048     // create the setup object
00049     m_setup = new ZCom_ReplicatorSetup(_flags, _rules, _intercept_id, _mindelay, _maxdelay);
00050 
00051     // out of mem
00052     if (!m_setup)
00053       return;
00054 
00055     m_ptr = (char*) _data;
00056     m_cmp = new char[_size];
00057     if (!m_cmp)
00058       return;
00059     memcpy(m_cmp, m_ptr, m_size);
00060     m_size = _size;
00061     m_flags |= ZCOM_REPLICATOR_INITIALIZED;
00062   }
00063 
00064   ZCOM_API ~ZCom_Replicate_Memblock()
00065   {
00066     if (m_cmp) delete []m_cmp;
00067   }
00068 
00069   ZCOM_API bool checkState() {
00070     // compare
00071     bool s = (memcmp(m_ptr, m_cmp, m_size) == 0);
00072     // if changed, update the comparison
00073     if (!s) memcpy(m_cmp, m_ptr, m_size);
00074     // return result
00075     return s;
00076   }
00077 
00078   ZCOM_API void packData(ZCom_BitStream *_stream) {
00079     // add data to stream
00080     _stream->addBuffer(m_ptr, m_size);
00081   }
00082   ZCOM_API void unpackData(ZCom_BitStream *_stream, bool _store, zU32 _estimated_time_sent) {
00083     // shall we store
00084     if (_store)
00085       _stream->getBuffer(m_ptr, m_size);
00086     // or just skip the data in the stream?
00087     else
00088       _stream->skipBuffer(m_size);
00089   }
00090 
00091   ZCOM_API void* peekData() {
00092     // check if peekData is really called from within an interceptor
00093     assert(getPeekStream());
00094     // allocate memory as peekbuffer
00095     char *buf = new char[m_size];
00096     if (!buf)
00097       return NULL;
00098 
00099     // read data into the buffer
00100     getPeekStream()->getBuffer(buf, m_size);
00101     // let zoidcom store the pointer to the buffer so we can delete it later
00102     peekDataStore(buf);
00103     // return the buffer so the caller can look at the data
00104     return buf;
00105   }
00106 
00107   ZCOM_API void clearPeekData() {
00108     // get the data we allocated above
00109     char *buf = (char*) peekDataRetrieve();
00110     // and delete it
00111     if (buf) delete []buf;
00112   };
00113 
00114   ZCOM_API void Process(eZCom_NodeRole _localrole, zU32 _simulation_time_passed) {};
00115 };
00116 
00117 #endif

This file is part of the documentation for Zoidcom. Documentation copyright © 2004-2008 by Jörg Rüppel. Generated on Sat Aug 16 15:26:49 2008 for Zoidcom by doxygen 1.4.6-NO