pupene  0.2.0
pup.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "pup-core.h"
4 
5 
6 /** \file
7  * Core `pup` functions for working with `STL` types.
8  */
9 namespace pupene::fns {
10  /**
11  * Pups STL-like sequential containers, but not `std::string`.
12  *
13  * @see enable_if_puppable_container
14  */
15  template <typename P,
16  typename Container, // excluding std::string
17  typename = void, // avoiding redefinition of pup
18  typename = enable_if_puppable_container<Container>>
19  void pup(Pupper<P>& p,
20  Container& container,
21  const Meta& meta) {
22 
23  pup_iterable(p, container, meta);
24  }
25 
26  /**
27  * Pups STL-like associative maps.
28  *
29  * @see enable_if_puppable_map
30  */
31  template <typename P,
32  template <typename ...> typename Map,
33  typename K,
34  typename V,
35  typename = enable_if_puppable_map<Map<K, V>>>
36  void pup(Pupper<P>& p,
37  Map<K, V>& map,
38  const Meta& meta) {
39 
40  pup_object_container(p, map, meta, [&map](auto&& fpup, auto size) {
41  const Meta meta = {"", Meta::Type::Object};
42  if (map.empty()) { // assume deserialization
43  for (auto i = 0u; size > i; i++) {
44  std::pair<K, V> kv;
45  fpup(kv, meta);
46  map[kv.first] = kv.second;
47  }
48  } else { // assume serialization
49  for (auto& entry : map) {
50  std::pair<K, V> kv = entry;
51  fpup(kv, meta);
52  }
53  }
54  });
55  }
56 
57  /**
58  * Pups std::pair, used for pupping associative maps.
59  */
60  template <typename P, typename K, typename V>
61  void pup(Pupper<P>& p, std::pair<K, V>& pair, const Meta& meta) {
62  pup_object(p, pair, meta, [&pair](auto&& fpup) {
63  fpup(pair.first, "key");
64  fpup(pair.second, "value");
65  });
66  }
67 }
Definition: debug.cpp:4
void pup(Pupper< P > &p, std::pair< K, V > &pair, const Meta &meta)
Pups std::pair, used for pupping associative maps.
Definition: pup.h:61
Holds name and type of objects.
Definition: traits.h:7
void pup(Pupper< P > &p, Container &container, const Meta &meta)
Pups STL-like sequential containers, but not std::string.
Definition: pup.h:19
Meta(const char *name, Type type=Type::Value)
Definition: traits.h:13
void pup(Pupper< P > &p, Map< K, V > &map, const Meta &meta)
Pups STL-like associative maps.
Definition: pup.h:36
Base class for working with puppable types.
Definition: pupper.h:83