notcurses/include/ncpp/Tablet.hh

62 lines
1.0 KiB
C++
Raw Normal View History

2020-01-07 22:51:34 +00:00
#ifndef __NCPP_TABLET_HH
#define __NCPP_TABLET_HH
#include <map>
#include <mutex>
#include <notcurses/notcurses.h>
2020-01-07 22:51:34 +00:00
#include "Root.hh"
namespace ncpp
{
class Plane;
class NCPP_API_EXPORT NcTablet : public Root
2020-01-07 22:51:34 +00:00
{
protected:
explicit NcTablet (nctablet *t)
2020-01-07 22:51:34 +00:00
: _tablet (t)
{
if (t == nullptr)
throw invalid_argument ("'t' must be a valid pointer");
2020-01-07 22:51:34 +00:00
};
public:
template<typename T>
T* get_userptr () const noexcept
{
return static_cast<T*>(nctablet_userptr (_tablet));
2020-01-07 22:51:34 +00:00
}
operator nctablet* () const noexcept
2020-01-07 22:51:34 +00:00
{
return _tablet;
}
operator nctablet const* () const noexcept
2020-01-07 22:51:34 +00:00
{
return _tablet;
}
Plane* get_plane () const noexcept;
static NcTablet* map_tablet (nctablet *t) noexcept;
2020-01-07 22:51:34 +00:00
protected:
static void unmap_tablet (NcTablet *p) noexcept;
2020-01-07 22:51:34 +00:00
nctablet* get_tablet () const noexcept
2020-01-07 22:51:34 +00:00
{
return _tablet;
}
private:
nctablet *_tablet = nullptr;
static std::map<nctablet*,NcTablet*> *tablet_map;
2020-01-07 22:51:34 +00:00
static std::mutex tablet_map_mutex;
2020-02-05 22:29:42 +00:00
friend class NcReel;
2020-01-07 22:51:34 +00:00
};
}
#endif