Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
vector_support.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 14.06.2013 20:43:00 EDT
3 // File: vector_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 __VECTOR_SUPPORT_HEADER
12 #define __VECTOR_SUPPORT_HEADER
13 
14 #include <vector>
15 
16 //------------------- print & serialize -------------------
17 template<typename T, typename S>
18 S & operator<<(S & os, std::vector<T> const & arg) {
19  typedef typename std::vector<T>::size_type size_type;
20  os << "[";
21  for(size_type i = 0; i < arg.size(); ++i) {
22  os << arg[i];
23  if(i != arg.size() - 1)
24  os << ", ";
25  }
26  os << "]";
27  return os;
28 }
29 namespace com {
30  template<typename T, typename Archive>
31  void serialize(Archive & ar, std::vector<T> & arg) {
32  typedef typename ustd::vector<T>::size_type size_type;
33  size_type size_ = arg.size();
34  ar & size_;
35  if(Archive::type == archive_enum::input) {
36  arg.resize(size_);
37  }
38  for(size_type i = 0; i < size_; ++i) {
39  ar & arg[i];
40  }
41  }
42 }//end namespace com
43 #endif //__VECTOR_SUPPORT_HEADER
void serialize(Archive &ar, T &t)
Definition: serializer.hpp:95
uint16_t size_type
Definition: vector.hpp:24