phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
ball_t Class Reference

Balls function as pointers. More...

#include <ball.h>

Collaboration diagram for ball_t:

Public Member Functions

 ball_t (node_t *who=0, name_t u=0, color_t col=green, name_t d=undeme)
 basic constructor for ball class
 
 ball_t (const ball_t &)=delete
 copy constructor
 
 ball_t (ball_t &&)=delete
 move constructor
 
ball_toperator= (const ball_t &)=delete
 copy assignment operator
 
ball_toperator= (ball_t &&)=delete
 move assignment operator
 
 ~ball_t (void)=default
 destructor
 
name_t deme (void) const
 view deme
 
name_tdeme (void)
 change deme
 
node_towner (void) const
 view owner of a green ball
 
node_t *& owner (void)
 change owner of a green ball
 
node_tchild (void) const
 a child is the owner of a green ball
 
node_tholder (void) const
 in whose pocket do I lie?
 
node_t *& holder (void)
 in whose pocket do I lie?
 
bool is (color_t c) const
 is a given ball of the given color?
 
string_t color_name (void) const
 human-readable colors
 
string_t color_symbol (void) const
 machine-readable color symbols
 
string_t yaml (string_t tab="") const
 human/machine-readable info
 
SEXP structure (void) const
 R list description.
 
string_t newick (const slate_t &t, bool showdeme) const
 

Data Fields

name_t uniq
 
color_t color
 

Static Public Attributes

static const size_t bytesize = 2*sizeof(name_t)+sizeof(color_t)
 size of binary serialization
 

Private Attributes

node_t_holder
 
node_t_owner
 
name_t _deme
 

Friends

raw_toperator>> (const ball_t &b, raw_t *o)
 binary serialization
 
raw_toperator>> (raw_t *o, ball_t &b)
 binary deserialization
 

Detailed Description

Balls function as pointers.

Each ball has:

  • a globally unique name
  • a color
  • a deme
  • a "holder": a pointer to the node in whose pocket it lies
  • an "owner": a pointer to the node in which it was originally created

Definition at line 27 of file ball.h.

Constructor & Destructor Documentation

◆ ball_t() [1/3]

ball_t::ball_t ( node_t * who = 0,
name_t u = 0,
color_t col = green,
name_t d = undeme )
inline

basic constructor for ball class

Definition at line 63 of file ball.h.

64 {
65 _holder = _owner = who;
66 uniq = u;
67 color = col;
68 _deme = d;
69 };
name_t uniq
Definition ball.h:35
node_t * _holder
Definition ball.h:30
color_t color
Definition ball.h:36
node_t * _owner
Definition ball.h:31
name_t _deme
Definition ball.h:32
Here is the caller graph for this function:

◆ ball_t() [2/3]

ball_t::ball_t ( const ball_t & )
delete

copy constructor

Here is the call graph for this function:

◆ ball_t() [3/3]

ball_t::ball_t ( ball_t && )
delete

move constructor

Here is the call graph for this function:

◆ ~ball_t()

ball_t::~ball_t ( void )
default

destructor

Member Function Documentation

◆ child()

node_t * ball_t::child ( void ) const
inline

a child is the owner of a green ball

Definition at line 102 of file ball.h.

102 {
103 assert(color==green);
104 return _owner;
105 };
@ green
Definition ball.h:12
Here is the caller graph for this function:

◆ color_name()

string_t ball_t::color_name ( void ) const
inline

human-readable colors

Definition at line 119 of file ball.h.

119 {
120 return colores[color];
121 };
static const char * colores[]
Definition ball.h:13
Here is the caller graph for this function:

◆ color_symbol()

string_t ball_t::color_symbol ( void ) const
inline

machine-readable color symbols

Definition at line 123 of file ball.h.

123 {
124 if (is(green) && _holder==_owner)
125 return "m"; // brown balls
126 else
127 return colorsymb[color];
128 };
static const char * colorsymb[]
Definition ball.h:14
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:
Here is the caller graph for this function:

◆ deme() [1/2]

name_t & ball_t::deme ( void )
inline

change deme

Definition at line 88 of file ball.h.

88 {
89 return _deme;
90 };

◆ deme() [2/2]

name_t ball_t::deme ( void ) const
inline

view deme

Definition at line 84 of file ball.h.

84 {
85 return _deme;
86 };
Here is the caller graph for this function:

◆ holder() [1/2]

node_t *& ball_t::holder ( void )
inline

in whose pocket do I lie?

Definition at line 111 of file ball.h.

111 {
112 return _holder;
113 };

◆ holder() [2/2]

node_t * ball_t::holder ( void ) const
inline

in whose pocket do I lie?

Definition at line 107 of file ball.h.

107 {
108 return _holder;
109 };
Here is the caller graph for this function:

◆ is()

bool ball_t::is ( color_t c) const
inline

is a given ball of the given color?

Definition at line 115 of file ball.h.

115 {
116 return color==c;
117 };
Here is the caller graph for this function:

◆ newick()

string_t ball_t::newick ( const slate_t & t,
bool showdeme ) const

Element of a Newick representation. This should only be called at tip-nodes.

Definition at line 14 of file newick.cc.

16{
17 assert(color==black);
18 string_t o = "[&&PhyloPOMP type=extant";
19 if (showdeme)
20 o += " deme=" + std::to_string(deme());
21 o += "]"
22 + std::to_string(uniq) +
23 ":" + std::to_string(t);
24 return o;
25}
@ black
Definition ball.h:12
name_t deme(void) const
view deme
Definition ball.h:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

ball_t & ball_t::operator= ( ball_t && )
delete

move assignment operator

Here is the call graph for this function:

◆ operator=() [2/2]

ball_t & ball_t::operator= ( const ball_t & )
delete

copy assignment operator

Here is the call graph for this function:

◆ owner() [1/2]

node_t *& ball_t::owner ( void )
inline

change owner of a green ball

Definition at line 97 of file ball.h.

97 {
98 assert(color==green);
99 return _owner;
100 };

◆ owner() [2/2]

node_t * ball_t::owner ( void ) const
inline

view owner of a green ball

Definition at line 92 of file ball.h.

92 {
93 assert(color==green);
94 return _owner;
95 };
Here is the caller graph for this function:

◆ structure()

SEXP ball_t::structure ( void ) const

R list description.

Definition at line 15 of file structure.cc.

17{
18 SEXP O, On, Name, Color, Deme;
19 int size = (is(black)) ? 3 : 2;
20 PROTECT(O = NEW_LIST(size));
21 PROTECT(On = NEW_CHARACTER(size));
22 PROTECT(Name = NEW_INTEGER(1));
23 *INTEGER(Name) = int(uniq);
24 PROTECT(Color = NEW_CHARACTER(1));
25 SET_STRING_ELT(Color,0,mkChar(color_symbol().c_str()));
26 set_list_elem(O,On,Name,"name",0);
27 set_list_elem(O,On,Color,"color",1);
28 if (is(black)) {
29 PROTECT(Deme = NEW_INTEGER(1));
30 *INTEGER(Deme) = int(deme());
31 set_list_elem(O,On,Deme,"deme",2);
32 UNPROTECT(1);
33 }
34 SET_NAMES(O,On);
35 UNPROTECT(4);
36 return O;
37}
string_t color_symbol(void) const
machine-readable color symbols
Definition ball.h:123
static int set_list_elem(SEXP list, SEXP names, SEXP element, const char *name, int pos)
Definition internal.h:76
Here is the call graph for this function:

◆ yaml()

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

human/machine-readable info

Definition at line 11 of file yaml.cc.

13{
14 string_t o;
15 o = "color: " + color_name() + "\n"
16 + tab + "name: " + std::to_string(uniq) + "\n";
17 if (color==black) {
18 o += tab + "deme: " + std::to_string(deme()) + "\n";
19 }
20 return o;
21}
string_t color_name(void) const
human-readable colors
Definition ball.h:119
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 ball_t & b,
raw_t * o )
friend

binary serialization

Definition at line 43 of file ball.h.

43 {
44 name_t buf[2] = {b.uniq, b._deme};
45 memcpy(o,buf,sizeof(buf)); o += sizeof(buf);
46 memcpy(o,&b.color,sizeof(color_t)); o += sizeof(color_t);
47 return o;
48 };
color_t
BALL COLORS.
Definition ball.h:12
size_t name_t
Definition internal.h:54

◆ operator>> [2/2]

raw_t * operator>> ( raw_t * o,
ball_t & b )
friend

binary deserialization

Definition at line 50 of file ball.h.

50 {
51 name_t buf[2];
52 memcpy(buf,o,sizeof(buf)); o += sizeof(buf);
53 b.uniq = buf[0]; b._deme = buf[1];
54 memcpy(&b.color,o,sizeof(color_t)); o += sizeof(color_t);
55 b._holder = 0; // must be set elsewhere
56 b._owner = 0; // must be set elsewhere
57 return o;
58 };

Field Documentation

◆ _deme

name_t ball_t::_deme
private

Definition at line 32 of file ball.h.

◆ _holder

node_t* ball_t::_holder
private

Definition at line 30 of file ball.h.

◆ _owner

node_t* ball_t::_owner
private

Definition at line 31 of file ball.h.

◆ bytesize

const size_t ball_t::bytesize = 2*sizeof(name_t)+sizeof(color_t)
static

size of binary serialization

Definition at line 41 of file ball.h.

◆ color

color_t ball_t::color

Definition at line 36 of file ball.h.

◆ uniq

name_t ball_t::uniq

Definition at line 35 of file ball.h.


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