Nsound  0.9.4
StreamOperators.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: StreamOperators.cc 879 2014-11-29 20:48:10Z weegreenblobbie $
4 //
5 // Copyright (c) 2009 to Present Nick Hilton
6 //
7 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
8 //
9 //-----------------------------------------------------------------------------
10 
11 //-----------------------------------------------------------------------------
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------------
28 
29 #include <Nsound/StreamOperators.h>
30 
31 namespace Nsound
32 {
33 
34 template <class T>
35 std::ostream &
36 _write(std::ostream & out, T value)
37 {
38  out.write(reinterpret_cast<char *>(&value), sizeof(T));
39  return out;
40 }
41 
42 std::ostream &
43 operator&(std::ostream & out, char value) { return _write(out, value); }
44 
45 std::ostream &
46 operator&(std::ostream & out, uint32 value) { return _write(out, value); }
47 
48 std::ostream &
49 operator&(std::ostream & out, uint64 value) { return _write(out, value); }
50 
51 std::ostream &
52 operator&(std::ostream & out, float32 value) { return _write(out, value); }
53 
54 std::ostream &
55 operator&(std::ostream & out, float64 value) { return _write(out, value); }
56 
57 template <class T>
58 std::istream &
59 _read(std::istream & in, T & value)
60 {
61  in.read(reinterpret_cast<char *>(&value), sizeof(T));
62  return in;
63 }
64 
65 std::istream &
66 operator&(std::istream & in, char & value) { return _read(in, value); }
67 
68 std::istream &
69 operator&(std::istream & in, uint32 & value) { return _read(in, value); }
70 
71 std::istream &
72 operator&(std::istream & in, uint64 & value) { return _read(in, value); }
73 
74 std::istream &
75 operator&(std::istream & in, float32 & value) { return _read(in, value); }
76 
77 std::istream &
78 operator&(std::istream & in, float64 & value) { return _read(in, value); }
79 
80 } // namespace
unsigned int uint32
Definition: Nsound.h:153
std::istream & _read(std::istream &in, T &value)
double float64
Definition: Nsound.h:146
std::ostream & _write(std::ostream &out, T value)
unsigned long long uint64
Definition: Nsound.h:154
float float32
Definition: Nsound.h:145
std::ostream & operator&(std::ostream &out, char value)