Audacity  2.2.2
Public Types | Public Member Functions | Private Attributes | List of all members
FileIO Class Reference

#include <FileIO.h>

Public Types

enum  FileIOMode { Input, Output }
 
typedef enum FileIO::FileIOMode FileIOMode
 

Public Member Functions

 FileIO (const wxString &name, FileIOMode mode)
 
 ~FileIO ()
 
bool IsOpened ()
 
bool Close ()
 
wxInputStream & Read (void *buffer, size_t size)
 
wxOutputStream & Write (const void *buffer, size_t size)
 

Private Attributes

wxString mName
 
FileIOMode mMode
 
std::unique_ptr< wxInputStream > mInputStream
 
std::unique_ptr
< wxFFileOutputStream > 
mOutputStream
 
bool mOpen
 

Detailed Description

Definition at line 18 of file FileIO.h.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
Input 
Output 

Definition at line 21 of file FileIO.h.

22  {
23  Input,
24  Output
25  } FileIOMode;
FileIOMode
Definition: FileIO.h:21

Constructor & Destructor Documentation

FileIO::FileIO ( const wxString &  name,
FileIOMode  mode 
)

Definition at line 20 of file FileIO.cpp.

References Input, mInputStream, mMode, mName, mOpen, and mOutputStream.

21 : mName(name),
22  mMode(mode),
23  mOpen(false)
24 {
25  wxString scheme;
26 
27  if (mMode == FileIO::Input) {
28  mInputStream = std::make_unique<wxFFileInputStream>(mName);
29  if (mInputStream == NULL || !mInputStream->IsOk()) {
30  wxPrintf(wxT("Couldn't get input stream: %s\n"), name);
31  return;
32  }
33  }
34  else {
35  mOutputStream = std::make_unique<wxFFileOutputStream>(mName);
36  if (mOutputStream == NULL || !mOutputStream->IsOk()) {
37  wxPrintf(wxT("Couldn't get output stream: %s\n"), name);
38  return;
39  }
40  }
41 
42  mOpen = true;
43 }
wxString mName
Definition: FileIO.h:41
std::unique_ptr< wxFFileOutputStream > mOutputStream
Definition: FileIO.h:44
std::unique_ptr< wxInputStream > mInputStream
Definition: FileIO.h:43
const wxChar * name
Definition: Distortion.cpp:94
FileIOMode mMode
Definition: FileIO.h:42
bool mOpen
Definition: FileIO.h:45
FileIO::~FileIO ( )

Definition at line 45 of file FileIO.cpp.

References Close().

46 {
47  Close();
48 }
bool Close()
Definition: FileIO.cpp:55

Member Function Documentation

bool FileIO::Close ( )

Definition at line 55 of file FileIO.cpp.

References mInputStream, mOpen, and mOutputStream.

Referenced by ~FileIO().

56 {
57  bool success = true;
58  if (mOutputStream) {
59  // mOutputStream->Sync() returns void! Rrr!
60  success = mOutputStream->GetFile()->Flush() &&
61  mOutputStream->Close();
62  mOutputStream.reset();
63  }
64  mInputStream.reset();
65  mOpen = false;
66  return success;
67 }
std::unique_ptr< wxFFileOutputStream > mOutputStream
Definition: FileIO.h:44
std::unique_ptr< wxInputStream > mInputStream
Definition: FileIO.h:43
bool mOpen
Definition: FileIO.h:45
bool FileIO::IsOpened ( )

Definition at line 50 of file FileIO.cpp.

References mOpen.

51 {
52  return mOpen;
53 }
bool mOpen
Definition: FileIO.h:45
wxInputStream & FileIO::Read ( void *  buffer,
size_t  size 
)

Definition at line 69 of file FileIO.cpp.

References mInputStream.

70 {
71  if (mInputStream == NULL) {
72  return *mInputStream;
73  }
74 
75  return mInputStream->Read(buf, size);
76 }
std::unique_ptr< wxInputStream > mInputStream
Definition: FileIO.h:43
wxOutputStream & FileIO::Write ( const void *  buffer,
size_t  size 
)

Definition at line 78 of file FileIO.cpp.

References mOutputStream.

79 {
80  if (mOutputStream == NULL) {
81  return *mOutputStream;
82  }
83 
84  return mOutputStream->Write(buf, size);
85 }
std::unique_ptr< wxFFileOutputStream > mOutputStream
Definition: FileIO.h:44

Member Data Documentation

std::unique_ptr<wxInputStream> FileIO::mInputStream
private

Definition at line 43 of file FileIO.h.

Referenced by Close(), FileIO(), and Read().

FileIOMode FileIO::mMode
private

Definition at line 42 of file FileIO.h.

Referenced by FileIO().

wxString FileIO::mName
private

Definition at line 41 of file FileIO.h.

Referenced by FileIO().

bool FileIO::mOpen
private

Definition at line 45 of file FileIO.h.

Referenced by Close(), FileIO(), and IsOpened().

std::unique_ptr<wxFFileOutputStream> FileIO::mOutputStream
private

Definition at line 44 of file FileIO.h.

Referenced by Close(), FileIO(), and Write().


The documentation for this class was generated from the following files: