From e2fbc55ad81b55827efec2012503ccf8b48c4671 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Thu, 22 Sep 2011 10:50:26 +0000 Subject: [PATCH] Glibmm: Add the common QofInstance methods by using an additional base class. Not yet complete, but at least compiles fine. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21294 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/optional/gtkmm/Makefile.am | 1 + src/optional/gtkmm/gncmm/Account.hpp | 3 +- src/optional/gtkmm/gncmm/GncInstance.hpp | 90 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/optional/gtkmm/gncmm/GncInstance.hpp diff --git a/src/optional/gtkmm/Makefile.am b/src/optional/gtkmm/Makefile.am index c9181bcc60..816fba6390 100644 --- a/src/optional/gtkmm/Makefile.am +++ b/src/optional/gtkmm/Makefile.am @@ -15,6 +15,7 @@ noinst_HEADERS = \ gncmm/Account.hpp \ gncmm/Book.hpp \ gncmm/Commodity.hpp \ + gncmm/GncInstance.hpp \ gncmm/private/Account_p.hpp \ gncmm/private/Book_p.hpp \ gncmm/private/Commodity_p.hpp \ diff --git a/src/optional/gtkmm/gncmm/Account.hpp b/src/optional/gtkmm/gncmm/Account.hpp index 3e613b3953..e3d7699bd4 100644 --- a/src/optional/gtkmm/gncmm/Account.hpp +++ b/src/optional/gtkmm/gncmm/Account.hpp @@ -34,6 +34,7 @@ extern "C" #include #include "Numeric.hpp" +#include "GncInstance.hpp" namespace gnc { @@ -48,7 +49,7 @@ class Commodity; /** Wrapper around a gnucash ::Account pointer with C++ methods for * easier setter and getter access. */ -class Account : public Glib::Object +class Account : public Glib::Object, public GncInstance { #ifndef DOXYGEN_SHOULD_SKIP_THIS typedef Account CppObjectType; diff --git a/src/optional/gtkmm/gncmm/GncInstance.hpp b/src/optional/gtkmm/gncmm/GncInstance.hpp new file mode 100644 index 0000000000..7fde9fcbf4 --- /dev/null +++ b/src/optional/gtkmm/gncmm/GncInstance.hpp @@ -0,0 +1,90 @@ +/* + * GncInstance.hpp + * Copyright (C) 2011 Christian Stimming + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 + * Boston, MA 02110-1301, USA gnu@gnu.org + */ + +#ifndef GNC_GNCINSTANCE_HPP +#define GNC_GNCINSTANCE_HPP + +// gnucash includes +#include "config.h" +extern "C" +{ +#include "qof.h" +} + +#include "Book.hpp" + +namespace gnc +{ + +/** Wrapper that should be used as an additional base class for those + * Glib::Object objects that are also derived from QofInstance. This + * base class offers some common methods. + * + * We cannot name it QofInstance because those stupid C macros (like + * QOF_CHECK_TYPE) would always confuse our namespaced declaration + * with the C declaration. I hate macros! + */ +class GncInstance +{ +public: + GncInstance() {} + virtual ~GncInstance() {} + + Glib::RefPtr getBook() const + { + return Glib::wrap(qof_instance_get_book (QOF_INSTANCE(get_gobj()))); + } + const ::GncGUID* getGUID() const + { + return qof_entity_get_guid(QOF_INSTANCE(get_gobj())); + } + + bool is_dirty() const + { + return qof_instance_get_dirty(QOF_INSTANCE(get_gobj())); + } + void set_dirty() + { + return qof_instance_set_dirty(QOF_INSTANCE(get_gobj())); + } + void mark_clean() + { + return qof_instance_mark_clean(QOF_INSTANCE(get_gobj())); + } + + //bool check_type(const char* type_id) { return (0 == g_strcmp0(type_id, QOF_INSTANCE(base_class::get())->e_type)); } + //Slots getSlots() const { return qof_instance_get_slots(QOF_INSTANCE(get())); } + +private: + GObject* get_gobj() + { + return dynamic_cast(*this).gobj(); + } + const GObject* get_gobj() const + { + return dynamic_cast(*this).gobj(); + } +}; + +} // END namespace gnc + +#endif