gps_position.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef GPS_POSITION_HPP
  2. #define GPS_POSITION_HPP
  3. // Copyright Matthias Troyer
  4. // 2005. Distributed under the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/mpi/datatype_fwd.hpp>
  8. #include <boost/mpl/and.hpp>
  9. #include <boost/serialization/export.hpp>
  10. #include <boost/shared_ptr.hpp>
  11. #include <iostream>
  12. class gps_position
  13. {
  14. private:
  15. friend class boost::serialization::access;
  16. // When the class Archive corresponds to an output archive, the
  17. // & operator is defined similar to <<. Likewise, when the class Archive
  18. // is a type of input archive the & operator is defined similar to >>.
  19. template<class Archive>
  20. void serialize(Archive & ar, const unsigned int version)
  21. {
  22. ar & degrees & minutes & seconds;
  23. }
  24. int degrees;
  25. int minutes;
  26. float seconds;
  27. public:
  28. gps_position(){};
  29. gps_position(int d, int m, float s) :
  30. degrees(d), minutes(m), seconds(s)
  31. {}
  32. friend std::ostream& operator<<(std::ostream& out, const gps_position& g);
  33. friend bool operator==(const gps_position& x, const gps_position& y)
  34. {
  35. return (x.degrees == y.degrees
  36. && x.minutes == y.minutes
  37. && x.seconds == y.seconds);
  38. }
  39. inline friend bool operator!=(const gps_position& x, const gps_position& y)
  40. {
  41. return !(x == y);
  42. }
  43. };
  44. inline
  45. std::ostream& operator<<(std::ostream& out, const gps_position& g) {
  46. out << "gps{" << g.degrees << 'd' << g.minutes << 'm' << g.seconds << "s}";
  47. return out;
  48. }
  49. namespace boost { namespace mpi {
  50. template <>
  51. struct is_mpi_datatype<gps_position>
  52. : public mpl::and_
  53. <
  54. is_mpi_datatype<int>,
  55. is_mpi_datatype<float>
  56. >
  57. {};
  58. } }
  59. #endif