framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
crc.hpp
Go to the documentation of this file.
1 // Copyright (C) 2012 iwg molw5
2 // For conditions of distribution and use, see copyright notice in COPYING
3 
13 #pragma once
14 
15 #ifndef FRAMEWORK_NO_BOOST
16  #include <boost/crc.hpp>
17 #endif
18 
19 namespace framework
20 {
21  namespace serializable
22  {
30  template <typename T>
32  {
33  public:
37  template <typename... Args>
38  crc_wrapper (Args&&... args)
39  : p_tSum(std::forward <Args> (args)...)
40  {
41  }
42 
46  bool write (char const* s, std::size_t n)
47  {
48  p_tSum.process_bytes(s, n);
49  return true;
50  }
51 
55  template <typename... Args>
56  auto checksum (Args&&... args) const ->
57  decltype(std::declval <T> ().checksum(std::forward <Args> (args)...))
58  {
59  return p_tSum.checksum(std::forward <Args> (args)...);
60  }
61 
65  template <typename... Args>
66  auto reset (Args&&... args) ->
67  decltype(std::declval <T> ().reset(std::forward <Args> (args)...))
68  {
69  return p_tSum.reset(std::forward <Args> (args)...);
70  }
71 
72  private:
73  T p_tSum;
74  };
75 
76 #ifndef FRAMEWORK_NO_BOOST
77  using crc_16_wrapper = crc_wrapper <boost::crc_16_type>;
78  using crc_ccitt_wrapper = crc_wrapper <boost::crc_ccitt_type>;
79  using crc_xmodem_wrapper = crc_wrapper <boost::crc_xmodem_type>;
80  using crc_32_wrapper = crc_wrapper <boost::crc_32_type>;
81 #endif
82  }
83 }