Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LookoutEvents.cc

Go to the documentation of this file.
00001 #include "LookoutEvents.h"
00002 
00003 #include <sstream>
00004 #include <libxml/tree.h>
00005 #include <iostream>
00006 
00007 using namespace std;
00008 
00009 //================ LookoutPointAtEvent
00010 
00011 std::string
00012 LookoutPointAtEvent::getDescription(bool showTypeSpecific/*=true*/, unsigned int verbosity/*=0*/) const {
00013   if(!showTypeSpecific)
00014     return EventBase::getDescription(showTypeSpecific,verbosity);
00015   std::ostringstream logdata;
00016   logdata << EventBase::getDescription(showTypeSpecific,verbosity)
00017     << "toBaseMatrix=" << NEWMAT::printmat(toBaseMatrix);
00018   return logdata.str();
00019 }
00020 
00021 unsigned int
00022 LookoutPointAtEvent::getBinSize() const {
00023   unsigned int used=EventBase::getBinSize();
00024   if(saveFormat==XML)
00025     return used; //if using XML, the XMLLoadSave::getBinSize (called by EventBase::getBinSize) is all we need
00026   //otherwise need to add our own fields
00027   used+=creatorSize("EventBase::LookoutPointAtEvent");
00028   used+=sizeof(toBaseMatrix);
00029   return used;
00030 }
00031 
00032 unsigned int
00033 LookoutPointAtEvent::loadBinaryBuffer(const char buf[], unsigned int len) {
00034   unsigned int origlen=len;
00035   unsigned int used;
00036   if(0==(used=EventBase::loadBinaryBuffer(buf,len))) return 0;
00037   len-=used; buf+=used;
00038   if(0==(used=checkCreator("EventBase::LookoutPointAtEvent",buf,len,true))) return 0;
00039   len-=used; buf+=used;
00040   for (int i = 0; i < 16; i++) {
00041     if(0==(used=decode(toBaseMatrix(1+i/4,1+(i%4)),buf,len))) return 0;
00042     len-=used; buf+=used;
00043   }
00044   return origlen-len; 
00045 }
00046 
00047 unsigned int
00048 LookoutPointAtEvent::saveBinaryBuffer(char buf[], unsigned int len) const {
00049   unsigned int origlen=len;
00050   unsigned int used;
00051   if(0==(used=EventBase::saveBinaryBuffer(buf,len))) return 0;
00052   len-=used; buf+=used;
00053   if(0==(used=saveCreator("EventBase::LookoutPointAtEvent",buf,len))) return 0;
00054   len-=used; buf+=used;
00055   for (int i = 0; i < 16; i++) {
00056     if(0==(used=encode(toBaseMatrix(1+i/4,1+(i%4)),buf,len))) return 0;
00057     len-=used; buf+=used;
00058   }
00059   return origlen-len;
00060 }
00061 
00062 void LookoutPointAtEvent::loadXML(xmlNode* node) {
00063   if(node==NULL)
00064     return;
00065   
00066   EventBase::loadXML(node);
00067   
00068   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; cur = skipToElement(cur->next)) {
00069     if(xmlStrcmp(cur->name, (const xmlChar *)"param"))
00070       continue;
00071     
00072     xmlChar * name = xmlGetProp(cur,(const xmlChar*)"name");
00073     if(name==NULL)
00074       throw bad_format(cur,"property missing name");
00075     
00076     xmlChar * val = xmlGetProp(cur,(const xmlChar*)"value");
00077     if(val==NULL)
00078       throw bad_format(cur,"property missing value");
00079     
00080     cout << "loadXML: " << name << "=" << val << endl;
00081     
00082     if(xmlStrcmp(name, (const xmlChar *)"toBaseMatrix")==0) {
00083       const string valStr = (const char*) val;
00084       string::size_type pos = valStr.find_first_of(' ', 0);
00085       string::size_type prev_pos = ++pos;
00086       for (unsigned int i = 0; i < 16; i++) {
00087   pos = valStr.find_first_of(' ', pos);
00088   toBaseMatrix(1+i/4,1+(i%4)) = atof(valStr.substr(prev_pos, pos-prev_pos).c_str());
00089   prev_pos = ++pos;
00090   if (prev_pos == string::npos)
00091     break;
00092       }
00093     }
00094     
00095     xmlFree(val);
00096     xmlFree(name);
00097   }
00098 }
00099 
00100 void LookoutPointAtEvent::saveXML(xmlNode * node) const {
00101   if(node==NULL)
00102     return;
00103   EventBase::saveXML(node);
00104   
00105   //clear old params first
00106   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; ) {
00107     if(xmlStrcmp(cur->name, (const xmlChar *)"param")==0) {
00108       xmlUnlinkNode(cur);
00109       xmlFreeNode(cur);
00110       cur = skipToElement(node->children); //restart the search (boo)
00111     } else
00112       cur = skipToElement(cur->next);
00113   }
00114   
00115   //  cout << "saveXML: " << toBaseMatrix << endl;
00116 
00117   xmlNode* cur=xmlNewChild(node,NULL,(const xmlChar*)"param",NULL);
00118   if(cur==NULL)
00119     throw bad_format(node,"Error: LookoutPointAtEvent xml error on saving param");
00120   xmlSetProp(cur,(const xmlChar*)"name",(const xmlChar*)"toBaseMatrix");
00121   std::ostringstream valbuf;
00122   for (int i = 0; i < 16; i++)
00123     valbuf << toBaseMatrix(1+i/4,1+(i%4)) << ' ';
00124   xmlSetProp(cur,(const xmlChar*)"value",(const xmlChar*)valbuf.str().c_str());
00125 }
00126 
00127 
00128 //================ LookoutIREvent
00129 
00130 std::string
00131 LookoutIREvent::getDescription(bool showTypeSpecific/*=true*/, unsigned int verbosity/*=0*/) const {
00132   if(!showTypeSpecific)
00133     return LookoutPointAtEvent::getDescription(showTypeSpecific,verbosity);
00134   std::ostringstream logdata;
00135   logdata << LookoutPointAtEvent::getDescription(showTypeSpecific,verbosity)
00136     << '\t' << distance;
00137   return logdata.str();
00138 }
00139 
00140 unsigned int
00141 LookoutIREvent::getBinSize() const {
00142   unsigned int used=LookoutPointAtEvent::getBinSize();
00143   if(saveFormat==XML)
00144     return used; //if using XML, the XMLLoadSave::getBinSize (called by LookoutPointAtEvent::getBinSize) is all we need
00145   //otherwise need to add our own fields
00146   used+=creatorSize("LookoutPointAtEvent::LookoutIREvent");
00147   used+=sizeof(distance);
00148   return used;
00149 }
00150 
00151 unsigned int
00152 LookoutIREvent::loadBinaryBuffer(const char buf[], unsigned int len) {
00153   unsigned int origlen=len;
00154   unsigned int used;
00155   if(0==(used=LookoutPointAtEvent::loadBinaryBuffer(buf,len))) return 0;
00156   len-=used; buf+=used;
00157   if(0==(used=checkCreator("LookoutPointAtEvent::LookoutIREvent",buf,len,true))) return 0;
00158   len-=used; buf+=used;
00159   if(0==(used=decode(distance,buf,len))) return 0;
00160   len-=used; buf+=used;
00161   return origlen-len; 
00162 }
00163 
00164 unsigned int
00165 LookoutIREvent::saveBinaryBuffer(char buf[], unsigned int len) const {
00166   unsigned int origlen=len;
00167   unsigned int used;
00168   if(0==(used=LookoutPointAtEvent::saveBinaryBuffer(buf,len))) return 0;
00169   len-=used; buf+=used;
00170   if(0==(used=saveCreator("LookoutPointAtEvent::LookoutIREvent",buf,len))) return 0;
00171   len-=used; buf+=used;
00172   if(0==(used=encode(distance,buf,len))) return 0;
00173   len-=used; buf+=used;
00174   return origlen-len;
00175 }
00176 
00177 void LookoutIREvent::loadXML(xmlNode* node) {
00178   if(node==NULL)
00179     return;
00180   
00181   LookoutPointAtEvent::loadXML(node);
00182   
00183   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; cur = skipToElement(cur->next)) {
00184     if(xmlStrcmp(cur->name, (const xmlChar *)"param"))
00185       continue;
00186     
00187     xmlChar * name = xmlGetProp(cur,(const xmlChar*)"name");
00188     if(name==NULL)
00189       throw bad_format(cur,"property missing name");
00190     
00191     xmlChar * val = xmlGetProp(cur,(const xmlChar*)"value");
00192     if(val==NULL)
00193       throw bad_format(cur,"property missing value");
00194     
00195     cout << "loadXML: " << name << "=" << val << endl;
00196     
00197     
00198     if(xmlStrcmp(name, (const xmlChar *)"distance")==0)
00199       distance=atof((const char*)val);
00200     
00201     xmlFree(val);
00202     xmlFree(name);
00203   }
00204 }
00205 
00206 void LookoutIREvent::saveXML(xmlNode * node) const {
00207   if(node==NULL)
00208     return;
00209   LookoutPointAtEvent::saveXML(node);
00210   
00211   //clear old params first
00212   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; ) {
00213     if(xmlStrcmp(cur->name, (const xmlChar *)"param")==0) {
00214       xmlUnlinkNode(cur);
00215       xmlFreeNode(cur);
00216       cur = skipToElement(node->children); //restart the search (boo)
00217     } else
00218       cur = skipToElement(cur->next);
00219   }
00220 
00221   xmlNode* cur=xmlNewChild(node,NULL,(const xmlChar*)"param",NULL);
00222   if(cur==NULL)
00223     throw bad_format(node,"Error: LocomotionEvent xml error on saving param");
00224   xmlSetProp(cur,(const xmlChar*)"name",(const xmlChar*)"distance");
00225   char valbuf[20];
00226   snprintf(valbuf,20,"%g",distance);
00227   xmlSetProp(cur,(const xmlChar*)"value",(const xmlChar*)valbuf);
00228 }

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