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

#include <FileIO.h>

Collaboration diagram for FileIO:
[legend]

Public Types

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

Public Member Functions

 FileIO (const wxFileNameWrapper &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

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

Detailed Description

Definition at line 21 of file FileIO.h.

Member Typedef Documentation

◆ FileIOMode

Member Enumeration Documentation

◆ FileIOMode

Enumerator
Input 
Output 

Definition at line 24 of file FileIO.h.

25 {
26 Input,
27 Output
28 } FileIOMode;
FileIOMode
Definition: FileIO.h:25
@ Input
Definition: FileIO.h:26
@ Output
Definition: FileIO.h:27

Constructor & Destructor Documentation

◆ FileIO()

FileIO::FileIO ( const wxFileNameWrapper name,
FileIOMode  mode 
)

Definition at line 19 of file FileIO.cpp.

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

References Input, mInputStream, mMode, mOpen, mOutputStream, name, and wxT().

Here is the call graph for this function:

◆ ~FileIO()

FileIO::~FileIO ( )

Definition at line 44 of file FileIO.cpp.

45{
46 Close();
47}
bool Close()
Definition: FileIO.cpp:54

References Close().

Here is the call graph for this function:

Member Function Documentation

◆ Close()

bool FileIO::Close ( )

Definition at line 54 of file FileIO.cpp.

55{
56 bool success = true;
57 if (mOutputStream) {
58 // mOutputStream->Sync() returns void! Rrr!
59 success = mOutputStream->GetFile()->Flush() &&
60 mOutputStream->Close();
61 mOutputStream.reset();
62 }
63 mInputStream.reset();
64 mOpen = false;
65 return success;
66}

References mInputStream, mOpen, and mOutputStream.

Referenced by ~FileIO().

Here is the caller graph for this function:

◆ IsOpened()

bool FileIO::IsOpened ( )

Definition at line 49 of file FileIO.cpp.

50{
51 return mOpen;
52}

References mOpen.

◆ Read()

wxInputStream & FileIO::Read ( void *  buffer,
size_t  size 
)

Definition at line 68 of file FileIO.cpp.

69{
70 if (mInputStream == NULL) {
71 return *mInputStream;
72 }
73
74 return mInputStream->Read(buf, size);
75}

References mInputStream, and size.

◆ Write()

wxOutputStream & FileIO::Write ( const void *  buffer,
size_t  size 
)

Definition at line 77 of file FileIO.cpp.

78{
79 if (mOutputStream == NULL) {
80 return *mOutputStream;
81 }
82
83 return mOutputStream->Write(buf, size);
84}

References mOutputStream, and size.

Member Data Documentation

◆ mInputStream

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

Definition at line 45 of file FileIO.h.

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

◆ mMode

FileIOMode FileIO::mMode
private

Definition at line 44 of file FileIO.h.

Referenced by FileIO().

◆ mOpen

bool FileIO::mOpen
private

Definition at line 47 of file FileIO.h.

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

◆ mOutputStream

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

Definition at line 46 of file FileIO.h.

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


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