chrono.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*! \file chrono.hpp
  2. \brief Support for types found in \<chrono\>
  3. \ingroup STLSupport */
  4. /*
  5. Copyright (c) 2014, Randolph Voorhies, Shane Grant
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. * Neither the name of the copyright holder nor the
  15. names of its contributors may be used to endorse or promote products
  16. derived from this software without specific prior written permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  21. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef CEREAL_TYPES_CHRONO_HPP_
  29. #define CEREAL_TYPES_CHRONO_HPP_
  30. #include <chrono>
  31. namespace cereal
  32. {
  33. //! Saving std::chrono::duration
  34. template <class Archive, class R, class P> inline
  35. void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::duration<R, P> const & dur )
  36. {
  37. ar( CEREAL_NVP_("count", dur.count()) );
  38. }
  39. //! Loading std::chrono::duration
  40. template <class Archive, class R, class P> inline
  41. void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::duration<R, P> & dur )
  42. {
  43. R count;
  44. ar( CEREAL_NVP_("count", count) );
  45. dur = std::chrono::duration<R, P>{count};
  46. }
  47. //! Saving std::chrono::time_point
  48. template <class Archive, class C, class D> inline
  49. void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::time_point<C, D> const & dur )
  50. {
  51. ar( CEREAL_NVP_("time_since_epoch", dur.time_since_epoch()) );
  52. }
  53. //! Loading std::chrono::time_point
  54. template <class Archive, class C, class D> inline
  55. void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::time_point<C, D> & dur )
  56. {
  57. D elapsed;
  58. ar( CEREAL_NVP_("time_since_epoch", elapsed) );
  59. dur = std::chrono::time_point<C, D>{elapsed};
  60. }
  61. } // namespace cereal
  62. #endif // CEREAL_TYPES_CHRONO_HPP_