# HG changeset patch
# User Konstantinos Poulios
# Date 1291819678 -3600
# Node ID 4140f28784c35b73be86474f395f5611486fa3ef
# Parent e773d57de57252789acfc562302e901059391966
Add a 'weakly set' flag in base_property.
diff -r e773d57de572 -r 4140f28784c3 src/ChangeLog
--- a/src/ChangeLog Wed Dec 08 07:57:16 2010 -0500
+++ b/src/ChangeLog Wed Dec 08 15:47:58 2010 +0100
@@ -1,3 +1,17 @@
+2010-12-08 Konstantinos Poulios
+
+ * genprops.awk, graphics.h.in (*properties::set_weakly): New method.
+ (base_property::is_weak): New method.
+ (base_property::set_weakmode): New method.
+ (base_graphics_object::set_weakly): New method.
+ (base_properties::set_weakly): New method.
+ * graphics.cc (base_property::set): Set weakmode to false when called.
+ (xset_weakly_forced): New static function which sets a property value
+ and sets its weakmode to true.
+ This changeset implements the possibility of escalated setting of a
+ property. Calling the method set_weakmode a property can be marked
+ as weakly or strongly set.
+
2010-12-08 John W. Eaton
* graphics.h.in (base_property::do_set): Don't reverse order of
diff -r e773d57de572 -r 4140f28784c3 src/genprops.awk
--- a/src/genprops.awk Wed Dec 08 07:57:16 2010 -0500
+++ b/src/genprops.awk Wed Dec 08 15:47:58 2010 +0100
@@ -249,6 +249,7 @@
printf (" properties (const graphics_handle& mh, const graphics_handle& p);\n\n");
printf (" ~properties (void) { }\n\n");
printf (" void set (const caseless_str& pname, const octave_value& val);\n\n");
+ printf (" void set_weakly (const caseless_str& pname, const octave_value& val, bool forced = false);\n\n");
printf (" octave_value get (bool all = false) const;\n\n");
printf (" octave_value get (const caseless_str& pname) const;\n\n");
printf (" octave_value get (const std::string& pname) const\n {\n return get (caseless_str (pname));\n }\n\n");
@@ -461,6 +462,34 @@
else
printf (" else\n base_properties::set (pname, val);\n}\n\n");
+ ## set_weakly method
+
+ if (base)
+ printf ("void\nbase_properties::set_weakly (const caseless_str& pname, const octave_value& val, bool forced)\n{\n");
+ else
+ printf ("void\n%s::properties::set_weakly (const caseless_str& pname_arg, const octave_value& val, bool forced)\n{\n",
+ class_name);
+
+ if (! base)
+ printf (" const std::set& pnames = all_property_names ();\n\n caseless_str pname = validate_property_name (\"get\", go_name, pnames, pname_arg);\n\n if (error_state)\n return;\n\n");
+
+ first = 1;
+
+ for (i = 1; i <= idx; i++)
+ {
+ if (! readonly[i])
+ {
+ printf (" %sif (pname.compare (\"%s\"))\n {\n if (%s.is_weak () || forced)\n {\n set_%s (val);\n %s.set_weakmode (true);\n }\n }\n",
+ (first == 0 ? "else " : ""), name[i], name[i], name[i], name[i]);
+ first = 0;
+ }
+ }
+
+ if (base)
+ printf (" else\n error (\"set_weakly: unknown property \\\"%%s\\\"\", pname.c_str ());\n}\n\n");
+ else
+ printf (" else\n base_properties::set_weakly (pname, val, forced);\n}\n\n");
+
## get "all" method
if (base)
diff -r e773d57de572 -r 4140f28784c3 src/graphics.cc
--- a/src/graphics.cc Wed Dec 08 07:57:16 2010 -0500
+++ b/src/graphics.cc Wed Dec 08 15:47:58 2010 +0100
@@ -781,6 +781,7 @@
if (do_run && ! error_state)
run_listeners (POSTSET);
+ set_weakmode (false);
return true;
}
@@ -1918,6 +1919,14 @@
}
}
+static void
+xset_weakly_forced (const graphics_handle& h, const caseless_str& name,
+ const octave_value& val)
+{
+ graphics_object obj = gh_manager::get_object (h);
+ obj.set_weakly (name, val, true);
+}
+
static octave_value
xget (const graphics_handle& h, const caseless_str& name)
{
diff -r e773d57de572 -r 4140f28784c3 src/graphics.h.in
--- a/src/graphics.h.in Wed Dec 08 07:57:16 2010 -0500
+++ b/src/graphics.h.in Wed Dec 08 15:47:58 2010 +0100
@@ -320,10 +320,11 @@
base_property (void) : id (-1), count (1) { }
base_property (const std::string& s, const graphics_handle& h)
- : id (-1), count (1), name (s), parent (h), hidden (false) { }
+ : id (-1), count (1), name (s), parent (h), hidden (false), weak(false) { }
base_property (const base_property& p)
- : id (-1), count (1), name (p.name), parent (p.parent), hidden (p.hidden) { }
+ : id (-1), count (1), name (p.name), parent (p.parent), hidden (p.hidden),
+ weak (p.weak) { }
virtual ~base_property (void) { }
@@ -343,6 +344,10 @@
virtual bool is_radio (void) const { return false; }
+ bool is_weak (void) const { return weak; }
+
+ void set_weakmode (bool flag) { weak = flag; }
+
int get_id (void) const { return id; }
void set_id (int d) { id = d; }
@@ -437,6 +442,7 @@
graphics_handle parent;
bool hidden;
listener_map listeners;
+ bool weak;
};
// ---------------------------------------------------------------------
@@ -1639,6 +1645,12 @@
bool is_radio (void) const
{ return rep->is_radio (); }
+ bool is_weak (void) const
+ { return rep->is_weak (); }
+
+ void set_weakmode (bool flag)
+ { rep->set_weakmode (flag); }
+
int get_id (void) const
{ return rep->get_id (); }
@@ -2000,6 +2012,9 @@
virtual void set (const caseless_str&, const octave_value&);
+ virtual void set_weakly (const caseless_str&, const octave_value&,
+ bool forced = false);
+
virtual octave_value get (const caseless_str& pname) const;
virtual octave_value get (const std::string& pname) const
@@ -2218,6 +2233,15 @@
error ("base_graphics_object::set: invalid graphics object");
}
+ virtual void set_weakly (const caseless_str& pname, const octave_value& pval,
+ bool forced)
+ {
+ if (valid_object ())
+ get_properties ().set_weakly (pname, pval, forced);
+ else
+ error ("base_graphics_object::set_weakly: invalid graphics object");
+ }
+
virtual void set_defaults (const std::string&)
{
error ("base_graphics_object::set_defaults: invalid graphics object");
@@ -2454,6 +2478,12 @@
void set (const octave_map& m);
+ void set_weakly (const caseless_str& pname, const octave_value& pval,
+ bool forced = false)
+ {
+ rep->set_weakly (pname, pval, forced);
+ }
+
void set_value_or_default (const caseless_str& name,
const octave_value& val);