Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RAII support for File class #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,37 @@ File::File(FRESULT result /* = FR_OK */)
_res = result;
}

File::File(File &&other)
{
_name = other._name;
_fil = other._fil;
_dir = other._dir;
_res = other._res;
other._name = NULL;
other._fil = NULL;
other._dir = {};
}

File &File::operator=(File &&other)
{
close();

_name = other._name;
_fil = other._fil;
_dir = other._dir;
_res = other._res;
other._name = NULL;
other._fil = NULL;
other._dir = {};

return *this;
}

File::~File()
{
close();
}

/** List directory contents to Serial.
*
* \param[in] flags The inclusive OR of
Expand Down
9 changes: 9 additions & 0 deletions src/STM32SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ uint8_t const LS_R = 4;
class File {
public:
File(FRESULT res = FR_OK);

File(const File &) = delete;
File &operator=(const File &) = delete;

File(File &&other);
File &operator=(File &&other);

virtual ~File();

virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
virtual size_t write(const char *buf, size_t size);
Expand Down
Loading