From 5d6a85ca9a6eb366f7e093c79afdfe52ddeb6943 Mon Sep 17 00:00:00 2001 From: Benny Baumann <BenBE@geshi.org> Date: Sun, 9 Dec 2018 19:15:28 +0100 Subject: [PATCH] chg: Use RAII for resource management on ncurses control --- src/app/rmrf.cpp | 10 +++------- src/{ui/View.ldflags => app/rmrf.ldflags} | 0 src/ui/View.cpp | 12 +++++------- src/ui/View.h | 16 ++++++++-------- 4 files changed, 16 insertions(+), 22 deletions(-) rename src/{ui/View.ldflags => app/rmrf.ldflags} (100%) diff --git a/src/app/rmrf.cpp b/src/app/rmrf.cpp index f23f389..1d94605 100644 --- a/src/app/rmrf.cpp +++ b/src/app/rmrf.cpp @@ -1,11 +1,7 @@ -#include "../ui/View.h" - -namespace rmrf { +#include "ui/View.h" int main() { - ui::init_ui(); - ui::destroy_ui(); - return 0; -} + auto ui_handle = std::make_shared<rmrf::ui::display>(); + return 0; } diff --git a/src/ui/View.ldflags b/src/app/rmrf.ldflags similarity index 100% rename from src/ui/View.ldflags rename to src/app/rmrf.ldflags diff --git a/src/ui/View.cpp b/src/ui/View.cpp index b86898e..f39ecc3 100644 --- a/src/ui/View.cpp +++ b/src/ui/View.cpp @@ -1,17 +1,15 @@ -#include <ncurses/ncursesw.h> +#include <ncursesw/ncurses.h> -#include "View.h" +#include "ui/View.h" -namespace rmrf { -namespace ui { +namespace rmrf::ui { -void init_ui() { +display::display() { initscr(); } -void destroy_ui() { +display::~display() { endwin(); } } -} diff --git a/src/ui/View.h b/src/ui/View.h index ef6ff63..afaf84d 100644 --- a/src/ui/View.h +++ b/src/ui/View.h @@ -1,12 +1,12 @@ -#ifndef VIEW_H -#define VIEW_H +#pragma once -namespace rmrf { -namespace ui { +#include <memory> -void init_ui(void); -void destroy_ui(void); +namespace rmrf::ui { + +struct display : std::enable_shared_from_this<display> { + display(); + ~display(); +}; } -} -#endif -- GitLab