chiark / gitweb /
Split up Fractal.h into Fractal, FractalMaths and Fractal-internals
authorRoss Younger <onyx-commits@impropriety.org.uk>
Fri, 1 Feb 2013 20:26:13 +0000 (09:26 +1300)
committerRoss Younger <onyx-commits@impropriety.org.uk>
Fri, 1 Feb 2013 20:26:13 +0000 (09:26 +1300)
Makefile.am
libfractal/Fractal-internals.h [new file with mode: 0644]
libfractal/Fractal.cpp
libfractal/Fractal.h
libfractal/FractalMaths.h [new file with mode: 0644]
libfractal/Mandelbar.cpp
libfractal/Mandelbrots.cpp
libfractal/Mandeldrop.cpp
libfractal/Misc.cpp

index 940ba5f..b35a895 100644 (file)
@@ -26,6 +26,7 @@ noinst_LIBRARIES+=libfractal.a
 
 libfractal_a_SOURCES= \
        libfractal/Fractal.h libfractal/Fractal.cpp libfractal/Registry.h \
+       libfractal/FractalMaths.h libfractal/Fractal-internals.h \
        libfractal/Mandelbrots.cpp libfractal/Mandelbar.cpp \
        libfractal/Mandeldrop.cpp libfractal/Misc.cpp
 
diff --git a/libfractal/Fractal-internals.h b/libfractal/Fractal-internals.h
new file mode 100644 (file)
index 0000000..f5954ef
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+    Fractal-internals.h: Definitions internal to libfractal
+    Copyright (C) 2010-3 Ross Younger
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef FRACTAL_INTERNALS_H_
+#define FRACTAL_INTERNALS_H_
+
+#include "FractalMaths.h"
+
+namespace Fractal {
+
+// Every source file that declares fractals must have a load_ function.
+// They are called in Fractal.cpp.
+void load_Mandelbrot();
+void load_Mandelbar();
+void load_Mandeldrop();
+void load_Misc();
+
+
+class Consts {
+public:
+       static const Value log2;
+       static const Value log3;
+       static const Value log4;
+       static const Value log5;
+};
+
+/*
+ * Mixin helper class. This enables a single templated fractal definition
+ * class to write the iteration code once and have it reused multiple times
+ * with different maths types.
+ */
+template <class IMPL>
+class MathsMixin : public IMPL {
+public:
+       virtual ~MathsMixin() {}
+
+       virtual void prepare_pixel(const Point coords, PointData& out) const {
+               IMPL::prepare_pixel_impl(coords,out);
+       }
+
+#define DO_PLOT(type,name,minpix)      \
+       case Maths::MathsType::name:    \
+       IMPL::template plot_pixel_impl<type>(maxiter,out); \
+       break;
+
+       virtual void plot_pixel(int maxiter, PointData& out, Maths::MathsType type) const {
+               switch(type) {
+                       ALL_MATHS_TYPES(DO_PLOT)
+               case Maths::MathsType::MAX:
+                       throw "Unhandled value type";
+               }
+       }
+};
+
+}; // namespace Fractal
+
+#endif /* FRACTAL_INTERNALS_H_ */
index 924084b..2fdb88d 100644 (file)
@@ -21,6 +21,7 @@
 #include <vector>
 #include <glib.h>
 #include "Fractal.h"
+#include "Fractal-internals.h"
 
 using namespace Fractal;
 
@@ -54,6 +55,19 @@ void Fractal::FractalCommon::unload_registry() {
        base_loaded = false;
 }
 
+void Fractal::FractalImpl::reg() {
+       FractalCommon::registry.reg(name, this);
+       isRegistered = 1;
+}
+
+void Fractal::FractalImpl::dereg()
+{
+       if (isRegistered)
+               FractalCommon::registry.dereg(name);
+       isRegistered = false;
+}
+
+
 struct MathsInfo {
        Maths::MathsType val;
        const char* name;
index cc7d2cd..f50106a 100644 (file)
 #define FRACTAL_H_
 
 #include <string>
-#include <complex>
 #include <map>
 #include <iostream>
 #include "Registry.h"
 #include "config.h"
+#include "FractalMaths.h"
 
 namespace Fractal {
 
-// Every source file that declares fractals must have a load_ function.
-// They are called in Fractal.cpp.
-void load_Mandelbrot();
-void load_Mandelbar();
-void load_Mandeldrop();
-void load_Misc();
-
-////////////////////////////////////////////////////////////////////////////
-// Maths types and traits
-
-typedef long double Value; // short for "fractal value"
-typedef std::complex<Value> Point; // "complex fractal point"
-
-#ifdef ENABLE_DOUBLE
-#define MAYBE_DO_DOUBLE(_DO) _DO(double,Double,0.00000000000000044408920985006L /* 4.44e-16 */)
-#else
-#define MAYBE_DO_DOUBLE(_DO)
-#endif
-
-#ifdef ENABLE_FLOAT
-#define MAYBE_DO_FLOAT(_DO) _DO(float, Float, 0.0000002384185791016)
-#else
-#define MAYBE_DO_FLOAT(_DO)
-#endif
-
-// Master list of all maths types we know about.
-// Format: _DO(type name, enum name, minimum pixel size)
-#define ALL_MATHS_TYPES(_DO)   \
-       MAYBE_DO_FLOAT(_DO)             \
-       MAYBE_DO_DOUBLE(_DO)            \
-       _DO(long double, LongDouble, 0.0000000000000000002168404345L /* 2.16e-19 */)    \
-
-
-class Maths {
-public:
-       enum class MathsType {
-#define DO_ENUM(type,name,minpix) name,
-               ALL_MATHS_TYPES(DO_ENUM)
-               MAX,
-       };
-
-       static const char* name(MathsType t); // Enum to name conversion
-       static Value min_pixel_size(MathsType t); // Minimum pixel size lookup
-       static Value smallest_min_pixel_size();
-};
-
-////////////////////////////////////////////////////////////////////////////
-
-class Consts {
-public:
-       static const Value log2;
-       static const Value log3;
-       static const Value log4;
-       static const Value log5;
-};
-
 ////////////////////////////////////////////////////////////////////////////
 
 class PointData {
@@ -171,50 +115,10 @@ public:
 
 private:
        bool isRegistered;
-       void reg() { FractalCommon::registry.reg(name, this); isRegistered = 1; }
-       void dereg()
-       {
-               if (isRegistered)
-                       FractalCommon::registry.dereg(name);
-               isRegistered = false;
-       }
-};
-
-/*
- * Mixin helper class. This enables a single templated fractal definition
- * class to write the iteration code once and have it reused multiple times
- * with different maths types.
- */
-template <class IMPL>
-class MathsMixin : public IMPL {
-public:
-       virtual ~MathsMixin() {}
-
-       virtual void prepare_pixel(const Point coords, PointData& out) const {
-               IMPL::prepare_pixel_impl(coords,out);
-       }
-
-#define DO_PLOT(type,name,minpix)      \
-       case Maths::MathsType::name:    \
-       IMPL::template plot_pixel_impl<type>(maxiter,out); \
-       break;
-
-       virtual void plot_pixel(int maxiter, PointData& out, Maths::MathsType type) const {
-               switch(type) {
-                       ALL_MATHS_TYPES(DO_PLOT)
-               case Maths::MathsType::MAX:
-                       throw "Unhandled value type";
-               }
-       }
+       void reg();
+       void dereg();
 };
 
 }; // namespace Fractal
 
-inline Fractal::Point operator/(const Fractal::Point& a, Fractal::Value b) {
-       Fractal::Point rv(a);
-       rv.real(real(rv)/b);
-       rv.imag(imag(rv)/b);
-       return rv;
-}
-
 #endif /* FRACTAL_H_ */
diff --git a/libfractal/FractalMaths.h b/libfractal/FractalMaths.h
new file mode 100644 (file)
index 0000000..0259985
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+    FractalMaths.h: Maths types for the fractal library
+    Copyright (C) 2010-3 Ross Younger
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef FRACTALMATHS_H_
+#define FRACTALMATHS_H_
+
+#include <complex>
+
+namespace Fractal {
+
+////////////////////////////////////////////////////////////////////////////
+// Maths types and traits
+
+typedef long double Value; // short for "fractal value"
+typedef std::complex<Value> Point; // "complex fractal point"
+
+#ifdef ENABLE_DOUBLE
+#define MAYBE_DO_DOUBLE(_DO) _DO(double,Double,0.00000000000000044408920985006L /* 4.44e-16 */)
+#else
+#define MAYBE_DO_DOUBLE(_DO)
+#endif
+
+#ifdef ENABLE_FLOAT
+#define MAYBE_DO_FLOAT(_DO) _DO(float, Float, 0.0000002384185791016)
+#else
+#define MAYBE_DO_FLOAT(_DO)
+#endif
+
+// Master list of all maths types we know about.
+// Format: _DO(type name, enum name, minimum pixel size)
+#define ALL_MATHS_TYPES(_DO)   \
+       MAYBE_DO_FLOAT(_DO)             \
+       MAYBE_DO_DOUBLE(_DO)            \
+       _DO(long double, LongDouble, 0.0000000000000000002168404345L /* 2.16e-19 */)    \
+
+class Maths {
+public:
+       enum class MathsType {
+#define DO_ENUM(type,name,minpix) name,
+               ALL_MATHS_TYPES(DO_ENUM)
+               MAX,
+       };
+
+       static const char* name(MathsType t); // Enum to name conversion
+       static Value min_pixel_size(MathsType t); // Minimum pixel size lookup
+       static Value smallest_min_pixel_size();
+};
+
+}; // namespace Fractal
+
+////////////////////////////////////////////////////////////////////////////
+
+inline Fractal::Point operator/(const Fractal::Point& a, Fractal::Value b) {
+       Fractal::Point rv(a);
+       rv.real(real(rv)/b);
+       rv.imag(imag(rv)/b);
+       return rv;
+}
+
+#endif /* FRACTALMATHS_H_ */
index 30b552d..c293150 100644 (file)
@@ -17,6 +17,7 @@
 */
 
 #include "Fractal.h"
+#include "Fractal-internals.h"
 #include <iostream>
 
 using namespace std;
index eab3c34..a447da7 100644 (file)
@@ -17,6 +17,7 @@
 */
 
 #include "Fractal.h"
+#include "Fractal-internals.h"
 
 using namespace std;
 using namespace Fractal;
index d7807f1..ad1403b 100644 (file)
@@ -17,6 +17,7 @@
 */
 
 #include "Fractal.h"
+#include "Fractal-internals.h"
 
 using namespace std;
 using namespace Fractal;
index eb32ac4..110ec77 100644 (file)
@@ -17,6 +17,7 @@
 */
 
 #include "Fractal.h"
+#include "Fractal-internals.h"
 
 using namespace std;
 using namespace Fractal;