phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 More...
 
 ball_t (const ball_t &)=delete
 copy constructor More...
 
 ball_t (ball_t &&)=delete
 move constructor More...
 
ball_toperator= (const ball_t &)=delete
 copy assignment operator More...
 
ball_toperator= (ball_t &&)=delete
 move assignment operator More...
 
 ~ball_t (void)=default
 destructor More...
 
name_t deme (void) const
 view deme More...
 
name_tdeme (void)
 change deme More...
 
node_towner (void) const
 view owner of a green ball More...
 
node_t *& owner (void)
 change owner of a green ball More...
 
node_tchild (void) const
 a child is the owner of a green ball More...
 
node_tholder (void) const
 in whose pocket do I lie? More...
 
node_t *& holder (void)
 in whose pocket do I lie? More...
 
bool is (color_t c) const
 is a given ball of the given color? More...
 
std::string color_name (void) const
 human-readable colors More...
 
std::string color_symbol (void) const
 machine-readable color symbols More...
 
std::string describe (void) const
 human-readable info More...
 
std::string yaml (std::string tab="") const
 machine-readable info More...
 
SEXP structure (void) const
 R list description. More...
 
std::string newick (const slate_t &t) const
 element of a newick representation More...
 

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 More...
 

Private Attributes

node_t_holder
 
node_t_owner
 
name_t _deme
 

Friends

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

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 29 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 65 of file ball.h.

66  {
67  _holder = _owner = who;
68  uniq = u;
69  color = col;
70  _deme = d;
71  };
name_t uniq
Definition: ball.h:37
node_t * _holder
Definition: ball.h:32
color_t color
Definition: ball.h:38
node_t * _owner
Definition: ball.h:33
name_t _deme
Definition: ball.h:34

◆ ball_t() [2/3]

ball_t::ball_t ( const ball_t )
delete

copy constructor

◆ ball_t() [3/3]

ball_t::ball_t ( ball_t &&  )
delete

move constructor

◆ ~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 104 of file ball.h.

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

◆ color_name()

std::string ball_t::color_name ( void  ) const
inline

human-readable colors

Definition at line 121 of file ball.h.

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

◆ color_symbol()

std::string ball_t::color_symbol ( void  ) const
inline

machine-readable color symbols

Definition at line 125 of file ball.h.

125  {
126  if (is(green) && _holder==_owner)
127  return "m"; // brown balls
128  else
129  return colorsymb[color];
130  };
static const char * colorsymb[]
Definition: ball.h:16
bool is(color_t c) const
is a given ball of the given color?
Definition: ball.h:117
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 90 of file ball.h.

90  {
91  return _deme;
92  };

◆ deme() [2/2]

name_t ball_t::deme ( void  ) const
inline

view deme

Definition at line 86 of file ball.h.

86  {
87  return _deme;
88  };
Here is the caller graph for this function:

◆ describe()

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

human-readable info

Definition at line 135 of file ball.h.

135  {
136  std::string o = color_name()
137  + "(" + std::to_string(uniq) + ",";
138  if (_deme != undeme) {
139  o += std::to_string(_deme);
140  }
141  o += ")";
142  return o;
143  };
static const name_t undeme
Definition: ball.h:17
std::string color_name(void) const
human-readable colors
Definition: ball.h:121
Here is the call graph for this function:

◆ holder() [1/2]

node_t*& ball_t::holder ( void  )
inline

in whose pocket do I lie?

Definition at line 113 of file ball.h.

113  {
114  return _holder;
115  };

◆ holder() [2/2]

node_t* ball_t::holder ( void  ) const
inline

in whose pocket do I lie?

Definition at line 109 of file ball.h.

109  {
110  return _holder;
111  };
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 117 of file ball.h.

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

◆ newick()

std::string ball_t::newick ( const slate_t t) const
inline

element of a newick representation

Definition at line 177 of file ball.h.

177  {
178  return color_symbol()
179  + "_" + std::to_string(_deme)
180  + "_" + std::to_string(uniq)
181  + ":" + std::to_string(t);
182  };
std::string color_symbol(void) const
machine-readable color symbols
Definition: ball.h:125
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

◆ operator=() [2/2]

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

copy assignment operator

◆ owner() [1/2]

node_t*& ball_t::owner ( void  )
inline

change owner of a green ball

Definition at line 99 of file ball.h.

99  {
100  assert(color==green);
101  return _owner;
102  };

◆ owner() [2/2]

node_t* ball_t::owner ( void  ) const
inline

view owner of a green ball

Definition at line 94 of file ball.h.

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

◆ structure()

SEXP ball_t::structure ( void  ) const
inline

R list description.

Definition at line 155 of file ball.h.

155  {
156  SEXP O, On, Name, Color, Deme;
157  int size = (is(black)) ? 3 : 2;
158  PROTECT(O = NEW_LIST(size));
159  PROTECT(On = NEW_CHARACTER(size));
160  PROTECT(Name = NEW_INTEGER(1));
161  *INTEGER(Name) = int(uniq);
162  PROTECT(Color = NEW_CHARACTER(1));
163  SET_STRING_ELT(Color,0,mkChar(color_symbol().c_str()));
164  set_list_elem(O,On,Name,"name",0);
165  set_list_elem(O,On,Color,"color",1);
166  if (is(black)) {
167  PROTECT(Deme = NEW_INTEGER(1));
168  *INTEGER(Deme) = int(_deme);
169  set_list_elem(O,On,Deme,"deme",2);
170  UNPROTECT(1);
171  }
172  SET_NAMES(O,On);
173  UNPROTECT(4);
174  return O;
175  };
@ black
Definition: ball.h:14
static int set_list_elem(SEXP list, SEXP names, SEXP element, const char *name, int pos)
Definition: internal.h:67
Here is the call graph for this function:

◆ yaml()

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

machine-readable info

Definition at line 145 of file ball.h.

145  {
146  std::string o;
147  o = "color: " + color_name() + "\n"
148  + tab + "name: " + std::to_string(uniq) + "\n";
149  if (color==black) {
150  o += tab + "deme: " + std::to_string(_deme) + "\n";
151  }
152  return o;
153  };
Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator>> [1/2]

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

binary serialization

Definition at line 45 of file ball.h.

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

◆ operator>> [2/2]

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

binary deserialization

Definition at line 52 of file ball.h.

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

Field Documentation

◆ _deme

name_t ball_t::_deme
private

Definition at line 34 of file ball.h.

◆ _holder

node_t* ball_t::_holder
private

Definition at line 32 of file ball.h.

◆ _owner

node_t* ball_t::_owner
private

Definition at line 33 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 43 of file ball.h.

◆ color

color_t ball_t::color

Definition at line 38 of file ball.h.

◆ uniq

name_t ball_t::uniq

Definition at line 37 of file ball.h.


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