phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
ball.h
Go to the documentation of this file.
1// -*- C++ -*-
2// BALL CLASS
3#ifndef _BALL_H_
4#define _BALL_H_
5
6#include "internal.h"
7
9
12typedef enum {green, blue, black} color_t;
13static const char* colores[] = {"green", "blue", "black"};
14static const char* colorsymb[] = {"g", "b", "o"};
15static const name_t undeme = 0;
16
17class node_t;
18
20
27class ball_t {
28
29private:
33
34public:
37
38public:
39
41 static const size_t bytesize = 2*sizeof(name_t)+sizeof(color_t);
43 friend raw_t* operator>> (const ball_t &b, raw_t *o) {
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 };
49
50 friend raw_t* operator>> (raw_t *o, ball_t &b) {
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 };
59
60public:
61
63 ball_t (node_t *who = 0, name_t u = 0,
64 color_t col = green, name_t d = undeme) {
65 _holder = _owner = who;
66 uniq = u;
67 color = col;
68 _deme = d;
69 };
70
71 ball_t (const ball_t&) = delete;
73 ball_t (ball_t&&) = delete;
75 ball_t & operator= (const ball_t&) = delete;
77 ball_t & operator= (ball_t&&) = delete;
79 ~ball_t (void) = default;
80
81public:
82
84 name_t deme (void) const {
85 return _deme;
86 };
87
88 name_t& deme (void) {
89 return _deme;
90 };
91
92 node_t* owner (void) const {
93 assert(color==green);
94 return _owner;
95 };
96
97 node_t*& owner (void) {
98 assert(color==green);
99 return _owner;
100 };
101
102 node_t* child (void) const {
103 assert(color==green);
104 return _owner;
105 };
106
107 node_t* holder (void) const {
108 return _holder;
109 };
110
111 node_t*& holder (void) {
112 return _holder;
113 };
114
115 bool is (color_t c) const {
116 return color==c;
117 };
118
119 string_t color_name (void) const {
120 return colores[color];
121 };
122
123 string_t color_symbol (void) const {
124 if (is(green) && _holder==_owner)
125 return "m"; // brown balls
126 else
127 return colorsymb[color];
128 };
129
130public:
131
133 string_t yaml (string_t tab = "") const;
135 SEXP structure (void) const;
138 string_t newick (const slate_t &t, bool showdeme) const;
139
140};
141
142#endif
color_t
BALL COLORS.
Definition ball.h:12
@ green
Definition ball.h:12
@ black
Definition ball.h:12
@ blue
Definition ball.h:12
static const name_t undeme
Definition ball.h:15
static const char * colorsymb[]
Definition ball.h:14
static const char * colores[]
Definition ball.h:13
node_t *& holder(void)
in whose pocket do I lie?
Definition ball.h:111
name_t & deme(void)
change deme
Definition ball.h:88
ball_t(ball_t &&)=delete
move constructor
node_t * owner(void) const
view owner of a green ball
Definition ball.h:92
name_t deme(void) const
view deme
Definition ball.h:84
name_t uniq
Definition ball.h:35
node_t * _holder
Definition ball.h:30
static const size_t bytesize
size of binary serialization
Definition ball.h:41
node_t * holder(void) const
in whose pocket do I lie?
Definition ball.h:107
SEXP structure(void) const
R list description.
Definition structure.cc:16
string_t newick(const slate_t &t, bool showdeme) const
Definition newick.cc:15
bool is(color_t c) const
is a given ball of the given color?
Definition ball.h:115
ball_t(node_t *who=0, name_t u=0, color_t col=green, name_t d=undeme)
basic constructor for ball class
Definition ball.h:63
node_t *& owner(void)
change owner of a green ball
Definition ball.h:97
string_t color_name(void) const
human-readable colors
Definition ball.h:119
~ball_t(void)=default
destructor
string_t yaml(string_t tab="") const
human/machine-readable info
Definition yaml.cc:12
ball_t(const ball_t &)=delete
copy constructor
color_t color
Definition ball.h:36
friend raw_t * operator>>(const ball_t &b, raw_t *o)
binary serialization
Definition ball.h:43
node_t * _owner
Definition ball.h:31
string_t color_symbol(void) const
machine-readable color symbols
Definition ball.h:123
ball_t & operator=(const ball_t &)=delete
copy assignment operator
node_t * child(void) const
a child is the owner of a green ball
Definition ball.h:102
name_t _deme
Definition ball.h:32
Encodes a genealogical node.
Definition node.h:21
Rbyte raw_t
Definition internal.h:52
size_t name_t
Definition internal.h:54
double slate_t
Definition internal.h:53