iSpike
2.1
Spike conversion library for robotics
|
00001 //iSpike includes 00002 #include "iSpike/ISpikeException.hpp" 00003 #include <iSpike/Writer/WriterFactory.hpp> 00004 #include <iSpike/Writer/AngleWriter.hpp> 00005 #include <iSpike/Writer/YarpAngleWriter.hpp> 00006 #include <iSpike/Writer/FileAngleWriter.hpp> 00007 #include "iSpike/Log/Log.hpp" 00008 using namespace ispike; 00009 00012 WriterFactory::WriterFactory(){ 00013 //Store list of available writers 00014 writerList.push_back(FileAngleWriter().getWriterDescription()); 00015 printWriters(); 00016 } 00017 00018 00020 WriterFactory::WriterFactory(string ip, unsigned port){ 00021 //Store list of available writers 00022 writerList.push_back(FileAngleWriter().getWriterDescription()); 00023 writerList.push_back(YarpAngleWriter(ip, port).getWriterDescription()); 00024 printWriters(); 00025 00026 //Store variables 00027 this->ip = ip; 00028 this->port = port; 00029 } 00030 00031 00032 /*--------------------------------------------------------------------*/ 00033 /*--------- PUBLIC METHODS -------*/ 00034 /*--------------------------------------------------------------------*/ 00035 00037 vector<Description> WriterFactory::getWritersOfType(string writerType){ 00038 vector<Description> result; 00039 for(unsigned i = 0; i < writerList.size(); i++){ 00040 if(writerList[i].getType() == writerType) 00041 result.push_back(writerList[i]); 00042 } 00043 return result; 00044 } 00045 00046 00048 map<string, Property> WriterFactory::getDefaultProperties(Description& desc){ 00049 if(desc.getName() == "File Angle Writer") { 00050 return FileAngleWriter().getProperties(); 00051 } 00052 else if(desc.getName() == "Yarp Angle Writer") { 00053 return YarpAngleWriter(this->ip, this->port).getProperties(); 00054 } 00055 throw ISpikeException("Invalid writer"); 00056 } 00057 00058 00060 Writer* WriterFactory::create(Description& desc, map<string, Property>& writerProperties){ 00061 Writer* result; 00062 if(desc.getName() == "File Angle Writer") { 00063 result = new FileAngleWriter(); 00064 } 00065 else if(desc.getName() == "Yarp Angle Writer") { 00066 result = new YarpAngleWriter(this->ip, this->port); 00067 } 00068 else { 00069 throw ISpikeException("Invalid writer"); 00070 } 00071 result->initialize(writerProperties); 00072 return result; 00073 } 00074 00075 00076 /*--------------------------------------------------------------------*/ 00077 /*--------- PRIVATE METHODS -------*/ 00078 /*--------------------------------------------------------------------*/ 00079 00081 void WriterFactory::printWriters(){ 00082 for(size_t i=0; i<writerList.size(); ++i) 00083 LOG(LOG_DEBUG)<<"Writer: "<<writerList[i].getName()<<", "<<writerList[i].getDescription(); 00084 }