Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
instrumentfilehandler.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 #include "instrumentfilehandler.h"
21 
23 {}
24 
25 
26 //-----------------------------------------------------------------------------
27 // Write an arbitrary object to device
28 //-----------------------------------------------------------------------------
29 
30 template <class T>
31 bool InstrumentFileHandler::write(QIODevice &iodevice, const T &object)
32 {
33  char* objectptr = (char*)(&object);
34  size_t size = sizeof(object);
35  size_t bytes = static_cast<size_t>(iodevice.write (objectptr,size));
36  return (bytes == size);
37 }
38 
39 
40 
41 //-----------------------------------------------------------------------------
42 // Read an arbitrary object from device
43 //-----------------------------------------------------------------------------
44 
45 template <class T>
46 bool InstrumentFileHandler::read(QIODevice &iodevice, const T &object)
47 {
48  char* objectptr = (char*)(&object);
49  size_t size = sizeof(object);
50  size_t bytes = static_cast<size_t>(iodevice.read (objectptr,size));
51  return (bytes == size);
52 }
53 
54 
55 //-----------------------------------------------------------------------------
56 // Various implementations of write and read
57 //-----------------------------------------------------------------------------
58 
59 template bool InstrumentFileHandler::write<qint32> (QIODevice&,const qint32&);
60 template bool InstrumentFileHandler::read<qint32> (QIODevice&,const qint32&);
61 template bool InstrumentFileHandler::write<quint32> (QIODevice&,const quint32&);
62 template bool InstrumentFileHandler::read<quint32> (QIODevice&,const quint32&);
63 template bool InstrumentFileHandler::write<double> (QIODevice&,const double&);
64 template bool InstrumentFileHandler::read<double> (QIODevice&,const double&);
65 template bool InstrumentFileHandler::write<bool> (QIODevice&,const bool&);
66 template bool InstrumentFileHandler::read<bool> (QIODevice&,const bool&);
67 
68 
static bool read(QIODevice &iodevice, const T &object)
static bool write(QIODevice &iodevice, const T &object)