iSpike  2.1
Spike conversion library for robotics
D:/Home/Programs/iSpike/src/Writer/FileAngleWriter.cpp
Go to the documentation of this file.
00001 #include <iSpike/Writer/FileAngleWriter.hpp>
00002 #include <iSpike/ISpikeException.hpp>
00003 #include <iSpike/Log/Log.hpp>
00004 using namespace ispike;
00005 
00006 #include <string>
00007 #include <fstream>
00008 #include <boost/lexical_cast.hpp>
00009 using namespace std;
00010 
00011 
00012 FileAngleWriter::FileAngleWriter() :
00013         fileName("anglesOut.txt")
00014 {
00015         addProperty(Property("anglesOut.txt", "File Name", "The file where the angles will be written to", true));
00016         writerDescription = Description("File Angle Writer", "This is a file angle writer", "Angle Writer");
00017 }
00018 
00019 
00020 /*--------------------------------------------------------------------*/
00021 /*---------                 PUBLIC METHODS                     -------*/
00022 /*--------------------------------------------------------------------*/
00023 
00024 //Inherited from Writer
00025 void FileAngleWriter::initialize(map<string, Property> &properties){
00026         setProperties(properties);
00027         setInitialized(true);
00028 }
00029 
00030 
00031 //Inherited from AngleWriter
00032 void FileAngleWriter::setAngle(double newAngle){
00033         if(this->angle != newAngle){
00034                 this->angle = newAngle;
00035                 writeAngleToFile();
00036         }
00037 }
00038 
00039 
00040 //Inherited from AngleWriter
00041 void FileAngleWriter::setDegreeOfFreedom(int dof){
00042         if(this->degreeOfFreedom != dof){
00043                 this->degreeOfFreedom = dof;
00044                 writeAngleToFile();
00045         }
00046 }
00047 
00048 
00049 //Inherited from PropertyHolder
00050 void FileAngleWriter::setProperties(map<string, Property>& properties){
00051         fileName = updateStringProperty(properties["File Name"]);
00052 }
00053 
00054 
00055 /*--------------------------------------------------------------------*/
00056 /*---------                PRIVATE METHODS                     -------*/
00057 /*--------------------------------------------------------------------*/
00058 
00060 void FileAngleWriter::writeAngleToFile(){
00061         ofstream fileStream;
00062         fileStream.open(fileName.c_str(), fstream::out);
00063         if (!fileStream) {
00064                 ostringstream errorStream;
00065                 errorStream << "FileAngleWriter: Could not write angles to " << fileName;
00066                 throw ISpikeException(errorStream.str());
00067         }
00068 
00069         fileStream << boost::lexical_cast<string>(getAngle()) << endl;
00070 
00071         if (fileStream.fail()) {
00072                 ostringstream errorStream;
00073                 errorStream << "FileAngleWriter: Could not write angles to " << fileName;
00074                 throw ISpikeException(errorStream.str());
00075         }
00076 
00077         fileStream.close();
00078 
00079 }
00080 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines