*** empty log message ***
[chuck-blob.git] / exile / v1 / src / chuck_oo.h
blobea282d5623d56183d88dd71c127b4d687a41ca18
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_oo.h
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Autumn 2002
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_OO_H__
34 #define __CHUCK_OO_H__
36 #include "chuck_def.h"
37 #include <assert.h>
38 #include <vector>
43 //-----------------------------------------------------------------------------
44 // name: struct Chuck_VM_Object
45 // dsec: base vm object
46 //-----------------------------------------------------------------------------
47 struct Chuck_VM_Object
49 public:
50 Chuck_VM_Object( t_CKBOOL pooled = FALSE )
51 { this->init_ref(); m_pooled = pooled; }
52 virtual ~Chuck_VM_Object() { }
53 virtual void init() { this->init_ref(); }
54 virtual void done() { }
56 public:
57 void init_ref() { m_ref_count = 0; }
58 void add_ref() { m_ref_count++; }
59 void release() { assert( m_ref_count > 0 ); m_ref_count--;
60 if( !m_ref_count )
61 if( !m_pooled ) delete this;
62 else assert( FALSE ); }
63 public:
64 t_CKUINT m_ref_count;
65 t_CKBOOL m_pooled;
71 //-----------------------------------------------------------------------------
72 // name: struct Chuck_Object
73 // dsec: base object
74 //-----------------------------------------------------------------------------
75 struct Chuck_Object : Chuck_VM_Object
76 { };
81 //-----------------------------------------------------------------------------
82 // name: struct Chuck_Array
83 // desc: native ChucK arrays
84 //-----------------------------------------------------------------------------
85 template<class T>
86 struct Chuck_Array : Chuck_Object
88 public:
89 Chuck_Array( t_CKINT size = 1 );
90 ~Chuck_Array();
92 public:
93 T operator[]( t_CKINT i );
95 public:
96 t_CKINT push_back( T val );
97 t_CKINT pop_back( );
98 T back( );
100 public:
101 std::vector<T> m_vector;
107 //-----------------------------------------------------------------------------
108 // name: Chuck_Event
109 // desc: base Chuck Event class
110 //-----------------------------------------------------------------------------
111 struct Chuck_Event : Chuck_Object
113 public:
114 Chuck_Event();
115 ~Chuck_Event();
117 public:
118 t_CKUINT signal();
119 t_CKUINT broadcast();
120 t_CKUINT wait();
126 #endif