Skip to content

Commit

Permalink
Improve fdstreambuf with comment and explicit & default constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Feb 20, 2025
1 parent 162a161 commit 30d2222
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/lib/fcitx-utils/fdstreambuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace fcitx {

class IFDStreamBufPrivate;

/**
* Provides a streambuf for reading from file descriptor
*
* @since 5.1.13
*/
class FCITXUTILS_EXPORT IFDStreamBuf : public std::streambuf {

public:
Expand All @@ -25,10 +30,26 @@ class FCITXUTILS_EXPORT IFDStreamBuf : public std::streambuf {
using pos_type = base_type::pos_type;
using off_type = base_type::off_type;

IFDStreamBuf(UnixFD fd);
IFDStreamBuf(int fd);
/**
* Constructor that will make IFDStreamBuf own the file descriptor.
*
* You can use following code to make it own the file descriptor.
* @code{.cpp}
* IFDStreamBuf buf(UnixFD::own(fd));
* IFDStreamBuf(UnixFD::own(fd))
* @endcode
*/
explicit IFDStreamBuf(UnixFD fd);

/**
* Create an non-owning IFDStreamBuf
*/
explicit IFDStreamBuf(int fd = -1);
FCITX_DECLARE_VIRTUAL_DTOR_MOVE(IFDStreamBuf);

/**
* Return true if fd is not -1.
*/
bool is_open() const noexcept;

IFDStreamBuf *close();
Expand All @@ -52,6 +73,11 @@ class FCITXUTILS_EXPORT IFDStreamBuf : public std::streambuf {

class OFDStreamBufPrivate;

/**
* Provides a streambuf for writing to file descriptor
*
* @since 5.1.13
*/
class FCITXUTILS_EXPORT OFDStreamBuf : public std::streambuf {

public:
Expand All @@ -62,10 +88,25 @@ class FCITXUTILS_EXPORT OFDStreamBuf : public std::streambuf {
using pos_type = base_type::pos_type;
using off_type = base_type::off_type;

/**
* Constructor that will make OFDStreamBuf own the file descriptor.
*
* You can use following code to make it own the file descriptor.
* @code{.cpp}
* OFDStreamBuf buf(UnixFD::own(fd));
* @endcode
*/
OFDStreamBuf(UnixFD fd);
OFDStreamBuf(int fd);

/**
* Create an non-owning IFDStreamBuf
*/
OFDStreamBuf(int fd = -1);
FCITX_DECLARE_VIRTUAL_DTOR_MOVE(OFDStreamBuf);

/**
* Return true if fd is not -1.
*/
bool is_open() const noexcept;

OFDStreamBuf *close();
Expand Down

0 comments on commit 30d2222

Please sign in to comment.