diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-06-24 21:28:40 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-06-24 21:28:40 +0000 |
commit | 706acbb46a91adef8ed2ec1d255802e93c59b65a (patch) | |
tree | eb3702adea14a190cf1b8ea43fd49147e73be0da | |
parent | 0f596b2a4ec68d082d82dad7f5c6a59ca445fc48 (diff) | |
download | dimension-706acbb46a91adef8ed2ec1d255802e93c59b65a.tar.xz |
New C++ dmnsn_progress* wrapper.
-rw-r--r-- | libdimensionxx/Makefile.am | 4 | ||||
-rw-r--r-- | libdimensionxx/dimensionxx.hpp | 1 | ||||
-rw-r--r-- | libdimensionxx/dimensionxx/array.hpp | 4 | ||||
-rw-r--r-- | libdimensionxx/dimensionxx/progress.hpp | 62 | ||||
-rw-r--r-- | libdimensionxx/progress.cpp | 92 |
5 files changed, 159 insertions, 4 deletions
diff --git a/libdimensionxx/Makefile.am b/libdimensionxx/Makefile.am index 1e19d28..0371435 100644 --- a/libdimensionxx/Makefile.am +++ b/libdimensionxx/Makefile.am @@ -17,13 +17,13 @@ ## along with this program. If not, see <http://www.gnu.org/licenses/>. ## ########################################################################### -nobase_include_HEADERS = dimensionxx.hpp dimensionxx/array.hpp dimensionxx/canvas.hpp dimensionxx/color.hpp dimensionxx/cookie.hpp dimensionxx/geometry.hpp dimensionxx/object.hpp dimensionxx/png.hpp +nobase_include_HEADERS = dimensionxx.hpp dimensionxx/array.hpp dimensionxx/canvas.hpp dimensionxx/color.hpp dimensionxx/cookie.hpp dimensionxx/geometry.hpp dimensionxx/object.hpp dimensionxx/png.hpp dimensionxx/progress.hpp INCLUDES = -I../libdimension lib_LTLIBRARIES = libdimensionxx.la -libdimensionxx_la_SOURCES = $(nobase_include_HEADERS) canvas.cpp color.cpp error.cpp object.cpp png.cpp +libdimensionxx_la_SOURCES = $(nobase_include_HEADERS) canvas.cpp color.cpp error.cpp object.cpp png.cpp progress.cpp if FOPENCOOKIE libdimensionxx_la_SOURCES += cookie-fopencookie.cpp diff --git a/libdimensionxx/dimensionxx.hpp b/libdimensionxx/dimensionxx.hpp index 37ecc13..d8df782 100644 --- a/libdimensionxx/dimensionxx.hpp +++ b/libdimensionxx/dimensionxx.hpp @@ -27,6 +27,7 @@ // libdimension wrappers #include <dimensionxx/error.hpp> #include <dimensionxx/array.hpp> +#include <dimensionxx/progress.hpp> #include <dimensionxx/geometry.hpp> #include <dimensionxx/color.hpp> #include <dimensionxx/canvas.hpp> diff --git a/libdimensionxx/dimensionxx/array.hpp b/libdimensionxx/dimensionxx/array.hpp index b13fa8a..dfbf1c8 100644 --- a/libdimensionxx/dimensionxx/array.hpp +++ b/libdimensionxx/dimensionxx/array.hpp @@ -21,8 +21,8 @@ #ifndef DIMENSIONXX_ARRAY_HPP #define DIMENSIONXX_ARRAY_HPP -#include <tr1/memory> -#include <cstdlib> // For size_t +#include <tr1/memory> // For tr1::shared_ptr +#include <cstdlib> // For size_t // dmnsn_array* wrapper. diff --git a/libdimensionxx/dimensionxx/progress.hpp b/libdimensionxx/dimensionxx/progress.hpp new file mode 100644 index 0000000..72099c4 --- /dev/null +++ b/libdimensionxx/dimensionxx/progress.hpp @@ -0,0 +1,62 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes <tavianator@gmail.com> * + * * + * 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 * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#ifndef DIMENSIONXX_PROGRESS_HPP +#define DIMENSIONXX_PROGRESS_HPP + +#include <tr1/memory> // For tr1::shared_ptr + +// dmnsn_canvas* wrapper. + +namespace Dimension +{ + // dmnsn_progress* wrapper class to represent an asynchronous worker thread + class Progress + { + public: + explicit Progress(dmnsn_progress* progress); + // Progress(const Progress& progress); + + // Finishes the job without throwing + ~Progress(); + + double progress() const; + void wait(double progress) const; + + void new_element(unsigned int total); + void increment(); + void done(); + + // Wait for job to finish, throwing if the job failed + void finish(); + + // Access the wrapped C object. + dmnsn_progress* dmnsn(); + const dmnsn_progress* dmnsn() const; + + private: + // Copy assignment prohibited + Progress& operator=(const Progress&); + + std::tr1::shared_ptr<dmnsn_progress*> m_progress; + }; +} + +#endif /* DIMENSIONXX_PROGRESS_HPP */ diff --git a/libdimensionxx/progress.cpp b/libdimensionxx/progress.cpp new file mode 100644 index 0000000..d09ac9b --- /dev/null +++ b/libdimensionxx/progress.cpp @@ -0,0 +1,92 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes <tavianator@gmail.com> * + * * + * 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 * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "dimensionxx.hpp" + +namespace Dimension +{ + Progress::Progress(dmnsn_progress* progress) + : m_progress(new dmnsn_progress*(progress)) + { } + + Progress::~Progress() + { + if (m_progress.unique()) { + try { + dmnsn_finish_progress(dmnsn()); + } catch (...) { + dmnsn_error(SEVERITY_MEDIUM, + "Finishing worker thread failed in Progress destructor."); + } + } + } + + double + Progress::progress() const + { + return dmnsn_get_progress(dmnsn()); + } + + void + Progress::wait(double progress) const + { + dmnsn_wait_progress(dmnsn(), progress); + } + + void + Progress::new_element(unsigned int total) + { + dmnsn_new_progress_element(dmnsn(), total); + } + + void + Progress::increment() + { + dmnsn_increment_progress(dmnsn()); + } + + void + Progress::done() + { + dmnsn_progress_done(dmnsn()); + } + + void + Progress::finish() + { + if (m_progress.unique()) { + dmnsn_finish_progress(dmnsn()); + } else { + throw Dimension_Error("Attempt to finish non-unique Progress."); + } + } + + dmnsn_progress* + Progress::dmnsn() + { + return *m_progress; + } + + const dmnsn_progress* + Progress::dmnsn() const + { + return *m_progress; + } +} |