diff options
author | Jonathon Jongsma <jjongsma@gnome.org> | 2010-12-30 16:35:03 -0600 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@gnome.org> | 2010-12-30 17:18:58 -0600 |
commit | 8439d62c975adca31c05f102c3570e09680d4bb4 (patch) | |
tree | df6264adc601f3bedae9afe0df0bc4264888ec0a | |
parent | 59538c87691e7f05dbd3433bbd52f17709496240 (diff) |
Provide static factory functions for Region
Since Region objects are ref-counted, don't allow them to be instantiated
manually, but provide static create() functions for automatically managing them
with RefPtrs. Also, remember to check the error status when creating them.
-rw-r--r-- | cairomm/region.cc | 14 | ||||
-rw-r--r-- | cairomm/region.h | 17 |
2 files changed, 26 insertions, 5 deletions
diff --git a/cairomm/region.cc b/cairomm/region.cc index 021c31b..bbbeeb1 100644 --- a/cairomm/region.cc +++ b/cairomm/region.cc @@ -25,11 +25,13 @@ namespace Cairo Region::Region() : m_cobject(cairo_region_create()) { + check_object_status_and_throw_exception (*this); } Region::Region(const RectangleInt& rectangle) : m_cobject(cairo_region_create_rectangle(&rectangle)) { + check_object_status_and_throw_exception (*this); } Region::Region(cairo_region_t* cobject, bool has_reference) @@ -39,6 +41,18 @@ Region::Region(cairo_region_t* cobject, bool has_reference) m_cobject = cobject; else m_cobject = cairo_region_reference(cobject); + + check_object_status_and_throw_exception (*this); +} + +RefPtr<Region> Region::create() +{ + return RefPtr<Region>(new Region()); +} + +RefPtr<Region> Region::create(const RectangleInt& rectangle) +{ + return RefPtr<Region>(new Region(rectangle)); } Region::~Region() diff --git a/cairomm/region.h b/cairomm/region.h index ea26a74..d4cf7db 100644 --- a/cairomm/region.h +++ b/cairomm/region.h @@ -28,14 +28,17 @@ namespace Cairo { -//TODO: Documentation. - /** - * This is a reference-counted object that should be used via Cairo::RefPtr. - */ + * A Region represents a set of integer-aligned rectangles. + * + * It allows set-theoretical operations like do_union() and intersect() to be + * performed on them. + * + * Since: 1.10 + **/ class Region { -public: +private: Region(); @@ -44,12 +47,16 @@ public: //TODO: wrapping cairo_region_create_rectangles() //Region(const RectangleInt *rects, int count); +public: /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr. * @param cobject The C instance. * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference. */ explicit Region(cairo_region_t* cobject, bool has_reference = false); + static RefPtr<Region> create(); + static RefPtr<Region> create(const RectangleInt& rectangle); + //TODO: //cairo_public cairo_region_t * //cairo_region_copy (const cairo_region_t *original); |