pupene  0.2.0
Functions
pupene::fns Namespace Reference

Functions

template<typename P , typename T >
PupPolicy begin (Pupper< P > &p, T &value, const Meta &meta)
 Called when a new object is encountered; an object is any type which is not floating point, integer or std::string. More...
 
template<typename P >
void end (Pupper< P > &p, const Meta &meta)
 The opposite of pupene::fns::begin(p, value, meta). More...
 
template<typename P , typename Container , typename = void, typename = enable_if_puppable_container<Container>>
void pup (Pupper< P > &p, Container &container, const Meta &meta)
 Pups STL-like sequential containers, but not std::string. More...
 
template<typename P , template< typename ... > typename Map, typename K , typename V , typename = enable_if_puppable_map<Map<K, V>>>
void pup (Pupper< P > &p, Map< K, V > &map, const Meta &meta)
 Pups STL-like associative maps. More...
 
template<typename P , typename T , typename = enable_if_puppable<T>>
void pup (Pupper< P > &p, T &value, const Meta &meta)
 Forwards value to the Pupper. More...
 
template<typename P , typename K , typename V >
void pup (Pupper< P > &p, std::pair< K, V > &pair, const Meta &meta)
 Pups std::pair, used for pupping associative maps. More...
 
template<typename P , typename Iterable , typename = enable_if_pup_iterable<Iterable>>
void pup_iterable (Pupper< P > &p, Iterable &container, const Meta &meta)
 Pups most STL-like containers, including strings. More...
 
template<typename P , typename T , typename Fn >
void pup_object (Pupper< P > &p, T &object, const Meta &meta, Fn &&body_fn)
 Describes a type by enumerating its members, used in conjunction with pup() implementations. More...
 
template<typename P , typename Iterable , typename BodyFn >
void pup_object_container (Pupper< P > &p, Iterable container, const Meta &meta, BodyFn &&body_fn)
 A pup_object() for dealing with iterable types. More...
 

Function Documentation

◆ begin()

template<typename P , typename T >
PupPolicy pupene::fns::begin ( Pupper< P > &  p,
T &  value,
const Meta meta 
)

Called when a new object is encountered; an object is any type which is not floating point, integer or std::string.

Forwards to Pupper::begin(). If the Pupper returns PupPolicy::consume_object, the Pupper deals with the object without invoking its associated pup function(s).

Parameters
valuePassed to pupper.
Returns
PupPolicy::pup_object or PupPolicy::consume_object

Definition at line 22 of file pup-pupper.h.

◆ end()

template<typename P >
void pupene::fns::end ( Pupper< P > &  p,
const Meta meta 
)

The opposite of pupene::fns::begin(p, value, meta).

The meta object is the same as was sent in when the corresponding begin(Pupper<P>, T&, Meta&).

Definition at line 48 of file pup-pupper.h.

◆ pup() [1/4]

template<typename P , typename Container , typename = void, typename = enable_if_puppable_container<Container>>
void pupene::fns::pup ( Pupper< P > &  p,
Container &  container,
const Meta meta 
)

Pups STL-like sequential containers, but not std::string.

See also
enable_if_puppable_container

Definition at line 19 of file pup.h.

◆ pup() [2/4]

template<typename P , template< typename ... > typename Map, typename K , typename V , typename = enable_if_puppable_map<Map<K, V>>>
void pupene::fns::pup ( Pupper< P > &  p,
Map< K, V > &  map,
const Meta meta 
)

Pups STL-like associative maps.

See also
enable_if_puppable_map

Definition at line 36 of file pup.h.

References pupene::Meta::Meta(), and pupene::Meta::Object.

◆ pup() [3/4]

template<typename P , typename T , typename = enable_if_puppable<T>>
void pupene::fns::pup ( Pupper< P > &  p,
T &  value,
const Meta meta 
)

Forwards value to the Pupper.

Template Parameters
TMatches std::string, integer and floating point types.
Parameters
valuePassed to pupper.
See also
enable_if_puppable

Definition at line 39 of file pup-pupper.h.

◆ pup() [4/4]

template<typename P , typename K , typename V >
void pupene::fns::pup ( Pupper< P > &  p,
std::pair< K, V > &  pair,
const Meta meta 
)

Pups std::pair, used for pupping associative maps.

Definition at line 61 of file pup.h.

◆ pup_iterable()

template<typename P , typename Iterable , typename = enable_if_pup_iterable<Iterable>>
void pupene::fns::pup_iterable ( Pupper< P > &  p,
Iterable &  container,
const Meta meta 
)

Pups most STL-like containers, including strings.

This function should only be called by pupper implementations.

Puppers commonly deal in formats where strings are considered fundamental/built-in types - if this is not the case, the pupper must specialize on std::string, and pup to this function, e.g.:

template <>
void pupene::BinaryReader::pup(std::string& value, const Meta& meta) {
pup_iterable(*this, value, meta);
}

The container object is encoded as size (element count) followed by its contents.

Example/layout

using pupene;
using int_string_pair = std::pair<uint32_t, std::string>;
std::vector<int_string_pair> pairs =
{{1, "one"}, {2, "two"}, {4, "four"}};
auto pupper = debug_pupper(std::cout);
pup(pupper, pairs, {});
// alternatively:
do_pup(NullPupper{}, pairs, true);

DebugPupper output:

object()
pup(size, 3)
array(data)
object()
pup(key, 1)
pup(value, one)
~object()
object()
pup(key, 2)
pup(value, two)
~object()
object()
pup(key, 4)
pup(value, four)
~object()
~array(data)
~object()
See also
enable_if_pup_iterable

Definition at line 145 of file pup-core.h.

◆ pup_object()

template<typename P , typename T , typename Fn >
void pupene::fns::pup_object ( Pupper< P > &  p,
T &  object,
const Meta meta,
Fn &&  body_fn 
)

Describes a type by enumerating its members, used in conjunction with pup() implementations.

Example: a pup for glm's vec2 type

template<typename P>
void pup(Pupper<P>& p, glm::vec2& v, const Meta& meta) {
pup_object(p, v, meta, [&v](auto&& fpup) {
fpup(v.x, "x");
fpup(v.y, "y");
});
}

body_fn is not invoked if begin() returns PupPolicy::consume_object.

Template Parameters
Fnhas signature [](auto&&)
Parameters
body_fninvoked with [](auto& v, const Meta& meta), where v is a member of object

Definition at line 39 of file pup-core.h.

References pupene::Meta::Meta(), pupene::Meta::name, pupene::Meta::Object, pupene::pup_object, pupene::Meta::type, and pupene::Meta::Value.

◆ pup_object_container()

template<typename P , typename Iterable , typename BodyFn >
void pupene::fns::pup_object_container ( Pupper< P > &  p,
Iterable  container,
const Meta meta,
BodyFn &&  body_fn 
)

A pup_object() for dealing with iterable types.

Encodes container as size followed by the contents.

Template Parameters
BodyFnhas signature [](auto&&, uint32_t size)
Parameters
body_fninvoked with [](auto& v, const Meta& meta), where v is a member of object

Definition at line 68 of file pup-core.h.

References pupene::Meta::Array, and pupene::Meta::Meta().