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

94 {
95 clean();
96 };
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 122 of file pocket.h.

122 {
123 ball_t *a = 0;
124 for (ball_t *b : *this) {
125 if (b->color == c) a = b;
126 }
127 assert(a != 0);
128 return a;
129 };
color_t color
Definition ball.h:36
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 114 of file pocket.h.

114 {
115 return *cbegin();
116 };
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 101 of file pocket.h.

101 {
102 ball_it i = find(b);
103 return (i != end());
104 };
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 106 of file pocket.h.

106 {
107 bool result = false;
108 for (ball_it i = begin(); !result && i != end(); i++) {
109 result = ((*i)->color == c);
110 }
111 return result;
112 };

◆ last_ball()

ball_t * pocket_t::last_ball ( void ) const
inline

retrieve the last ball

Definition at line 118 of file pocket.h.

118 {
119 return *crbegin();
120 };
Here is the caller graph for this function:

◆ 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

Repairs the links green balls and their names. Needed in deserialization.

Definition at line 81 of file pocket.h.

82 {
83 for (ball_t *b : *this) {
84 if (b->is(green)) {
85 b->owner() = node_name.at(b->uniq);
86 (*ball_name)[b->uniq] = b;
87 }
88 }
89 };
@ 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
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: