Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

TextMsgEvent.cc

Go to the documentation of this file.
00001 #include "TextMsgEvent.h"
00002 #include <sstream>
00003 #include <libxml/tree.h>
00004 
00005 std::string
00006 TextMsgEvent::getDescription(bool showTypeSpecific/*=true*/, unsigned int verbosity/*=0*/) const {
00007   if(!showTypeSpecific)
00008     return EventBase::getDescription(showTypeSpecific,verbosity);
00009   std::ostringstream logdata;
00010   logdata << EventBase::getDescription(showTypeSpecific,verbosity) << '\t' << _text;
00011   return logdata.str();
00012 }
00013 
00014 unsigned int
00015 TextMsgEvent::getBinSize() const {
00016   unsigned int used=EventBase::getBinSize();
00017   if(saveFormat==XML)
00018     return used; //if using XML, the XMLLoadSave::getBinSize (called by EventBase::getBinSize) is all we need
00019   //otherwise need to add our own fields
00020   used+=creatorSize("EventBase::TextMsgEvent");
00021   used+=getSerializedSize(_text);
00022   //used+=sizeof(_token);
00023   return used;
00024 }
00025 
00026 unsigned int
00027 TextMsgEvent::loadBinaryBuffer(const char buf[], unsigned int len) {
00028   unsigned int origlen=len;
00029   if(!checkInc(EventBase::loadBinaryBuffer(buf,len),buf,len)) return 0;
00030   if(!checkCreatorInc("EventBase::TextMsgEvent",buf,len,true)) return 0;
00031   if(!decodeInc(_text,buf,len)) return 0;
00032   //if(!decodeInc(_token,buf,len)) return 0;
00033   //len-=used; buf+=used;
00034   return origlen-len; 
00035 }
00036 
00037 unsigned int
00038 TextMsgEvent::saveBinaryBuffer(char buf[], unsigned int len) const {
00039   unsigned int origlen=len;
00040   if(!checkInc(EventBase::saveBinaryBuffer(buf,len),buf,len)) return 0;
00041   if(!saveCreatorInc("EventBase::TextMsgEvent",buf,len)) return 0;
00042   if(!encodeInc(_text,buf,len)) return 0;
00043   //if(!encodeInc(_token,buf,len)) return 0;
00044   return origlen-len;
00045 }
00046 
00047 void TextMsgEvent::loadXML(xmlNode* node) {
00048   if(node==NULL)
00049     return;
00050   
00051   EventBase::loadXML(node);
00052   
00053   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; cur = skipToElement(cur->next)) {
00054     if(xmlStrcmp(cur->name, (const xmlChar *)"param"))
00055       continue;
00056     
00057     xmlChar * name = xmlGetProp(cur,(const xmlChar*)"name");
00058     if(name==NULL)
00059       throw bad_format(cur,"property missing name");
00060     
00061     xmlChar * val = xmlGetProp(cur,(const xmlChar*)"value");
00062     if(val==NULL)
00063       throw bad_format(cur,"property missing value");
00064     
00065     if(xmlStrcmp(name, (const xmlChar *)"text")==0)
00066       _text=(const char*)val;
00067     
00068     xmlFree(val);
00069     xmlFree(name);
00070   }
00071 }
00072 
00073 void TextMsgEvent::saveXML(xmlNode * node) const {
00074   if(node==NULL)
00075     return;
00076   EventBase::saveXML(node);
00077   
00078   //clear old params first
00079   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; ) {
00080     if(xmlStrcmp(cur->name, (const xmlChar *)"param")==0) {
00081       xmlUnlinkNode(cur);
00082       xmlFreeNode(cur);
00083       cur = skipToElement(node->children); //restart the search (boo)
00084     } else
00085       cur = skipToElement(cur->next);
00086   }
00087   
00088   xmlNode* cur=xmlNewChild(node,NULL,(const xmlChar*)"param",NULL);
00089   if(cur==NULL)
00090     throw bad_format(node,"Error: VisionObjectEvent xml error on saving param");
00091   xmlSetProp(cur,(const xmlChar*)"name",(const xmlChar*)"text");
00092   xmlSetProp(cur,(const xmlChar*)"value",(const xmlChar*)_text.c_str());
00093 }
00094 
00095 /*! @file
00096  * @brief Implements TextMsgEvent, which extends EventBase to also include actual message text
00097  * @author ejt (Creator)
00098  *
00099  * $Author: ejt $
00100  * $Name: tekkotsu-3_0 $
00101  * $Revision: 1.4 $
00102  * $State: Exp $
00103  * $Date: 2006/09/09 04:32:48 $
00104  */

Tekkotsu v3.0
Generated Wed Oct 4 00:03:46 2006 by Doxygen 1.4.7