Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduEventBase.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include "KoduSayEvent.h"
00004 
00005 using namespace std;
00006 
00007 const char* KoduEventBase::classID = "EventBase::KoduEvent";
00008 
00009 KoduEventBase* KoduEventBase::getInstance(const char buf[], unsigned int size) {
00010   KoduEventBase eb;
00011   if (!eb.checkInc((int)eb.loadBinaryBuffer(buf,size), buf, size)) {
00012       cout << "Error: Received event is not a KoduEvent" << endl;
00013       return NULL;
00014     }
00015 
00016     if (eb.checkCreator(KoduSayEvent::classID, buf, size, false)) {
00017       return new KoduSayEvent();
00018     }
00019     else
00020       return NULL;
00021 }
00022 
00023 int KoduEventBase::getDestination() {
00024     return _destID;
00025 }
00026 
00027 void KoduEventBase::setDestination(int destID) {
00028     _destID = destID;
00029 }
00030 
00031 std::string KoduEventBase::getDescription(bool showTypeSpecific, unsigned int verbosity) const {
00032     if ( !showTypeSpecific )
00033         return EventBase::getDescription(showTypeSpecific,verbosity);
00034     std::ostringstream logdata;
00035     logdata << EventBase::getDescription(showTypeSpecific,verbosity) << '\t' << "KoduEventBase" << '\t' << _destID;
00036     return logdata.str();
00037 }
00038 
00039 unsigned int KoduEventBase::getBinSize() const {
00040     unsigned int used=EventBase::getBinSize();
00041     if(saveFormat==XML)
00042         return used; //if using XML, the XMLLoadSave::getBinSize (called by EventBase::getBinSize) is all we need
00043     //otherwise need to add our own fields
00044     used+=creatorSize(KoduEventBase::classID);
00045     used+=getSerializedSize(_destID);
00046     return used;
00047 }
00048 
00049 unsigned int KoduEventBase::saveBinaryBuffer(char buf[], unsigned int len) const {
00050     unsigned int origlen=len;
00051     if (!checkInc(EventBase::saveBinaryBuffer(buf,len),buf,len)) return 0;
00052     if (!saveCreatorInc(KoduEventBase::classID,buf,len)) return 0;
00053     if (!encodeInc(_destID,buf,len)) return 0;
00054     return origlen-len;
00055 }
00056 
00057 unsigned int KoduEventBase::loadBinaryBuffer(const char buf[], unsigned int len) {
00058     unsigned int origlen = len;
00059     if (!checkInc(EventBase::loadBinaryBuffer(buf,len),buf,len)) return 0;
00060     if (!checkCreatorInc(KoduEventBase::classID,buf,len,true)) return 0;
00061     if (!decodeInc(_destID,buf,len)) return 0;
00062     return origlen-len; 
00063 }
00064 
00065 /**
00066  * @file
00067  *
00068  * @brief Events involved with the Kodu Interpreter
00069  *
00070  * @author afranchu
00071  * @author medee
00072  */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3