phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
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_tfirst_ball (void) const
 retrieve the first ball
 
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
 
string_t yaml (string_t tab="") const
 human/machine-readable info
 
SEXP structure (void) const
 R list description.
 

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 30 of file pocket.h.

Constructor & Destructor Documentation

◆ ~pocket_t()

pocket_t::~pocket_t ( void )
inline

destructor

Definition at line 102 of file pocket.h.

102 {
103 clean();
104 };
void clean(void)
delete balls and clear pocket
Definition pocket.h:35
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 130 of file pocket.h.

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

◆ bytesize()

size_t pocket_t::bytesize ( void ) const
inline

size of binary serialization

Definition at line 44 of file pocket.h.

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

◆ clean()

void pocket_t::clean ( void )
inlineprivate

delete balls and clear pocket

Definition at line 35 of file pocket.h.

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

◆ first_ball()

ball_t * pocket_t::first_ball ( void ) const
inline

retrieve the first ball

Definition at line 122 of file pocket.h.

122 {
123 return *cbegin();
124 };
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 109 of file pocket.h.

109 {
110 ball_it i = find(b);
111 return (i != end());
112 };
std::set< ball_t *, ball_order >::const_iterator ball_it
Definition pocket.h:24
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 114 of file pocket.h.

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

◆ last_ball()

ball_t * pocket_t::last_ball ( void ) const
inline

retrieve the last ball

Definition at line 126 of file pocket.h.

126 {
127 return *crbegin();
128 };
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 139 of file pocket.h.

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

◆ repair_holder()

void pocket_t::repair_holder ( node_t * p)
inlineprotected

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

Definition at line 72 of file pocket.h.

72 {
73 for (ball_t *b : *this) {
74 b->holder() = p;
75 }
76 };
node_t * holder(void) const
in whose pocket do I lie?
Definition ball.h:107
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 81 of file pocket.h.

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

◆ structure()

SEXP pocket_t::structure ( void ) const

R list description.

Definition at line 40 of file structure.cc.

42{
43 SEXP o;
44 PROTECT(o = NEW_LIST(size()));
45 int k = 0;
46 for (ball_rev_it i = crbegin(); i != crend(); i++) {
47 SET_ELEMENT(o,k++,(*i)->structure());
48 }
49 UNPROTECT(1);
50 return o;
51}
std::set< ball_t *, ball_order >::const_reverse_iterator ball_rev_it
Definition pocket.h:25
Here is the caller graph for this function:

◆ yaml()

string_t pocket_t::yaml ( string_t tab = "") const

human/machine-readable info

Definition at line 24 of file yaml.cc.

26{
27 string_t o = "";
28 string_t t = tab + " ";
29 for (ball_t *b : *this) {
30 o += tab + "- " + b->yaml(t);
31 }
32 return o;
33}
string_t yaml(string_t tab="") const
human/machine-readable info
Definition yaml.cc:12
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 48 of file pocket.h.

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

◆ 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 57 of file pocket.h.

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

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