view include/Fractal.h @ 4:df02a7de7fe2

I think I've got the Abstract Factory code working pretty robustly now, though I still need to make the factory singletons thread-safe
author Eris Caffee <discordia@eldalin.com>
date Tue, 26 Oct 2010 02:03:47 -0500
parents 0f4ad525f49a
children d691ce98f406
line source
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) 2010 Sarah Eris Horsley Caffee
4 //
5 // mandelbrot - A simple Mandelbrot Set viewer.
6 //
7 // Fractal.h
8 // Fractal calculator virtual class definition. Actual fractals should
9 // implement this.
10 //
11 ////////////////////////////////////////////////////////////////////////////////
13 #ifndef FRACTAL_H
14 #define FRACTAL_H
16 #include <map>
17 #include <string>
19 // Need to define this via the pre-processor because if it's a staticaly
20 // initialized const string we still have no guarantee that it will be
21 // initialized before it is needed by a FractalCreator class.
22 // Do the same in all derived classes.
24 class Fractal
25 {
26 public:
27 Fractal();
29 virtual bool calc_set() = 0;
30 virtual bool init(SDL_Surface * surf) = 0;
32 double get_re_min() const;
33 double set_re_min(const double r_min);
35 double get_im_max() const;
36 double set_im_max(const double i_max);
38 double get_size() const;
39 double set_size(const double s);
41 unsigned int get_max_iter() const;
42 unsigned int set_max_iter(const unsigned int iter);
43 unsigned int inc_max_iter();
44 unsigned int dec_max_iter();
46 void set_calc_needed();
48 virtual std::string const & get_display_name() const;
49 virtual std::string const & get_fractal_name() const;
52 virtual bool get_option(std::string option, void * value) const {};
53 virtual bool set_option(std::string option, void * value) {};
57 protected:
59 virtual void draw_pixel(int x, int y, Uint32 * color);
61 // fractal_name is the basic name of ths fractal, such as "Mandelbrot set"
62 // or "Julia set"
63 // display_name is probably the same, but might have a bit of extra info,
64 // such as "Julia set K=(1,2)
65 std::string display_name;
66 std::string fractal_name;
68 double re_min;
69 double im_max;
70 double size;
71 unsigned int max_iter;
72 bool calc_needed;
74 SDL_Surface * surface;
76 };
78 class FractalCreator
79 {
80 public:
81 virtual Fractal * create() const = 0;
82 };
84 std::map <std::string, FractalCreator *> & get_Fractal_map();
86 #endif