binary.hh
Go to the documentation of this file.
00001 #ifndef HALFSTEPS_PATTERN_BINARY_HH
00002 # define HALFSTEPS_PATTERN_BINARY_HH
00003 # include <utility>
00004 # include <walk_interfaces/pattern-generator.hh>
00005 # include <walk_interfaces/binary.hh>
00006 
00007 # include <halfsteps_pattern_generator.hh>
00008 
00009 namespace walk
00010 {
00011   inline
00012   BinaryReaderHelper&
00013   operator>> (BinaryReaderHelper& helper,
00014               HalfStepsPatternGenerator::footprint_t& footprint)
00015   {
00016     using namespace boost::posix_time;
00017     using namespace boost::gregorian;
00018 
00019     std::size_t beginTimeStrSize = 0;
00020     helper.stream.read(reinterpret_cast<char*>(&beginTimeStrSize), sizeof (std::size_t));
00021 
00022     char* str = new char[beginTimeStrSize];
00023     helper.stream.read(str, beginTimeStrSize * sizeof (char));
00024 
00025     std::string beginTimeStr = str;
00026     delete[] str;
00027 
00028     footprint.beginTime = walk::Time (from_iso_string (beginTimeStr));
00029 
00030     double d = 0;
00031     helper.stream.read(reinterpret_cast<char*>(&d), sizeof (double));
00032     footprint.duration = milliseconds (d * 1e3);
00033     helper >> footprint.position;
00034     return helper;
00035   }
00036 
00037   inline
00038   BinaryReaderHelper&
00039   operator>>
00040   (BinaryReaderHelper& helper,
00041    WALK_INTERFACES_EIGEN_STL_VECTOR(HalfStepsPatternGenerator::footprint_t)&
00042    footprints)
00043   {
00044     WALK_INTERFACES_EIGEN_STL_VECTOR
00045       (HalfStepsPatternGenerator::footprint_t)::size_type
00046       countFootprints = 0.;
00047 
00048     helper.stream.read
00049       (reinterpret_cast<char*>(&countFootprints),
00050        sizeof (WALK_INTERFACES_EIGEN_STL_VECTOR
00051                (HalfStepsPatternGenerator::footprint_t)::size_type));
00052 
00053     footprints.clear ();
00054     for (unsigned i = 0; i < countFootprints; ++i)
00055       {
00056         HalfStepsPatternGenerator::footprint_t footprint;
00057         helper >> footprint;
00058         footprints.push_back (footprint);
00059       }
00060     return helper;
00061   }
00062 
00063   inline
00064   BinaryWriterHelper&
00065   operator<< (BinaryWriterHelper& helper,
00066               const HalfStepsPatternGenerator::footprint_t& footprint)
00067   {
00068     using namespace boost::gregorian;
00069 
00070     std::string beginTimeStr = to_iso_string (footprint.beginTime);
00071     std::size_t size = beginTimeStr.size () + 1;
00072 
00073     helper.stream.write(reinterpret_cast<const char*>(&size), sizeof (std::size_t));
00074     helper.stream.write(beginTimeStr.c_str(), size * sizeof (unsigned char));
00075 
00076     double t = 0. + footprint.duration.total_nanoseconds () / 1e9;
00077     helper.stream.write(reinterpret_cast<const char*>(&t), sizeof (double));
00078     helper << footprint.position;
00079     return helper;
00080   }
00081 
00082   inline
00083   BinaryWriterHelper&
00084   operator<<
00085   (BinaryWriterHelper& helper,
00086    const WALK_INTERFACES_EIGEN_STL_VECTOR
00087    (HalfStepsPatternGenerator::footprint_t)& footprints)
00088   {
00089     WALK_INTERFACES_EIGEN_STL_VECTOR
00090       (HalfStepsPatternGenerator::footprint_t)::size_type
00091       countFootprints = footprints.size ();
00092 
00093     helper.stream.write
00094       (reinterpret_cast<const char*>(&countFootprints),
00095        sizeof (WALK_INTERFACES_EIGEN_STL_VECTOR
00096                (HalfStepsPatternGenerator::footprint_t)::size_type));
00097 
00098     BOOST_FOREACH (const HalfStepsPatternGenerator::footprint_t& footprint, footprints)
00099       helper << footprint;
00100     return helper;
00101   }
00102 
00103 } // end of namespace walk.
00104 
00105 #endif //! HALFSTEPS_PATTERN_BINARY_HH


halfsteps_pattern_generator
Author(s): Nicolas Perrin, Thomas Moulard/thomas.moulard@gmail.com
autogenerated on Sat Dec 28 2013 17:05:31