phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pocket_t Class Reference

A pocket is a set of balls. More...

#include <pocket.h>

Inheritance diagram for pocket_t:
Collaboration diagram for pocket_t:

Public Member Functions

size_t bytesize (void) const
 size of binary serialization
 
void repair_owners (const std::unordered_map< name_t, node_t * > &node_name, std::unordered_map< name_t, ball_t * > *ball_name)
 
 ~pocket_t (void)
 destructor
 
bool holds (ball_t *b) const
 does this node hold the given ball?
 
bool holds (color_t c) const
 does this node hold a ball of this color?
 
ball_tlast_ball (void) const
 retrieve the last ball
 
ball_tball (const color_t c) const
 retrieve the first ball of the specified color.
 
ball_tother (const ball_t *b) const
 return a pointer to another ball
 
std::string describe (void) const
 human-readable info
 
SEXP structure (void) const
 R list description.
 
std::string yaml (std::string tab="") const
 human/machine-readable info
 

Protected Member Functions

void repair_holder (node_t *p)
 

Private Member Functions

void clean (void)
 delete balls and clear pocket
 

Friends

raw_toperator>> (const pocket_t &p, raw_t *o)
 binary serialization
 
raw_toperator>> (raw_t *o, pocket_t &p)
 

Detailed Description

A pocket is a set of balls.

An order relation among balls ensures the uniqueness of the internal representation.

Definition at line 32 of file pocket.h.

Constructor & Destructor Documentation

◆ ~pocket_t()

pocket_t::~pocket_t ( void )
inline

destructor

Definition at line 104 of file pocket.h.

104 {
105 clean();
106 };
void clean(void)
delete balls and clear pocket
Definition pocket.h:37
Here is the call graph for this function:

Member Function Documentation

◆ ball()

ball_t * pocket_t::ball ( const color_t c) const
inline

retrieve the first ball of the specified color.

Definition at line 128 of file pocket.h.

128 {
129 for (ball_t *b : *this) {
130 if (b->color == c) return b;
131 }
132 err("in '%s' (%s line %d): no ball of color %s", // # nocov
133 __func__,__FILE__,__LINE__,colores[c]); // # nocov
134 return 0;
135 };
static const char * colores[]
Definition ball.h:15
color_t color
Definition ball.h:38
#define err(...)
Definition internal.h:18

◆ bytesize()

size_t pocket_t::bytesize ( void ) const
inline

size of binary serialization

Definition at line 46 of file pocket.h.

46 {
47 return sizeof(size_t) + size()*(ball_t::bytesize);
48 };
static const size_t bytesize
size of binary serialization
Definition ball.h:43
Here is the caller graph for this function:

◆ clean()

void pocket_t::clean ( void )
inlineprivate

delete balls and clear pocket

Definition at line 37 of file pocket.h.

37 {
38 for (ball_t *b : *this) delete b;
39 clear();
40 };
Here is the caller graph for this function:

◆ describe()

std::string pocket_t::describe ( void ) const
inline

human-readable info

Definition at line 146 of file pocket.h.

146 {
147 std::string s = "{";
148 ball_it i = begin();
149 s += (*i)->describe(); ++i;
150 while (i != end()) {
151 s += ", " + (*i)->describe(); ++i;
152 }
153 s += "}";
154 return s;
155 };
std::set< ball_t *, ball_order >::const_iterator ball_it
Definition pocket.h:26
Here is the caller graph for this function:

◆ holds() [1/2]

bool pocket_t::holds ( ball_t * b) const
inline

does this node hold the given ball?

Definition at line 111 of file pocket.h.

111 {
112 ball_it i = find(b);
113 return (i != end());
114 };
Here is the caller graph for this function:

◆ holds() [2/2]

bool pocket_t::holds ( color_t c) const
inline

does this node hold a ball of this color?

Definition at line 116 of file pocket.h.

116 {
117 bool result = false;
118 for (ball_it i = begin(); !result && i != end(); i++) {
119 result = ((*i)->color == c);
120 }
121 return result;
122 };

◆ last_ball()

ball_t * pocket_t::last_ball ( void ) const
inline

retrieve the last ball

Definition at line 124 of file pocket.h.

124 {
125 return *crbegin();
126 };
Here is the caller graph for this function:

◆ other()

ball_t * pocket_t::other ( const ball_t * b) const
inline

return a pointer to another ball

Definition at line 137 of file pocket.h.

137 {
138 for (ball_t *a : *this) {
139 if (a != b) return a;
140 }
141 err("error in '%s' (%s line %d): there is no other.", // # nocov
142 __func__,__FILE__,__LINE__); // # nocov
143 return 0;
144 };

◆ repair_holder()

void pocket_t::repair_holder ( node_t * p)
inlineprotected

Needed in deserialization. Inform all balls as to their holder.

Definition at line 74 of file pocket.h.

74 {
75 for (ball_t *b : *this) {
76 b->holder() = p;
77 }
78 };
node_t * holder(void) const
in whose pocket do I lie?
Definition ball.h:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ repair_owners()

void pocket_t::repair_owners ( const std::unordered_map< name_t, node_t * > & node_name,
std::unordered_map< name_t, ball_t * > * ball_name )
inline

Needed in deserialization. This function repairs the links green balls and their names.

Definition at line 83 of file pocket.h.

84 {
85 std::unordered_map<name_t,node_t*>::const_iterator n;
86 for (ball_t *b : *this) {
87 if (b->is(green)) {
88 n = node_name.find(b->uniq);
89 if (n != node_name.end()) {
90 node_t *p = n->second;
91 b->owner() = p;
92 ball_name->insert({b->uniq,b});
93 } else {
94 err("in '%s' (%s line %d): cannot find ball %zd", // #nocov
95 __func__,__FILE__,__LINE__,b->uniq); // #nocov
96 }
97 }
98 }
99 };
@ green
Definition ball.h:14
node_t * owner(void) const
view owner of a green ball
Definition ball.h:94
name_t uniq
Definition ball.h:37
bool is(color_t c) const
is a given ball of the given color?
Definition ball.h:117
#define n
Definition lbdp_pomp.c:8
Here is the call graph for this function:

◆ structure()

SEXP pocket_t::structure ( void ) const
inline

R list description.

Definition at line 157 of file pocket.h.

157 {
158 SEXP o;
159 PROTECT(o = NEW_LIST(size()));
160 int k = 0;
161 for (ball_rev_it i = crbegin(); i != crend(); i++) {
162 SET_ELEMENT(o,k++,(*i)->structure());
163 }
164 UNPROTECT(1);
165 return o;
166 };
std::set< ball_t *, ball_order >::const_reverse_iterator ball_rev_it
Definition pocket.h:27
Here is the caller graph for this function:

◆ yaml()

std::string pocket_t::yaml ( std::string tab = "") const
inline

human/machine-readable info

Definition at line 168 of file pocket.h.

168 {
169 std::string o = "";
170 std::string t = tab + " ";
171 for (ball_t *b : *this) {
172 o += tab + "- " + b->yaml(t);
173 }
174 return o;
175 };
std::string yaml(std::string tab="") const
machine-readable info
Definition ball.h:145
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator>> [1/2]

raw_t * operator>> ( const pocket_t & p,
raw_t * o )
friend

binary serialization

Definition at line 50 of file pocket.h.

50 {
51 size_t psize = p.size();
52 memcpy(o,&psize,sizeof(size_t)); o += sizeof(size_t);
53 for (ball_t *i : p)
54 o = (*i >> o);
55 return o;
56 };

◆ operator>> [2/2]

raw_t * operator>> ( raw_t * o,
pocket_t & p )
friend

binary deserialization. this leaves the balls without knowledge of their holder.

Definition at line 59 of file pocket.h.

59 {
60 p.clean();
61 size_t psize;
62 memcpy(&psize,o,sizeof(size_t)); o += sizeof(size_t);
63 for (size_t i = 0; i < psize; i++) {
64 ball_t *b = new ball_t();
65 o = (o >> *b);
66 p.insert(b);
67 }
68 return o;
69 };

The documentation for this class was generated from the following file: