8 #include <unordered_map>
26 typedef typename std::set<ball_t*,ball_order>::const_iterator
ball_it;
27 typedef typename std::set<ball_t*,ball_order>::const_reverse_iterator
ball_rev_it;
32 class pocket_t :
public std::set<ball_t*,ball_order> {
38 for (
ball_it i = begin(); i != end(); i++)
delete *i;
51 size_t psize = p.size();
52 memcpy(o,&psize,
sizeof(
size_t)); o +=
sizeof(size_t);
53 for (
ball_it i = p.begin(); i != p.end(); i++)
62 memcpy(&psize,o,
sizeof(
size_t)); o +=
sizeof(size_t);
63 for (
size_t i = 0; i < psize; i++) {
75 for (
ball_it i = begin(); i != end(); i++) {
83 void repair_owners (
const std::unordered_map<name_t,node_t*>& node_name,
84 std::unordered_map<name_t,ball_t*> *ball_name) {
85 std::unordered_map<name_t,node_t*>::const_iterator
n;
86 for (
ball_it i = begin(); i != end(); i++) {
89 n = node_name.find(b->
uniq);
90 if (
n != node_name.end()) {
93 ball_name->insert({b->
uniq,b});
95 err(
"in '%s' (%s line %d): cannot find ball %zd",
96 __func__,__FILE__,__LINE__,b->
uniq);
119 for (
ball_it i = begin(); !result && i != end(); i++) {
120 result = ((*i)->color == c);
130 for (
ball_it i = begin(); i != end(); i++) {
131 if ((*i)->color == c)
return *i;
133 err(
"in '%s' (%s line %d): no ball of color %s",
134 __func__,__FILE__,__LINE__,
colores[c]);
139 for (
ball_it i = begin(); i != end(); i++) {
140 if (*i != b)
return *i;
142 err(
"error in '%s' (%s line %d): there is no other.",
143 __func__,__FILE__,__LINE__);
150 s += (*i)->describe(); ++i;
152 s +=
", " + (*i)->describe(); ++i;
160 PROTECT(o = NEW_LIST(size()));
162 for (
ball_rev_it i = crbegin(); i != crend(); i++) {
163 SET_ELEMENT(o,k++,(*i)->structure());
169 std::string
yaml (std::string tab =
"")
const {
171 std::string t = tab +
" ";
172 for (
ball_it i = begin(); i != end(); i++) {
173 o += tab +
"- " + (*i)->yaml(t);
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
bool is(color_t c) const
is a given ball of the given color?
Encodes a genealogical node.
A pocket is a set of balls.
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)
SEXP structure(void) const
R list description.
friend raw_t * operator>>(const pocket_t &p, raw_t *o)
binary serialization
std::string yaml(std::string tab="") const
human/machine-readable info
bool holds(color_t c) const
does this node hold a ball of this color?
ball_t * ball(const color_t c) const
retrieve the first ball of the specified color.
ball_t * other(const ball_t *b) const
return a pointer to another ball
void repair_holder(node_t *p)
std::string describe(void) const
human-readable info
~pocket_t(void)
destructor
size_t bytesize(void) const
size of binary serialization
ball_t * last_ball(void) const
retrieve the last 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