2 Copyright 2006 Johnathan Corgan.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2
6 as published by the Free Software Foundation.
8 This software is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with GNU Radio; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street,
16 Boston, MA 02110-1301, USA.
19 // Application level includes
20 #include "samplelog.h"
26 // System level includes
29 SampleLog::SampleLog()
35 void SampleLog::Load(wxString filename)
37 m_file = new wxFile(filename.c_str(), wxFile::read_write);
40 if (m_file && m_file->IsOpened()) {
41 while (readline(line)) {
42 Sample sample(line); // can't use inline temporary in next line
43 Add(sample); // Locking is handled in Add
50 bool SampleLog::readline(wxString &line)
56 count = m_file->Read(&ch, 1);
57 while (count == 1 && ch != '\n') {
59 count = m_file->Read(&ch, 1);
62 return !line.IsEmpty();
65 void SampleLog::Add(Sample &sample)
67 wxMutexLocker locker(m_mutex);
70 m_save = m_samples.size();
72 m_samples.push_back(sample);
76 bool SampleLog::Save(wxString &filename)
78 wxASSERT(!m_file); // Save called with filename when it already exists is an error
79 wxLogError(_T("SampleLog::Save: called with %s when file already exists"), filename.c_str());
81 m_filename = filename;
82 m_file = new wxFile(m_filename.c_str(), wxFile::write);
87 bool SampleLog::Save()
93 wxMutexLocker locker(m_mutex);
96 if (m_file && m_file->IsOpened()) {
97 for (int i = m_save; i < m_samples.size(); i++) {
98 m_samples[i].Dump(str, 255);
99 m_file->Write(str, strlen(str));
100 m_file->Write("\n", strlen("\n"));