summaryrefslogtreecommitdiffstats
path: root/libdimensionxx/objects.cpp
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-07 04:23:05 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-07 04:23:05 +0000
commit81c84a38992ce8e38106d86ce85ac3e88ed91a31 (patch)
tree08fb5913e141b7e208737b799b45921d477d45cc /libdimensionxx/objects.cpp
parentd7b7b4b3391cf99ca63d8311eac3957df7a862ed (diff)
downloaddimension-81c84a38992ce8e38106d86ce85ac3e88ed91a31.tar.xz
Add shallow copy semantics to Camera's, Object's, and Scene's.
Diffstat (limited to 'libdimensionxx/objects.cpp')
-rw-r--r--libdimensionxx/objects.cpp36
1 files changed, 32 insertions, 4 deletions
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)
+ { }
}