|
From: <pst...@us...> - 2013-03-17 23:04:55
|
Revision: 963
http://sourceforge.net/p/jazzplusplus/code/963
Author: pstieber
Date: 2013-03-17 23:04:53 +0000 (Sun, 17 Mar 2013)
Log Message:
-----------
1. Updated to use std::string for file names.
2. Updated to use C++ streams instead of C-style I/O.
Modified Paths:
--------------
trunk/jazz/src/Events.cpp
trunk/jazz/src/Events.h
Modified: trunk/jazz/src/Events.cpp
===================================================================
--- trunk/jazz/src/Events.cpp 2013-03-17 23:02:54 UTC (rev 962)
+++ trunk/jazz/src/Events.cpp 2013-03-17 23:04:53 UTC (rev 963)
@@ -27,10 +27,6 @@
#include "JazzPlusPlusApplication.h"
#include "Synth.h"
-#include <cassert>
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
#include <sstream>
using namespace std;
@@ -42,7 +38,7 @@
JZReadBase::JZReadBase()
: mTicksPerQuarter(0),
mTrackCount(0),
- mpFd(NULL)
+ mIfs()
{
}
@@ -54,23 +50,16 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-int JZReadBase::Open(const char* pFileName)
+int JZReadBase::Open(const string& FileName)
{
- if (pFileName == NULL)
+ mIfs.open(FileName.c_str(), ios::binary);
+ if (!mIfs)
{
- mpFd = stdin;
+ ostringstream Oss;
+ Oss << "Error opening file " << FileName;
+ Error(Oss.str());
+ return 0;
}
- else
- {
- mpFd = fopen(pFileName, "rb");
- if (mpFd == NULL)
- {
- ostringstream Oss;
- Oss << "Error opening file " << pFileName;
- Error(Oss.str());
- return 0;
- }
- }
return 1;
}
@@ -78,10 +67,7 @@
//-----------------------------------------------------------------------------
void JZReadBase::Close()
{
- if (mpFd != stdin)
- {
- fclose(mpFd);
- }
+ mIfs.close();
}
//*****************************************************************************
@@ -89,7 +75,7 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
JZWriteBase::JZWriteBase()
- : mpFd(NULL)
+ : mOfs()
{
}
@@ -102,40 +88,18 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int JZWriteBase::Open(
- const char* pFileName,
+ const string& FileName,
int TrackCount,
int TicksPerQuarter)
{
- if (pFileName == NULL)
+ mOfs.open(FileName.c_str(), ios::binary);
+ if (!mOfs)
{
- mpFd = stdout;
+ ostringstream Oss;
+ Oss << "Error opening file " << FileName;
+ Error(Oss.str());
+ return 0;
}
- else
- {
-#ifndef __WXMSW__
- FILE *testfd = fopen(pFileName, "r");
- if (testfd)
- {
- fclose(testfd);
- char *syscmd;
- syscmd = new char[strlen("cp") + 2 * strlen(pFileName) + strlen(".backup") + 3];
- sprintf(syscmd, "cp %s %s.backup", pFileName, pFileName);
- if (system(syscmd) != 0)
- {
- fprintf(stderr, "Could not make backup file %s.backup\n", pFileName);
- }
- delete syscmd;
- }
-#endif
- mpFd = fopen(pFileName, "wb");
- if (mpFd == NULL)
- {
- ostringstream Oss;
- Oss << "Error opening file " << pFileName;
- Error(Oss.str());
- return 0;
- }
- }
return TrackCount;
}
@@ -143,10 +107,7 @@
//-----------------------------------------------------------------------------
void JZWriteBase::Close()
{
- if (mpFd != stdout)
- {
- fclose(mpFd);
- }
+ mOfs.close();
}
//*****************************************************************************
Modified: trunk/jazz/src/Events.h
===================================================================
--- trunk/jazz/src/Events.h 2013-03-17 23:02:54 UTC (rev 962)
+++ trunk/jazz/src/Events.h 2013-03-17 23:04:53 UTC (rev 963)
@@ -22,7 +22,8 @@
#pragma once
-#include <cstdio>
+#include <fstream>
+#include <string>
#include <wx/pen.h>
@@ -42,7 +43,7 @@
virtual ~JZReadBase();
- virtual int Open(const char* pFileName);
+ virtual int Open(const std::string& FileName);
virtual void Close();
@@ -59,7 +60,7 @@
int mTrackCount;
- FILE* mpFd;
+ std::ifstream mIfs;
};
//*****************************************************************************
@@ -85,7 +86,7 @@
virtual ~JZWriteBase();
virtual int Open(
- const char* pFileName,
+ const std::string& FileName,
int TrackCount,
int TicksPerQuarter);
@@ -122,7 +123,7 @@
protected:
- FILE* mpFd;
+ std::ofstream mOfs;
};
//*****************************************************************************
@@ -212,7 +213,7 @@
{
public:
- int Open(const char* pFileName, int nTracks, int TicksPerQuarter)
+ int Open(const std::string& FileName, int nTracks, int TicksPerQuarter)
{
return 1;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|