From e957408cb8cd200696a081b4f5c749c5294110ec Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 1 Jul 2009 04:44:51 +0000 Subject: Sphere and cube C++ wrappers. --- libdimensionxx/Makefile.am | 2 ++ libdimensionxx/dimensionxx.hpp | 3 +- libdimensionxx/dimensionxx/cube.hpp | 30 +++++++++++++++++++ libdimensionxx/dimensionxx/object.hpp | 2 +- libdimensionxx/dimensionxx/objects.hpp | 45 ++++++++++++++++++++++++++++ libdimensionxx/object.cpp | 5 ++++ libdimensionxx/objects.cpp | 54 ++++++++++++++++++++++++++++++++++ 7 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 libdimensionxx/dimensionxx/cube.hpp create mode 100644 libdimensionxx/dimensionxx/objects.hpp create mode 100644 libdimensionxx/objects.cpp (limited to 'libdimensionxx') diff --git a/libdimensionxx/Makefile.am b/libdimensionxx/Makefile.am index 6b53858..b35ec97 100644 --- a/libdimensionxx/Makefile.am +++ b/libdimensionxx/Makefile.am @@ -24,6 +24,7 @@ nobase_include_HEADERS = dimensionxx.hpp \ dimensionxx/cookie.hpp \ dimensionxx/geometry.hpp \ dimensionxx/object.hpp \ + dimensionxx/objects.hpp \ dimensionxx/png.hpp \ dimensionxx/progress.hpp @@ -36,6 +37,7 @@ libdimensionxx_la_SOURCES = $(nobase_include_HEADERS) \ color.cpp \ error.cpp \ object.cpp \ + objects.cpp \ png.cpp \ progress.cpp diff --git a/libdimensionxx/dimensionxx.hpp b/libdimensionxx/dimensionxx.hpp index d8df782..c413d87 100644 --- a/libdimensionxx/dimensionxx.hpp +++ b/libdimensionxx/dimensionxx.hpp @@ -31,7 +31,8 @@ #include #include #include -#include #include +#include +#include #endif /* DIMENSIONXX_HPP */ diff --git a/libdimensionxx/dimensionxx/cube.hpp b/libdimensionxx/dimensionxx/cube.hpp new file mode 100644 index 0000000..9452c88 --- /dev/null +++ b/libdimensionxx/dimensionxx/cube.hpp @@ -0,0 +1,30 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +// Cube wrapper + +#ifndef DIMENSIONXX_CUBE_HPP +#define DIMENSIONXX_CUBE_HPP + +namespace Dimension +{ +} + +#endif /* DIMENSIONXX_CUBE_HPP */ diff --git a/libdimensionxx/dimensionxx/object.hpp b/libdimensionxx/dimensionxx/object.hpp index 40dcb25..6eaca83 100644 --- a/libdimensionxx/dimensionxx/object.hpp +++ b/libdimensionxx/dimensionxx/object.hpp @@ -43,7 +43,7 @@ namespace Dimension // No-op Object(); // Wrap an existing object. - explicit Object(dmnsn_object* object) : m_object(object) { } + explicit Object(dmnsn_object* object); dmnsn_object* m_object; diff --git a/libdimensionxx/dimensionxx/objects.hpp b/libdimensionxx/dimensionxx/objects.hpp new file mode 100644 index 0000000..5d5fe46 --- /dev/null +++ b/libdimensionxx/dimensionxx/objects.hpp @@ -0,0 +1,45 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +// Object wrappers. + +#ifndef DIMENSIONXX_OBJECTS_HPP +#define DIMENSIONXX_OBJECTS_HPP + +namespace Dimension +{ + // Sphere object + class Sphere : public Object + { + public: + Sphere(); + virtual ~Sphere(); + }; + + // A cube + class Cube : public Object + { + public: + Cube(); + virtual ~Cube(); + }; +} + +#endif /* DIMENSIONXX_OBJECTS_HPP */ diff --git a/libdimensionxx/object.cpp b/libdimensionxx/object.cpp index 33aeb85..61a887c 100644 --- a/libdimensionxx/object.cpp +++ b/libdimensionxx/object.cpp @@ -58,6 +58,11 @@ namespace Dimension Object::Object() { } + // Protected manual constructor + Object::Object(dmnsn_object *object) + : m_object(object) + { } + // Custom object callbacks namespace { dmnsn_array * diff --git a/libdimensionxx/objects.cpp b/libdimensionxx/objects.cpp new file mode 100644 index 0000000..1a63494 --- /dev/null +++ b/libdimensionxx/objects.cpp @@ -0,0 +1,54 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#include "dimensionxx.hpp" + +namespace Dimension +{ + // Create a sphere + Sphere::Sphere() + : Object(dmnsn_new_sphere()) + { + if (!m_object) { + throw Dimension_Error("Failed to allocate sphere."); + } + } + + // Delete a sphere + Sphere::~Sphere() + { + dmnsn_delete_sphere(m_object); + } + + // Create a cube + Cube::Cube() + : Object(dmnsn_new_cube()) + { + if (!m_object) { + throw Dimension_Error("Failed to allocate sphere."); + } + } + + // Delete a sphere + Cube::~Cube() + { + dmnsn_delete_cube(m_object); + } +} -- cgit v1.2.3