1 |
/* |
---|
2 |
* Copyright (C) 2005-2007 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This library is free software; you can redistribute it and/or |
---|
10 |
* modify it under the terms of the GNU Lesser General Public |
---|
11 |
* License version 2.1, as published by the Free Software Foundation; |
---|
12 |
* |
---|
13 |
* This library is distributed in the hope that it will be useful, |
---|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 |
* Lesser General Public License for more details. |
---|
17 |
* |
---|
18 |
* You should have received a copy of the GNU Lesser General Public |
---|
19 |
* License along with this library; if not, write to the Free Software |
---|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
21 |
* MA 02110-1301 USA |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#include "OscArgument.h" |
---|
25 |
|
---|
26 |
namespace OSC { |
---|
27 |
|
---|
28 |
IMPL_DEBUG_MODULE( OscArgument, OscArgument, DEBUG_LEVEL_VERBOSE ); |
---|
29 |
|
---|
30 |
OscArgument::OscArgument(int32_t i) |
---|
31 |
: m_isInt(true) |
---|
32 |
, m_intVal(i) |
---|
33 |
, m_isInt64(false) |
---|
34 |
, m_int64Val(0) |
---|
35 |
, m_isFloat(false) |
---|
36 |
, m_floatVal(0.0) |
---|
37 |
, m_isString(false) |
---|
38 |
, m_stringVal("") |
---|
39 |
{} |
---|
40 |
|
---|
41 |
OscArgument::OscArgument(int64_t i) |
---|
42 |
: m_isInt(false) |
---|
43 |
, m_intVal(0) |
---|
44 |
, m_isInt64(true) |
---|
45 |
, m_int64Val(i) |
---|
46 |
, m_isFloat(false) |
---|
47 |
, m_floatVal(0.0) |
---|
48 |
, m_isString(false) |
---|
49 |
, m_stringVal("") |
---|
50 |
{} |
---|
51 |
|
---|
52 |
OscArgument::OscArgument(float f) |
---|
53 |
: m_isInt(false) |
---|
54 |
, m_intVal(0) |
---|
55 |
, m_isInt64(false) |
---|
56 |
, m_int64Val(0) |
---|
57 |
, m_isFloat(true) |
---|
58 |
, m_floatVal(f) |
---|
59 |
, m_isString(false) |
---|
60 |
, m_stringVal("") |
---|
61 |
{} |
---|
62 |
|
---|
63 |
OscArgument::OscArgument(string s) |
---|
64 |
: m_isInt(false) |
---|
65 |
, m_intVal(0) |
---|
66 |
, m_isInt64(false) |
---|
67 |
, m_int64Val(0) |
---|
68 |
, m_isFloat(false) |
---|
69 |
, m_floatVal(0.0) |
---|
70 |
, m_isString(true) |
---|
71 |
, m_stringVal(s) |
---|
72 |
{} |
---|
73 |
|
---|
74 |
OscArgument::~OscArgument() |
---|
75 |
{} |
---|
76 |
|
---|
77 |
bool |
---|
78 |
OscArgument::operator == ( const OscArgument& rhs ) |
---|
79 |
{ |
---|
80 |
if(m_isInt && rhs.m_isInt) { |
---|
81 |
return m_intVal == rhs.m_intVal; |
---|
82 |
} else if(m_isInt64 && rhs.m_isInt64) { |
---|
83 |
return m_int64Val == rhs.m_int64Val; |
---|
84 |
} else if(m_isFloat && rhs.m_isFloat) { |
---|
85 |
return m_floatVal == rhs.m_floatVal; |
---|
86 |
} else if(m_isString && rhs.m_isString) { |
---|
87 |
return m_stringVal == rhs.m_stringVal; |
---|
88 |
} else { |
---|
89 |
return false; |
---|
90 |
} |
---|
91 |
} |
---|
92 |
|
---|
93 |
int32_t |
---|
94 |
OscArgument::toInt() { |
---|
95 |
if(m_isInt) { |
---|
96 |
return m_intVal; |
---|
97 |
} else if(m_isInt64) { |
---|
98 |
return (int32_t)(m_int64Val & 0xFFFFFFFF); |
---|
99 |
} else if(m_isFloat) { |
---|
100 |
return (int32_t)(m_floatVal); |
---|
101 |
} else { |
---|
102 |
return 0; |
---|
103 |
} |
---|
104 |
} |
---|
105 |
|
---|
106 |
int64_t |
---|
107 |
OscArgument::toInt64() { |
---|
108 |
if(m_isInt) { |
---|
109 |
return (int64_t)(m_intVal); |
---|
110 |
} else if(m_isInt64) { |
---|
111 |
return m_int64Val; |
---|
112 |
} else if(m_isFloat) { |
---|
113 |
return (int64_t)(m_floatVal); |
---|
114 |
} else { |
---|
115 |
return 0; |
---|
116 |
} |
---|
117 |
} |
---|
118 |
|
---|
119 |
float |
---|
120 |
OscArgument::toFloat() { |
---|
121 |
if(m_isInt) { |
---|
122 |
return (float)(m_intVal); |
---|
123 |
} else if(m_isInt64) { |
---|
124 |
return (float)(m_int64Val); |
---|
125 |
} else if(m_isFloat) { |
---|
126 |
return m_floatVal; |
---|
127 |
} else { |
---|
128 |
return 0; |
---|
129 |
} |
---|
130 |
} |
---|
131 |
|
---|
132 |
void |
---|
133 |
OscArgument::print() |
---|
134 |
{ |
---|
135 |
debugOutput(DEBUG_LEVEL_NORMAL, " Argument "); |
---|
136 |
if(m_isInt) { |
---|
137 |
debugOutputShort(DEBUG_LEVEL_NORMAL, " Int : %ld\n", m_intVal); |
---|
138 |
} else if(m_isInt64) { |
---|
139 |
debugOutputShort(DEBUG_LEVEL_NORMAL, " Int64 : %lld\n", m_int64Val); |
---|
140 |
} else if(m_isFloat) { |
---|
141 |
debugOutputShort(DEBUG_LEVEL_NORMAL, " Float : %f\n", m_floatVal); |
---|
142 |
} else if(m_isString) { |
---|
143 |
debugOutputShort(DEBUG_LEVEL_NORMAL, " String : %s\n", m_stringVal.c_str()); |
---|
144 |
} else { |
---|
145 |
debugOutputShort(DEBUG_LEVEL_NORMAL, " Empty\n"); |
---|
146 |
} |
---|
147 |
} |
---|
148 |
|
---|
149 |
} // end of namespace OSC |
---|