Jamoma API  0.6.0.a19
OscTypes.h
1 /*
2  oscpack -- Open Sound Control (OSC) packet manipulation library
3  http://www.rossbencina.com/code/oscpack
4 
5  Copyright (c) 2004-2013 Ross Bencina <rossb@audiomulch.com>
6 
7  Permission is hereby granted, free of charge, to any person obtaining
8  a copy of this software and associated documentation files
9  (the "Software"), to deal in the Software without restriction,
10  including without limitation the rights to use, copy, modify, merge,
11  publish, distribute, sublicense, and/or sell copies of the Software,
12  and to permit persons to whom the Software is furnished to do so,
13  subject to the following conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26 
27 /*
28  The text above constitutes the entire oscpack license; however,
29  the oscpack developer(s) also make the following non-binding requests:
30 
31  Any person wishing to distribute modifications to the Software is
32  requested to send the modifications to the original developer so that
33  they can be incorporated into the canonical version. It is also
34  requested that these non-binding requests be included whenever the
35  above license is reproduced.
36 */
37 #ifndef INCLUDED_OSCPACK_OSCTYPES_H
38 #define INCLUDED_OSCPACK_OSCTYPES_H
39 
40 
41 namespace osc{
42 
43 // basic types
44 
45 #if defined(__BORLANDC__) || defined(_MSC_VER)
46 
47 typedef __int64 int64;
48 typedef unsigned __int64 uint64;
49 
50 #elif defined(__x86_64__) || defined(_M_X64)
51 
52 typedef long int64;
53 typedef unsigned long uint64;
54 
55 #else
56 
57 typedef long long int64;
58 typedef unsigned long long uint64;
59 
60 #endif
61 
62 
63 
64 #if defined(__x86_64__) || defined(_M_X64)
65 
66 typedef signed int int32;
67 typedef unsigned int uint32;
68 
69 #else
70 
71 typedef signed long int32;
72 typedef unsigned long uint32;
73 
74 #endif
75 
76 
77 enum ValueTypeSizes{
78  OSC_SIZEOF_INT32 = 4,
79  OSC_SIZEOF_UINT32 = 4,
80  OSC_SIZEOF_INT64 = 8,
81  OSC_SIZEOF_UINT64 = 8,
82 };
83 
84 
85 // osc_bundle_element_size_t is used for the size of bundle elements and blobs
86 // the OSC spec specifies these as int32 (signed) but we ensure that they
87 // are always positive since negative field sizes make no sense.
88 
89 typedef int32 osc_bundle_element_size_t;
90 
91 enum {
92  OSC_INT32_MAX = 0x7FFFFFFF,
93 
94  // Element sizes are specified to be int32, and are always rounded up to nearest
95  // multiple of 4. Therefore their values can't be greater than 0x7FFFFFFC.
96  OSC_BUNDLE_ELEMENT_SIZE_MAX = 0x7FFFFFFC
97 };
98 
99 
100 inline bool IsValidElementSizeValue( osc_bundle_element_size_t x )
101 {
102  // sizes may not be negative or exceed OSC_BUNDLE_ELEMENT_SIZE_MAX
103  return x >= 0 && x <= OSC_BUNDLE_ELEMENT_SIZE_MAX;
104 }
105 
106 
107 inline bool IsMultipleOf4( osc_bundle_element_size_t x )
108 {
109  return (x & ((osc_bundle_element_size_t)0x03)) == 0;
110 }
111 
112 
113 enum TypeTagValues {
114  TRUE_TYPE_TAG = 'T',
115  FALSE_TYPE_TAG = 'F',
116  NIL_TYPE_TAG = 'N',
117  INFINITUM_TYPE_TAG = 'I',
118  INT32_TYPE_TAG = 'i',
119  FLOAT_TYPE_TAG = 'f',
120  CHAR_TYPE_TAG = 'c',
121  RGBA_COLOR_TYPE_TAG = 'r',
122  MIDI_MESSAGE_TYPE_TAG = 'm',
123  INT64_TYPE_TAG = 'h',
124  TIME_TAG_TYPE_TAG = 't',
125  DOUBLE_TYPE_TAG = 'd',
126  STRING_TYPE_TAG = 's',
127  SYMBOL_TYPE_TAG = 'S',
128  BLOB_TYPE_TAG = 'b',
129  ARRAY_BEGIN_TYPE_TAG = '[',
130  ARRAY_END_TYPE_TAG = ']'
131 };
132 
133 
134 
135 // i/o manipulators used for streaming interfaces
136 
137 struct BundleInitiator{
138  explicit BundleInitiator( uint64 timeTag_ ) : timeTag( timeTag_ ) {}
139  uint64 timeTag;
140 };
141 
142 extern BundleInitiator BeginBundleImmediate;
143 
144 inline BundleInitiator BeginBundle( uint64 timeTag=1 )
145 {
146  return BundleInitiator(timeTag);
147 }
148 
149 
150 struct BundleTerminator{
151 };
152 
153 extern BundleTerminator EndBundle;
154 
155 struct BeginMessage{
156  explicit BeginMessage( const char *addressPattern_ ) : addressPattern( addressPattern_ ) {}
157  const char *addressPattern;
158 };
159 
160 struct MessageTerminator{
161 };
162 
163 extern MessageTerminator EndMessage;
164 
165 
166 // osc specific types. they are defined as structs so they can be used
167 // as separately identifiable types with the streaming operators.
168 
169 struct NilType{
170 };
171 
172 extern NilType OscNil;
173 
174 #ifndef _OBJC_OBJC_H_
175 extern NilType Nil; // Objective-C defines Nil. so our Nil is deprecated. use OscNil instead
176 #endif
177 
178 struct InfinitumType{
179 };
180 
181 extern InfinitumType Infinitum;
182 
183 struct RgbaColor{
184  RgbaColor() {}
185  explicit RgbaColor( uint32 value_ ) : value( value_ ) {}
186  uint32 value;
187 
188  operator uint32() const { return value; }
189 };
190 
191 
192 struct MidiMessage{
193  MidiMessage() {}
194  explicit MidiMessage( uint32 value_ ) : value( value_ ) {}
195  uint32 value;
196 
197  operator uint32() const { return value; }
198 };
199 
200 
201 struct TimeTag{
202  TimeTag() {}
203  explicit TimeTag( uint64 value_ ) : value( value_ ) {}
204  uint64 value;
205 
206  operator uint64() const { return value; }
207 };
208 
209 
210 struct Symbol{
211  Symbol() {}
212  explicit Symbol( const char* value_ ) : value( value_ ) {}
213  const char* value;
214 
215  operator const char *() const { return value; }
216 };
217 
218 
219 struct Blob{
220  Blob() {}
221  explicit Blob( const void* data_, osc_bundle_element_size_t size_ )
222  : data( data_ ), size( size_ ) {}
223  const void* data;
224  osc_bundle_element_size_t size;
225 };
226 
227 struct ArrayInitiator{
228 };
229 
230 extern ArrayInitiator BeginArray;
231 
232 struct ArrayTerminator{
233 };
234 
235 extern ArrayTerminator EndArray;
236 
237 } // namespace osc
238 
239 
240 #endif /* INCLUDED_OSCPACK_OSCTYPES_H */