iSpike  2.1
Spike conversion library for robotics
D:/Home/Programs/iSpike/src/Reader/ReaderFactory.cpp
Go to the documentation of this file.
00001 //iSpike includes
00002 #include <iSpike/Reader/ReaderFactory.hpp>
00003 #include <iSpike/Reader/AngleReader.hpp>
00004 #include <iSpike/Reader/FileAngleReader.hpp>
00005 #include <iSpike/Reader/FileVisualReader.hpp>
00006 #include <iSpike/Reader/YarpAngleReader.hpp>
00007 #include <iSpike/Reader/YarpVisualReader.hpp>
00008 #include "iSpike/ISpikeException.hpp"
00009 #include "iSpike/Log/Log.hpp"
00010 using namespace ispike;
00011 
00012 //Other includes
00013 #include <iostream>
00014 using namespace std;
00015 
00018 ReaderFactory::ReaderFactory(){
00019         this->readerList.push_back(FileAngleReader().getReaderDescription());
00020         this->readerList.push_back(FileVisualReader().getReaderDescription());
00021         printReaders();
00022 }
00023 
00024 
00026 ReaderFactory::ReaderFactory(string ip, unsigned port){
00027         this->readerList.push_back(FileAngleReader().getReaderDescription());
00028         this->readerList.push_back(FileVisualReader().getReaderDescription());
00029         this->readerList.push_back(YarpAngleReader(ip, port).getReaderDescription());
00030         this->readerList.push_back(YarpVisualReader(ip, port).getReaderDescription());
00031         printReaders();
00032 
00033         this->ip = ip;
00034         this->port = port;
00035 }
00036 
00037 
00038 /*--------------------------------------------------------------------*/
00039 /*---------                 PUBLIC METHODS                     -------*/
00040 /*--------------------------------------------------------------------*/
00041 
00043 vector<Description> ReaderFactory::getReadersOfType(string readerType){
00044         vector<Description> result;
00045         for(unsigned i = 0; i < readerList.size(); i++) {
00046                 if(readerList[i].getType() == readerType)
00047                         result.push_back(readerList[i]);
00048         }
00049         return result;
00050 }
00051 
00052 
00054 map<string, Property> ReaderFactory::getDefaultProperties(Description& desc){
00055         if(desc.getName() == "File Angle Reader") {
00056                 return FileAngleReader().getProperties();
00057         }
00058         else if(desc.getName() == "File Visual Reader"){
00059                 return FileVisualReader().getProperties();
00060         }
00061         else if(desc.getName() == "Yarp Angle Reader") {
00062                 return YarpAngleReader(ip, port).getProperties();
00063         }
00064         else if(desc.getName() == "Yarp Visual Reader"){
00065                 return YarpVisualReader(ip, port).getProperties();
00066         }
00067         throw ISpikeException("Invalid writer");
00068 }
00069 
00070 
00072 Reader* ReaderFactory::create(Description& desc, map<string, Property>& readerProperties){
00073         Reader* result;
00074         if(desc.getName() == "File Angle Reader") {
00075                 result = new FileAngleReader();
00076         }
00077         else if(desc.getName() == "File Visual Reader"){
00078                 result = new FileVisualReader();
00079         }
00080         else if(desc.getName() == "Yarp Angle Reader") {
00081                 result = new YarpAngleReader(ip, port);
00082         }
00083         else if(desc.getName() == "Yarp Visual Reader"){
00084                 result = new YarpVisualReader(ip, port);
00085         }
00086         else {
00087                 throw ISpikeException("Invalid reader type");
00088         }
00089         result->initialize(readerProperties);
00090         return result;
00091 }
00092 
00093 
00094 /*--------------------------------------------------------------------*/
00095 /*---------                 PUBLIC METHODS                     -------*/
00096 /*--------------------------------------------------------------------*/
00097 
00099 void ReaderFactory::printReaders(){
00100         for(size_t i=0; i<readerList.size(); ++i)
00101                 LOG(LOG_DEBUG)<<"Reader: "<<readerList[i].getName()<<", "<<readerList[i].getDescription();
00102 }
00103 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines