Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
bitset_support.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 15.06.2013 22:15:42 EDT
3 // File: bitset_support.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __BITSET_SUPPORT_HEADER
12 #define __BITSET_SUPPORT_HEADER
13 
14 #include <bitset>
15 
16 //------------------- print & serialize -------------------
17 namespace com {
18  template<size_t N, typename Archive>
19  void serialize(Archive & ar, std::bitset<N> & arg) {
20  typedef typename ustd::fast_bitset<1>::size_type size_type;
21  size_type size_ = arg.size();
22  ar & size_;
23  if(size_ <= 8) {
24  uint8_t data = arg.to_ulong();
25  ar & data;
26  arg = data;
27  } else if(size_ <= 16) {
28  uint16_t data = arg.to_ulong();
29  ar & data;
30  arg = data;
31  } else if(size_ <= 32) {
32  uint32_t data = arg.to_ulong();
33  ar & data;
34  arg = data;
35  } else if(size_ <= 64) {
36  uint64_t data = arg.to_ulong();
37  ar & data;
38  arg = data;
39  }
40  }
41 }//end namespace com
42 #endif //__BITSET_SUPPORT_HEADER
uint8_t size_type
Definition: fast_bitset.hpp:51
void serialize(Archive &ar, T &t)
Definition: serializer.hpp:95