8#include <unordered_map>
24typedef typename std::set<ball_t*,ball_order>::const_iterator
ball_it;
25typedef typename std::set<ball_t*,ball_order>::const_reverse_iterator
ball_rev_it;
30class pocket_t :
public std::set<ball_t*,ball_order> {
36 for (
ball_t *b : *
this)
delete b;
49 size_t psize = p.size();
50 memcpy(o,&psize,
sizeof(
size_t)); o +=
sizeof(size_t);
60 memcpy(&psize,o,
sizeof(
size_t)); o +=
sizeof(size_t);
61 for (
size_t i = 0; i < psize; i++) {
81 void repair_owners (
const std::unordered_map<name_t,node_t*>& node_name,
82 std::unordered_map<name_t,ball_t*> *ball_name) {
83 std::unordered_map<name_t,node_t*>::const_iterator
n;
86 n = node_name.find(b->
uniq);
87 if (
n != node_name.end()) {
92 err(
"in '%s' (%s line %d): cannot find ball %zd",
93 __func__,__FILE__,__LINE__,b->
uniq);
116 for (
ball_it i = begin(); !result && i != end(); i++) {
117 result = ((*i)->color == c);
132 if (b->
color == c)
return b;
134 err(
"in '%s' (%s line %d): no ball of color %s",
135 __func__,__FILE__,__LINE__,
colores[c]);
141 if (a != b)
return a;
143 err(
"error in '%s' (%s line %d): there is no other.",
144 __func__,__FILE__,__LINE__);
148 string_t
yaml (string_t tab =
"")
const;
static const char * colores[]
Balls function as pointers.
node_t * owner(void) const
view owner of a green ball
static const size_t bytesize
size of binary serialization
node_t * holder(void) const
in whose pocket do I lie?
bool is(color_t c) const
is a given ball of the given color?
Encodes a genealogical node.
void insert(ball_t *a)
insert a ball into the pocket of a node
A pocket is a set of balls.
friend raw_t * operator>>(const pocket_t &p, raw_t *o)
binary serialization
void clean(void)
delete balls and clear pocket
void repair_owners(const std::unordered_map< name_t, node_t * > &node_name, std::unordered_map< name_t, ball_t * > *ball_name)
ball_t * ball(const color_t c) const
retrieve the first ball of the specified color.
SEXP structure(void) const
R list description.
bool holds(color_t c) const
does this node hold a ball of this color?
ball_t * last_ball(void) const
retrieve the last ball
void repair_holder(node_t *p)
~pocket_t(void)
destructor
size_t bytesize(void) const
size of binary serialization
string_t yaml(string_t tab="") const
human/machine-readable info
ball_t * first_ball(void) const
retrieve the first ball
ball_t * other(const ball_t *b) const
return a pointer to another ball
bool holds(ball_t *b) const
does this node hold the given ball?
std::set< ball_t *, ball_order >::const_reverse_iterator ball_rev_it
std::set< ball_t *, ball_order >::const_iterator ball_it
Ordering for balls in pockets.
bool operator()(const ball_t *a, const ball_t *b) const