5 Copyright (C) 2011 Grame
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
30 #include "OSCFError.h"
37 //--------------------------------------------------------------------------
38 // Message implementation
39 //--------------------------------------------------------------------------
40 Message::Message(const Message
& msg
)
42 setAddress (msg
.address());
43 fArguments
= msg
.params();
46 //--------------------------------------------------------------------------
47 static string
escape (const string
& str
)
50 const char *ptr
= str
.c_str();
60 //--------------------------------------------------------------------------
61 void Message::print(std::ostream
& out
) const
63 out
<< address() << " " ;
64 argslist::const_iterator i
= params().begin();
66 ios::fmtflags f
= out
.flags ( ios::showpoint
);
67 while (i
!= params().end()) {
68 MsgParam
<string
>* s
= dynamic_cast<MsgParam
<string
>*>((baseparam
*)(*i
));
69 if (s
) out
<< "\"" << escape(s
->getValue()) << "\" ";
70 MsgParam
<int>* ip
= dynamic_cast<MsgParam
<int>*>((baseparam
*)(*i
));
71 if (ip
) out
<< ip
->getValue() << " ";
72 MsgParam
<float>* f
= dynamic_cast<MsgParam
<float>*>((baseparam
*)(*i
));
73 if (f
) out
<< f
->getValue() << " ";
79 //--------------------------------------------------------------------------
80 void Message::print(OSCStream
& out
) const
82 out
<< OSCStart(address().c_str());
87 //--------------------------------------------------------------------------
88 void Message::printArgs(OSCStream
& out
) const
90 for (int i
=0; i
< size(); i
++) {
91 string str
; float fv
; int iv
;
92 if (param(i
, fv
)) out
<< fv
;
93 else if (param(i
, iv
)) out
<< iv
;
94 else if (param(i
, str
)) out
<< str
;
95 else OSCFErr
<< "Message::print(OSCStream& out): unknown message parameter type" << OSCFEndl
;