forked from pure-data/pure-data
/
ceammc_message.h
120 lines (103 loc) · 3.55 KB
/
ceammc_message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*****************************************************************************
* Copyright 2016 Serge Poltavsky. All rights reserved.
*
* This file may be distributed under the terms of GNU Public License version
* 3 (GPL v3) as defined by the Free Software Foundation (FSF). A copy of the
* license should have been included with this file, or the project in which
* this file belongs to. You may also find the details of GPL v3 at:
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* If you have any questions regarding the use of this file, feel free to
* contact the author of this file, or the owner of the project in which
* this file belongs to.
*****************************************************************************/
#ifndef CEAMMC_MESSAGE_H
#define CEAMMC_MESSAGE_H
#include "ceammc_atomlist.h"
namespace ceammc {
class Message {
public:
enum Type {
NONE,
BANG,
FLOAT,
SYMBOL,
POINTER,
LIST,
ANY,
DATA
};
private:
Type type_;
Atom value_;
AtomList v_list_;
public:
// create none
Message();
// create float
Message(t_float v);
// create symbol
Message(t_symbol* s);
Message(const Atom& a);
// create list
Message(const AtomList& l);
Message(const AtomListView& v);
Message(int argc, t_atom* argv);
// create any
Message(t_symbol* s, const AtomList& l);
Message(t_symbol* s, const AtomListView& v);
Message(t_symbol* s, int argc, t_atom* argv);
template <typename... Args>
Message(const char* s, Args... args)
: type_(ANY)
, value_(gensym(s))
, v_list_({ wrap_atom(args)... })
{
}
// copy/move
Message(const Message& m);
Message(Message&& m);
Message& operator=(const Message& m);
Message& operator=(Message&& m);
void setBang();
void setAtom(const Atom& a);
void setFloat(t_float v);
void setSymbol(t_symbol* s);
void setList(const AtomList& l);
void setList(int argc, t_atom* argv);
void setAny(t_symbol* s, const AtomList& l);
void setAny(t_symbol* s, int argc, t_atom* argv);
bool isEqual(const Message& v) const;
Type type() const;
void output(t_outlet* x) const;
inline bool isData() const { return type_ == DATA; }
inline bool isFloat() const { return type_ == FLOAT; }
inline bool isSymbol() const { return type_ == SYMBOL; }
inline bool isList() const { return type_ == LIST; }
inline bool isAny() const { return type_ == ANY; }
inline bool isNone() const { return type_ == NONE; }
inline bool isBang() const { return type_ == BANG; }
inline const Atom& atomValue() const { return value_; }
inline const AtomList& listValue() const { return v_list_; }
inline AtomList anyValue() const
{
AtomList res(v_list_);
res.insert(0, value_);
return res;
}
public:
static Message makeBang();
static Message makeTyped(const AtomListView& lv);
private:
static Atom wrap_atom(const char* str) { return Atom(gensym(str)); }
static Atom wrap_atom(t_symbol* s) { return Atom(s); }
static Atom wrap_atom(double d) { return Atom(static_cast<t_float>(d)); }
static Atom wrap_atom(float f) { return Atom(static_cast<t_float>(f)); }
static Atom wrap_atom(int i) { return Atom(i); }
static Atom wrap_atom(long l) { return Atom(l); }
};
bool operator==(const Message& c1, const Message& c2);
bool operator!=(const Message& c1, const Message& c2);
std::ostream& operator<<(std::ostream& os, const Message& m);
} // namespace ceammc
#endif // CEAMMC_MESSAGE_H