CanFileResolutionHelper.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #ifndef ICL_HARDWARE_CAN_SOURCE_CAN_FILE_RESOLUTION_HELPER_H_INCLUDED
00024 #define ICL_HARDWARE_CAN_SOURCE_CAN_FILE_RESOLUTION_HELPER_H_INCLUDED
00025 
00026 #include <fstream>
00027 #include <string>
00028 #include <boost/shared_ptr.hpp>
00029 
00030 #include <icl_sourcesink/Position.h>
00031 #include <icl_sourcesink/FileResolutionHelper.h>
00032 #include <icl_hardware_can/source/HardwareCanSource.h>
00033 
00034 namespace icl_hardware {
00035 namespace can {
00036 
00037 class CanFileResolutionHelper : public ::icl_sourcesink::FileResolutionHelper
00038 {
00039 public:
00041   typedef boost::shared_ptr<CanFileResolutionHelper> Ptr;
00043   typedef boost::shared_ptr<const CanFileResolutionHelper> ConstPtr;
00044 
00045   CanFileResolutionHelper(const std::string& filename);
00046 
00047   virtual CanFileResolutionHelper *clone() const
00048   {
00049     CanFileResolutionHelper *my_clone = new CanFileResolutionHelper(m_filename);
00050     my_clone->m_file.clear();
00051     my_clone->seekg(tellg());
00052     return my_clone;
00053   }
00054 
00055   virtual bool good() const
00056   {
00057     return m_file.good();
00058   }
00059 
00060   virtual icl_sourcesink::Position current() const
00061   {
00062     return m_current_position;
00063   }
00064 
00065   virtual bool advance();
00066 
00067   virtual std::ifstream::pos_type size() const
00068   {
00069     std::ifstream::pos_type curr = m_file.tellg();
00070     m_file.seekg(0, std::ios::end);
00071     std::ifstream::pos_type result = m_file.tellg();
00072     m_file.seekg(curr);
00073     return result;
00074   }
00075 
00076   virtual std::ifstream::pos_type tellg() const
00077   {
00078     return m_file.tellg();
00079   }
00080 
00081   virtual bool seekg(std::ifstream::pos_type position)
00082   {
00083     m_file.clear();
00084     m_file.seekg(position);
00085     return resolveHere();
00086   }
00087 
00088   virtual bool seekg(std::ifstream::off_type offset, std::ios_base::seekdir direction)
00089   {
00090     m_file.clear();
00091     m_file.seekg(offset, direction);
00092     return resolveHere();
00093   }
00094 
00095   static boost::posix_time::ptime timestampToPtime(double stamp);
00096 
00097   CanMessageStamped::Ptr currentMessage() const { return m_current_message; }
00098 
00099 protected:
00100   bool tryParse(const std::string& line, uint64_t current_pos);
00101 
00102   bool resolveHere();
00103 
00104 private:
00105   std::string m_filename;
00106   mutable std::ifstream m_file;
00107   icl_sourcesink::Position m_current_position;
00108   CanMessageStamped::Ptr m_current_message;
00109 };
00110 
00111 }
00112 }
00113 
00114 #endif


fzi_icl_can
Author(s):
autogenerated on Thu Jun 6 2019 20:26:01