Graphics properties as objects
Michael Goffioul
michael.goffioul at gmail.com
Tue Jan 8 03:57:30 CST 2008
Hi,
I thought again about possible implementation, trying to consider everything.
So I'd like to propose the following scheme. Would this be acceptable?
Note: I decided to write the direct access get_xxx methods such that they
return the property value; the reason is that those accessors will mostly be
used by the C++ backend, which is mainly interested in the values; this makes
the code of the backend more intuitive.
class base_property
{
public:
...
void set_name (const std::string& name);
void set_parent (const graphics_handle& h);
};
class matrix_property : public base_property
{
public:
matrix_property (Matrix m)
: base_property (), data (m) { }
...
Matrix matrix_value (void) const { return data; }
private:
Matrix data;
};
class property
{
public:
property (base_property *p, bool persist = false);
...
};
class base_properties
{
public:
...
// this method is to add dynamic properties into the map
void insert_property (const std::string& name, property p)
{
p.set_name (name);
p.set_parent (__myhandle__);
all_props[name] = p;
}
// this method is to add fixed properties into the map
// (could probably be "protected")
void insert_static_property (const std::string& name, base_property& p)
{
p.set_name (name);
p.set_parent (__myhandle__);
all_props[name] = property (&p, true);
}
};
class axes : public graphics_object
{
public:
class properties : public base_properties
{
public:
properties (...)
: base_properties (...) ,
position (Matrix ()),
...
{
insert_static_property ("position", position);
...
}
Matrix get_position (void) const { return position.matrix_value (); }
void set_position (const octave_value& v) { position.set (v); }
...
private:
matrix_property position;
...
};
};
More information about the Octave-maintainers
mailing list