flatom.cpp 2.68 KB
Newer Older
thomas's avatar
thomas committed
1
/* 
thomas's avatar
thomas committed
2

thomas's avatar
thomas committed
3
flext - C++ layer for Max/MSP and pd (pure data) externals
thomas's avatar
thomas committed
4

thomas's avatar
thomas committed
5
6
7
8
9
10
11
12
13
Copyright (c) 2001,2002 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  

*/

/*! \file flatom.cpp
    \brief Definitions for handling the t_atom type and lists thereof.
*/
thomas's avatar
thomas committed
14
 
thomas's avatar
thomas committed
15
#include "flext.h"
thomas's avatar
thomas committed
16

thomas's avatar
thomas committed
17
//namespace flext {
thomas's avatar
thomas committed
18

thomas's avatar
thomas committed
19
flext::AtomList::AtomList(int argc,const t_atom *argv):
thomas's avatar
thomas committed
20
	lst(NULL),cnt(0)
thomas's avatar
thomas committed
21
{
thomas's avatar
thomas committed
22
23
24
	operator()(argc,argv);
}

thomas's avatar
thomas committed
25
flext::AtomList::AtomList(const AtomList &a):
thomas's avatar
thomas committed
26
27
28
29
30
	lst(NULL),cnt(0)
{
	operator =(a);
}

thomas's avatar
thomas committed
31
flext::AtomList::~AtomList() {	Clear(); }
thomas's avatar
thomas committed
32

thomas's avatar
thomas committed
33
flext::AtomList &flext::AtomList::operator()(int argc,const t_atom *argv)
thomas's avatar
thomas committed
34
{
thomas's avatar
thomas committed
35
	if(lst && cnt != argc) { delete[] lst; lst = NULL; cnt = 0; }
thomas's avatar
thomas committed
36
37
38
39
40
41

	if(argc) {
		cnt = argc;
		lst = new t_atom[cnt];

		if(argv) {
thomas's avatar
thomas committed
42
43
44
			for(int i = 0; i < argc; ++i) SetAtom(lst[i],argv[i]);
/*			
			{
thomas's avatar
thomas committed
45
46
47
48
				switch(lst[i].a_type = argv[i].a_type) {
				case A_FLOAT:
					lst[i].a_w.w_float = argv[i].a_w.w_float;
					break;
thomas's avatar
thomas committed
49
#ifdef MAXMSP
thomas's avatar
thomas committed
50
51
52
				case A_LONG:
					lst[i].a_w.w_int = argv[i].a_w.w_int;
					break;
thomas's avatar
thomas committed
53
#endif
thomas's avatar
thomas committed
54
55
56
				case A_SYMBOL:
					lst[i].a_w.w_symbol = argv[i].a_w.w_symbol;
					break;
thomas's avatar
thomas committed
57
#ifdef PD
thomas's avatar
thomas committed
58
59
60
				case A_POINTER:
					lst[i].a_w.w_gpointer = argv[i].a_w.w_gpointer;
					break;
thomas's avatar
thomas committed
61
#endif
thomas's avatar
thomas committed
62
63
64
65
66
				default:
					post("AtomList - atom type (%i) not supported",lst[i].a_type);
					lst[i].a_type = A_NULL;
					break;
				}
thomas's avatar
thomas committed
67
			}
thomas's avatar
thomas committed
68
*/
thomas's avatar
thomas committed
69
70
		}
	}
thomas's avatar
thomas committed
71
	return *this;
thomas's avatar
thomas committed
72
73
}

thomas's avatar
thomas committed
74

thomas's avatar
thomas committed
75
flext::AtomList &flext::AtomList::Append(const t_atom &a)
thomas's avatar
thomas committed
76
77
78
79
80
{
	t_atom *nlst = new t_atom[cnt+1];
	for(int i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]);
	SetAtom(nlst[cnt],a);
	
thomas's avatar
thomas committed
81
82
	if(lst) delete[] lst;
 	lst = nlst;
thomas's avatar
thomas committed
83
84
85
86
87
	++cnt;

	return *this;
}

thomas's avatar
thomas committed
88
flext::AtomList &flext::AtomList::Append(int argc,const t_atom *argv)
thomas's avatar
thomas committed
89
{
thomas's avatar
thomas committed
90
	t_atom *nlst = new t_atom[cnt+argc];
thomas's avatar
thomas committed
91
92
	int i;
	for(i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]);
thomas's avatar
thomas committed
93
	for(i = 0; i < argc; ++i) SetAtom(nlst[cnt+i],argv[i]);
thomas's avatar
thomas committed
94
	
thomas's avatar
thomas committed
95
	if(lst) delete[] lst;
thomas's avatar
thomas committed
96
	lst = nlst;
thomas's avatar
thomas committed
97
	cnt += argc;
thomas's avatar
thomas committed
98
99
100
101

	return *this;
}

thomas's avatar
thomas committed
102
flext::AtomList &flext::AtomList::Prepend(const t_atom &a)
thomas's avatar
thomas committed
103
104
105
106
107
{
	t_atom *nlst = new t_atom[cnt+1];
	for(int i = 0; i < cnt; ++i) SetAtom(nlst[i+1],lst[i]);
	SetAtom(nlst[0],a);
	
thomas's avatar
thomas committed
108
	if(lst) delete[] lst;
thomas's avatar
thomas committed
109
110
111
112
113
114
	lst = nlst;
	++cnt;

	return *this;
}

thomas's avatar
thomas committed
115
flext::AtomList &flext::AtomList::Prepend(int argc,const t_atom *argv)
thomas's avatar
thomas committed
116
{
thomas's avatar
thomas committed
117
	t_atom *nlst = new t_atom[cnt+argc];
thomas's avatar
thomas committed
118
	int i;
thomas's avatar
thomas committed
119
120
	for(i = 0; i < argc; ++i) SetAtom(nlst[i],argv[i]);
	for(i = 0; i < cnt; ++i) SetAtom(nlst[argc+i],lst[i]);
thomas's avatar
thomas committed
121
	
thomas's avatar
thomas committed
122
	if(lst) delete[] lst;
thomas's avatar
thomas committed
123
	lst = nlst;
thomas's avatar
thomas committed
124
	cnt += argc;
thomas's avatar
thomas committed
125
126
127

	return *this;
}
thomas's avatar
thomas committed
128

thomas's avatar
thomas committed
129
flext::AtomList flext::AtomList::GetPart(int offs,int len) const
thomas's avatar
thomas committed
130
131
132
133
134
135
136
137
138
{
	if(offs+len > Count()) {
		len = Count()-offs;
		if(len < 0) len = 0;
	}

	return AtomList(len,Atoms()+offs);
}

thomas's avatar
thomas committed
139
//} // namespace flext