summaryrefslogtreecommitdiffstats
path: root/libdimensionxx/dimensionxx
diff options
context:
space:
mode:
Diffstat (limited to 'libdimensionxx/dimensionxx')
-rw-r--r--libdimensionxx/dimensionxx/canvas.hpp20
-rw-r--r--libdimensionxx/dimensionxx/png.hpp60
2 files changed, 34 insertions, 46 deletions
diff --git a/libdimensionxx/dimensionxx/canvas.hpp b/libdimensionxx/dimensionxx/canvas.hpp
index f519fbd..b8f2887 100644
--- a/libdimensionxx/dimensionxx/canvas.hpp
+++ b/libdimensionxx/dimensionxx/canvas.hpp
@@ -23,6 +23,8 @@
#ifndef DIMENSIONXX_CANVAS_HPP
#define DIMENSIONXX_CANVAS_HPP
+#include <tr1/memory>
+
namespace Dimension
{
// Base canvas class. Wraps a dmnsn_canvas*.
@@ -31,10 +33,14 @@ namespace Dimension
public:
// Allocate a dmnsn_canvas of specified width and height
Canvas(unsigned int width, unsigned int height);
+
// Wrap an existing canvas
explicit Canvas(dmnsn_canvas* canvas);
+
+ // Canvas(const Canvas& canvas);
+
// Delete the canvas
- virtual ~Canvas();
+ ~Canvas();
// Get the width and height
unsigned int width() const;
@@ -48,17 +54,11 @@ namespace Dimension
dmnsn_canvas* dmnsn();
const dmnsn_canvas* dmnsn() const;
- protected:
- // Derived classes may want to set m_canvas later. Set it to NULL now, so
- // that the destructor can still dmnsn_delete_canvas it.
- Canvas();
-
- dmnsn_canvas* m_canvas;
-
private:
- // Copying prohibited
- Canvas(const Canvas&);
+ // Copy-assignment prohibited
Canvas& operator=(const Canvas&);
+
+ std::tr1::shared_ptr<dmnsn_canvas*> m_canvas;
};
}
diff --git a/libdimensionxx/dimensionxx/png.hpp b/libdimensionxx/dimensionxx/png.hpp
index 980840c..17cb883 100644
--- a/libdimensionxx/dimensionxx/png.hpp
+++ b/libdimensionxx/dimensionxx/png.hpp
@@ -28,55 +28,43 @@
namespace Dimension
{
- // PNG_Canvas handles reading a Canvas from a PNG file, writing one to a PNG
- // file, or both, depending on what type of stream(s) are given to the
- // constructor.
- class PNG_Canvas : public Canvas
+ class PNG_Writer
{
public:
- // Input PNG_Canvas; read the Canvas from istr now
- explicit PNG_Canvas(std::istream& istr);
+ PNG_Writer(Canvas& canvas, std::ostream& ostr);
+ ~PNG_Writer();
- // Output PNG_Canvas; write the Canvas to ostr at destruction, or when
- // write() is called.
- PNG_Canvas(unsigned int x, unsigned int y, std::ostream& ostr);
-
- // I/O PNG_Canvas; read the Canvas from istr now, and write to ostr at
- // destruction or then write() is called.
- PNG_Canvas(std::istream& istr, std::ostream& ostr);
+ void write();
+ Progress write_async();
- // Call write() if we're an output PNG_Canvas, but trap any exceptions and
- // report a dmnsn_error() instead.
- virtual ~PNG_Canvas();
+ private:
+ // Copying prohibited
+ PNG_Writer(const PNG_Writer&);
+ PNG_Writer& operator=(const PNG_Writer&);
- // Write the Canvas to the output stream, throwing a Dimension_Error on
- // error.
- void write();
+ Canvas* m_canvas;
+ std::ostream* m_ostr;
+ bool m_written;
+ };
- // Write the Canvas to the output stream in the background
- Progress write_async();
+ class PNG_Reader
+ {
+ public:
+ PNG_Reader(std::istream& istr);
+ // ~PNG_Reader();
- // Construct an input or I/O PNG_Canvas in the background
- static Progress read_async(std::istream& istr);
- explicit PNG_Canvas(Progress& progress);
- explicit PNG_Canvas(Progress& progress, std::ostream& ostr);
+ Canvas read();
- protected:
- // In case a derived class needs to set m_canvas after we're constructed
- explicit PNG_Canvas(std::ostream& ostr);
+ Progress read_async();
+ static Canvas finish(Progress& progress);
private:
// Copying prohibited
- PNG_Canvas(const PNG_Canvas&);
- PNG_Canvas& operator=(const PNG_Canvas&);
+ PNG_Reader(const PNG_Reader&);
+ PNG_Reader& operator=(const PNG_Reader&);
std::istream* m_istr;
- std::ostream* m_ostr;
- bool m_written;
-
- // Read the Canvas from a PNG file, and throw a Dimension_Error upon
- // failure.
- void read();
+ bool m_read;
};
}