r21483 - gnucash/trunk/src/optional/gtkmm - [Gtkmm] Add gnc::GncInstance as wrapper for QofInstance, to be used as a base class for the derived qof classes.
Christian Stimming
cstim at code.gnucash.org
Sun Oct 23 16:43:51 EDT 2011
Author: cstim
Date: 2011-10-23 16:43:51 -0400 (Sun, 23 Oct 2011)
New Revision: 21483
Trac: http://svn.gnucash.org/trac/changeset/21483
Added:
gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/private/GncInstance_p.hpp
Modified:
gnucash/trunk/src/optional/gtkmm/Makefile.am
gnucash/trunk/src/optional/gtkmm/gncmm/Account.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/wrap_init.cpp
Log:
[Gtkmm] Add gnc::GncInstance as wrapper for QofInstance, to be used as a base class for the derived qof classes.
Modified: gnucash/trunk/src/optional/gtkmm/Makefile.am
===================================================================
--- gnucash/trunk/src/optional/gtkmm/Makefile.am 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/Makefile.am 2011-10-23 20:43:51 UTC (rev 21483)
@@ -6,6 +6,7 @@
gncmm/Account.cpp \
gncmm/Book.cpp \
gncmm/Commodity.cpp \
+ gncmm/GncInstance.cpp \
gncmm/Numeric.cpp \
gncmm/Split.cpp \
gncmm/Transaction.cpp \
@@ -24,6 +25,7 @@
gncmm/private/Account_p.hpp \
gncmm/private/Book_p.hpp \
gncmm/private/Commodity_p.hpp \
+ gncmm/private/GncInstance_p.hpp \
gncmm/private/Split_p.hpp \
gncmm/private/Transaction_p.hpp \
gncmm/wrap_init.hpp \
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Account.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Account.cpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Account.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -87,13 +87,13 @@
}
Account::Account(const Glib::ConstructParams& construct_params)
- : Glib::Object(construct_params)
+ : GncInstance(construct_params)
{
}
Account::Account(::Account* castitem)
- : Glib::Object((GObject*)(castitem))
+ : GncInstance((::QofInstance*)(castitem))
{}
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -49,7 +49,7 @@
/** Wrapper around a gnucash ::Account pointer with C++ methods for
* easier setter and getter access.
*/
-class Account : public Glib::Object, public GncInstance
+class Account : public GncInstance
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Account CppObjectType;
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -87,13 +87,13 @@
}
Book::Book(const Glib::ConstructParams& construct_params)
- : Glib::Object(construct_params)
+ : GncInstance(construct_params)
{
}
Book::Book(QofBook* castitem)
- : Glib::Object((GObject*)(castitem))
+ : GncInstance((::QofInstance*)(castitem))
{}
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -32,7 +32,7 @@
}
#include <glibmm/object.h>
-//#include "GncInstance.hpp"
+#include "GncInstance.hpp"
namespace gnc
{
@@ -48,7 +48,7 @@
/** Wrapper around a gnucash ::QofBook pointer with C++ methods for
* easier setter and getter access.
*/
-class Book : public Glib::Object //, public GncInstance
+class Book : public GncInstance
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Book CppObjectType;
@@ -98,8 +98,14 @@
Glib::RefPtr<Account> get_root_account();
- bool is_readonly() const { return qof_book_is_readonly(gobj()); }
- void mark_readonly() { qof_book_mark_readonly(gobj()); }
+ bool is_readonly() const
+ {
+ return qof_book_is_readonly(gobj());
+ }
+ void mark_readonly()
+ {
+ qof_book_mark_readonly(gobj());
+ }
void set_string_option (const Glib::ustring& opt_name, const Glib::ustring& opt_val);
Glib::ustring get_string_option (const Glib::ustring& opt_name) const;
};
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.cpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -86,13 +86,13 @@
}
Commodity::Commodity(const Glib::ConstructParams& construct_params)
- : Glib::Object(construct_params)
+ : GncInstance(construct_params)
{
}
Commodity::Commodity(gnc_commodity* castitem)
- : Glib::Object((GObject*)(castitem))
+ : GncInstance((::QofInstance*)(castitem))
{}
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.hpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Commodity.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -44,7 +44,7 @@
{
/** Wrapper around a gnucash \ref gnc_commodity object */
-class Commodity : public Glib::Object, public GncInstance
+class Commodity : public GncInstance
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Commodity CppObjectType;
Copied: gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.cpp (from rev 21482, gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp)
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.cpp (rev 0)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -0,0 +1,131 @@
+/*
+ * GncInstance.cpp
+ * 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 at gnu.org
+ */
+
+#include "GncInstance.hpp"
+#include "private/GncInstance_p.hpp"
+#include "Book.hpp"
+
+
+namespace Glib
+{
+
+Glib::RefPtr<gnc::GncInstance> wrap(::QofInstance* object, bool take_copy)
+{
+ return Glib::RefPtr<gnc::GncInstance>( dynamic_cast<gnc::GncInstance*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
+ //We use dynamic_cast<> in case of multiple inheritance.
+}
+
+} /* namespace Glib */
+
+
+namespace gnc
+{
+
+
+/* The *_Class implementation: */
+
+const Glib::Class& GncInstance_Class::init()
+{
+ if (!gtype_) // create the GType if necessary
+ {
+ // Glib::Class has to know the class init function to clone custom types.
+ class_init_func_ = &GncInstance_Class::class_init_function;
+
+ // This is actually just optimized away, apparently with no harm.
+ // Make sure that the parent type has been created.
+ //CppClassParent::CppObjectType::get_type();
+
+ // Create the wrapper type, with the same class/instance size as the base type.
+ register_derived_type(qof_instance_get_type());
+
+ // Add derived versions of interfaces, if the C type implements any interfaces:
+
+ }
+
+ return *this;
+}
+
+
+void GncInstance_Class::class_init_function(void* g_class, void* class_data)
+{
+ BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
+ CppClassParent::class_init_function(klass, class_data);
+}
+
+
+Glib::ObjectBase* GncInstance_Class::wrap_new(GObject* object)
+{
+ return new GncInstance((::QofInstance*)object);
+}
+
+
+/* The implementation: */
+
+::QofInstance* GncInstance::gobj_copy()
+{
+ reference();
+ return gobj();
+}
+
+GncInstance::GncInstance(const Glib::ConstructParams& construct_params)
+ : Glib::Object(construct_params)
+{
+
+}
+
+GncInstance::GncInstance(::QofInstance* castitem)
+ : Glib::Object((GObject*)(castitem))
+{}
+
+
+GncInstance::~GncInstance()
+{}
+
+
+GncInstance::CppClassType GncInstance::gncInstance_class_; // initialize static member
+
+GType GncInstance::get_type()
+{
+ return gncInstance_class_.init().get_type();
+}
+
+
+GType GncInstance::get_base_type()
+{
+ return qof_instance_get_type();
+}
+
+// ////////////////////////////////////////
+
+Glib::RefPtr<Book> GncInstance::getBook() const
+{
+ return Glib::wrap(qof_instance_get_book (gobj()));
+}
+void GncInstance::set_book(Glib::RefPtr<Book> book)
+{
+ g_assert (book);
+ qof_instance_set_book(gobj(), book->gobj());
+}
+
+
+
+} // END namespace gnc
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.hpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/GncInstance.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -36,61 +36,96 @@
{
class Book;
class GncInstance;
+class GncInstance_Class;
} // END namespace gnc
-#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
+/** Wrapper for ::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
+class GncInstance : public Glib::Object
{
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+ typedef GncInstance CppObjectType;
+ typedef GncInstance_Class CppClassType;
+ typedef ::QofInstance BaseObjectType;
+ typedef ::QofInstanceClass BaseClassType;
+
+private:
+ friend class GncInstance_Class;
+ static CppClassType gncInstance_class_;
+
+private:
+ // noncopyable
+ GncInstance(const GncInstance&);
+ GncInstance& operator=(const GncInstance&);
+
+protected:
+ explicit GncInstance(const Glib::ConstructParams& construct_params);
+ explicit GncInstance(::QofInstance* castitem);
+
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
public:
- GncInstance() {}
- virtual ~GncInstance() {}
+ virtual ~GncInstance();
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+ static GType get_type() G_GNUC_CONST;
+ static GType get_base_type() G_GNUC_CONST;
+#endif
- Glib::RefPtr<Book> getBook() const
+ ///Provides access to the underlying C GObject.
+ ::QofInstance* gobj()
{
- return Glib::wrap(qof_instance_get_book (get_instance()));
+ return reinterpret_cast< ::QofInstance*>(gobject_);
}
+
+ ///Provides access to the underlying C GObject.
+ const ::QofInstance* gobj() const
+ {
+ return reinterpret_cast< ::QofInstance*>(gobject_);
+ }
+
+ ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
+ ::QofInstance* gobj_copy();
+
+public:
+
+ Glib::RefPtr<Book> getBook() const;
+ void set_book(Glib::RefPtr<Book> book);
const ::GncGUID* getGUID() const
{
- return qof_entity_get_guid(get_instance());
+ return qof_entity_get_guid(gobj_const());
}
bool is_dirty() const
{
- return qof_instance_get_dirty(get_instance());
+ return qof_instance_get_dirty(gobj_const());
}
void set_dirty()
{
- return qof_instance_set_dirty(get_instance());
+ return qof_instance_set_dirty(gobj());
}
void mark_clean()
{
- return qof_instance_mark_clean(get_instance());
+ return qof_instance_mark_clean(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:
- ::QofInstance* get_instance()
+ /*const*/
+ ::QofInstance* gobj_const() const
{
- return QOF_INSTANCE(dynamic_cast<Glib::Object&>(*this).gobj());
+ return const_cast< ::QofInstance*>(gobj());
}
- /*const*/ ::QofInstance* get_instance() const
- {
- return QOF_INSTANCE(dynamic_cast<const Glib::Object&>(*this).gobj());
- }
};
} // END namespace gnc
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -87,13 +87,13 @@
}
Split::Split(const Glib::ConstructParams& construct_params)
- : Glib::Object(construct_params)
+ : GncInstance(construct_params)
{
}
Split::Split(::Split* castitem)
- : Glib::Object((GObject*)(castitem))
+ : GncInstance((::QofInstance*)(castitem))
{}
@@ -191,14 +191,14 @@
void TmpSplit::copyInto(Transaction& t) const
{
- Glib::RefPtr<Split> s(Glib::wrap(xaccMallocSplit(t.getBook()->gobj())));
- s->setAccount(m_account);
- s->setParent(t);
- s->setMemo(m_memo);
- s->setAction(m_action);
- s->setReconcile(m_reconcile);
- s->setAmount(m_amount);
- s->setValue(m_value);
+// Glib::RefPtr<Split> s(Glib::wrap(xaccMallocSplit(t.getBook()->gobj())));
+// s->setAccount(m_account);
+// s->setParent(t);
+// s->setMemo(m_memo);
+// s->setAction(m_action);
+// s->setReconcile(m_reconcile);
+// s->setAmount(m_amount);
+// s->setValue(m_value);
}
} // END namespace gnc
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -56,7 +56,7 @@
/** Wrapper around a gnucash ::Split pointer with C++ methods for
* easier setter and getter access.
*/
-class Split : public Glib::Object, public GncInstance
+class Split : public GncInstance
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Split CppObjectType;
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -89,13 +89,13 @@
}
Transaction::Transaction(const Glib::ConstructParams& construct_params)
- : Glib::Object(construct_params)
+ : GncInstance(construct_params)
{
}
Transaction::Transaction(::Transaction* castitem)
- : Glib::Object((GObject*)(castitem))
+ : GncInstance((::QofInstance*)(castitem))
{}
@@ -202,7 +202,7 @@
//m_splits[i].copyInto(t);
}
}
-
+#if 0
Glib::RefPtr<Transaction> TmpTransaction::createAsReal() const
{
assert (!m_splits.empty());
@@ -216,7 +216,7 @@
trans->commitEdit();
return trans;
}
-
+#endif
void TmpTransaction::push_back(const TmpSplit& s)
{
m_splits.push_back(s);
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -57,7 +57,7 @@
/** Wrapper around a gnucash ::Transaction pointer with C++ methods for
* easier setter and getter access.
*/
-class Transaction : public Glib::Object, public GncInstance
+class Transaction : public GncInstance
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Transaction CppObjectType;
Added: gnucash/trunk/src/optional/gtkmm/gncmm/private/GncInstance_p.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/private/GncInstance_p.hpp (rev 0)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/private/GncInstance_p.hpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -0,0 +1,48 @@
+// -*- c++ -*-
+// Generated by gtkmmproc -- DO NOT MODIFY!
+#ifndef _GNCMM_GNC_COMMODITY_P_H
+#define _GNCMM_GNC_COMMODITY_P_H
+
+
+#include <glibmm/private/object_p.h>
+
+#include <glibmm/class.h>
+
+namespace gnc
+{
+
+class GncInstance_Class : public Glib::Class
+{
+public:
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+ typedef GncInstance CppObjectType;
+ typedef ::QofInstance BaseObjectType;
+ typedef ::QofInstanceClass BaseClassType;
+ typedef Glib::Object_Class CppClassParent;
+ typedef GObjectClass BaseClassParent;
+
+ friend class GncInstance;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+ const Glib::Class& init();
+
+
+ static void class_init_function(void* g_class, void* class_data);
+
+ static Glib::ObjectBase* wrap_new(GObject*);
+
+protected:
+
+ //Callbacks (default signal handlers):
+ //These will call the *_impl member methods, which will then call the existing default signal callbacks, if any.
+ //You could prevent the original default signal handlers being called by overriding the *_impl method.
+
+ //Callbacks (virtual functions):
+};
+
+
+} // namespace gnc
+
+
+#endif /* _GNCMM_GNC_COMMODITY_P_H */
+
Property changes on: gnucash/trunk/src/optional/gtkmm/gncmm/private/GncInstance_p.hpp
___________________________________________________________________
Added: svn:eol-style
+ LF
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/wrap_init.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/wrap_init.cpp 2011-10-22 21:30:51 UTC (rev 21482)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/wrap_init.cpp 2011-10-23 20:43:51 UTC (rev 21483)
@@ -29,6 +29,7 @@
GType gnc_commodity_get_type(void);
GType gnc_split_get_type(void);
GType gnc_transaction_get_type(void);
+ GType qof_instance_get_type (void);
} // extern "C"
//Declarations of the *_Class::wrap_new() methods, instead of including all the private headers:
@@ -36,6 +37,7 @@
namespace gnc { class Account_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; }
namespace gnc { class Book_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; }
namespace gnc { class Commodity_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; }
+namespace gnc { class GncInstance_Class { public : static Glib::ObjectBase* wrap_new(GObject*); }; }
namespace gnc { class Split_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; }
namespace gnc { class Transaction_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; }
@@ -47,6 +49,7 @@
Glib::wrap_register(gnc_account_get_type(), &gnc::Account_Class::wrap_new);
Glib::wrap_register(qof_book_get_type(), &gnc::Book_Class::wrap_new);
Glib::wrap_register(gnc_commodity_get_type(), &gnc::Commodity_Class::wrap_new);
+ Glib::wrap_register(qof_instance_get_type(), &gnc::GncInstance_Class::wrap_new);
Glib::wrap_register(gnc_split_get_type(), &gnc::Split_Class::wrap_new);
Glib::wrap_register(gnc_transaction_get_type(), &gnc::Transaction_Class::wrap_new);
@@ -54,6 +57,7 @@
gnc::Account::get_type();
gnc::Book::get_type();
gnc::Commodity::get_type();
+ gnc::GncInstance::get_type();
gnc::Split::get_type();
gnc::Transaction::get_type();
} // wrap_init()
More information about the gnucash-changes
mailing list