2020-05-08 19:19:37 +00:00
|
|
|
#ifndef __NCPP_READER_HH
|
|
|
|
#define __NCPP_READER_HH
|
|
|
|
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
|
|
|
|
#include "NCAlign.hh"
|
2020-05-24 12:41:18 +00:00
|
|
|
#include "Plane.hh"
|
2020-05-22 20:11:59 +00:00
|
|
|
#include "Utilities.hh"
|
2020-05-08 19:19:37 +00:00
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
|
|
|
class NCPP_API_EXPORT Reader : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-09-13 17:53:11 +00:00
|
|
|
explicit Reader (Plane *p, const ncreader_options *opts)
|
|
|
|
: Reader (static_cast<const Plane*>(p), opts)
|
2020-05-08 19:19:37 +00:00
|
|
|
{}
|
|
|
|
|
2020-09-13 17:53:11 +00:00
|
|
|
explicit Reader (Plane const* p, const ncreader_options *opts)
|
2020-05-24 12:41:18 +00:00
|
|
|
: Root (Utilities::get_notcurses_cpp (p))
|
|
|
|
{
|
|
|
|
if (p == nullptr)
|
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
|
2020-09-13 17:53:11 +00:00
|
|
|
common_init (Utilities::to_ncplane (p), opts);
|
2020-05-24 12:41:18 +00:00
|
|
|
}
|
2020-05-08 19:19:37 +00:00
|
|
|
|
2020-09-13 17:53:11 +00:00
|
|
|
explicit Reader (Plane &p, const ncreader_options *opts)
|
|
|
|
: Reader (static_cast<Plane const&>(p), opts)
|
2020-05-08 19:19:37 +00:00
|
|
|
{}
|
|
|
|
|
2020-09-13 17:53:11 +00:00
|
|
|
explicit Reader (Plane const& p, const ncreader_options *opts)
|
2020-05-24 12:41:18 +00:00
|
|
|
: Root (Utilities::get_notcurses_cpp (p))
|
2020-05-08 19:19:37 +00:00
|
|
|
{
|
2020-09-13 17:53:11 +00:00
|
|
|
common_init (Utilities::to_ncplane (p), opts);
|
2020-05-08 19:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Reader ()
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
|
|
|
ncreader_destroy (reader, nullptr);
|
|
|
|
}
|
|
|
|
|
2020-05-24 08:07:12 +00:00
|
|
|
bool clear () const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
bool ret = ncreader_clear (reader) != 0;
|
|
|
|
return error_guard_cond<bool, bool> (ret, ret);
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:19:37 +00:00
|
|
|
char* get_contents () const noexcept
|
|
|
|
{
|
|
|
|
return ncreader_contents(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
Plane* get_plane () const noexcept
|
|
|
|
{
|
|
|
|
return Plane::map_plane (ncreader_plane (reader));
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
private:
|
2020-09-13 17:53:11 +00:00
|
|
|
void common_init (ncplane *n, const ncreader_options *opts)
|
2020-05-24 12:41:18 +00:00
|
|
|
{
|
2020-09-13 17:53:11 +00:00
|
|
|
reader = ncreader_create (n, opts);
|
2020-05-24 12:41:18 +00:00
|
|
|
if (reader == nullptr)
|
|
|
|
throw init_error ("Notcurses failed to create a new reader");
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:19:37 +00:00
|
|
|
private:
|
|
|
|
ncreader *reader;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|