From 81c84a38992ce8e38106d86ce85ac3e88ed91a31 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 7 Jul 2009 04:23:05 +0000 Subject: Add shallow copy semantics to Camera's, Object's, and Scene's. --- libdimensionxx/objects.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'libdimensionxx/objects.cpp') diff --git a/libdimensionxx/objects.cpp b/libdimensionxx/objects.cpp index 1b78731..eac642c 100644 --- a/libdimensionxx/objects.cpp +++ b/libdimensionxx/objects.cpp @@ -26,7 +26,7 @@ namespace Dimension Sphere::Sphere() : Object(dmnsn_new_sphere()) { - if (!m_object) { + if (!dmnsn()) { throw Dimension_Error("Failed to allocate sphere."); } } @@ -34,14 +34,28 @@ namespace Dimension // Delete a sphere Sphere::~Sphere() { - dmnsn_delete_sphere(m_object); + if (unique()) { + dmnsn_delete_sphere(dmnsn()); + } } + // Shallow copy a sphere + Object* + Sphere::copy() const + { + return new Sphere(*this); + } + + // Protected copy constructor + Sphere::Sphere(const Sphere& sphere) + : Object(sphere) + { } + // Create a cube Cube::Cube() : Object(dmnsn_new_cube()) { - if (!m_object) { + if (!dmnsn()) { throw Dimension_Error("Failed to allocate cube."); } } @@ -49,6 +63,20 @@ namespace Dimension // Delete a sphere Cube::~Cube() { - dmnsn_delete_cube(m_object); + if (unique()) { + dmnsn_delete_cube(dmnsn()); + } } + + // Shallow copy a cube + Object* + Cube::copy() const + { + return new Cube(*this); + } + + // Protected copy constructor + Cube::Cube(const Cube& sphere) + : Object(sphere) + { } } -- cgit v1.2.3