changeset 7527:d219e712c20e

make row_vector_property work?
author John W. Eaton <jwe@octave.org>
date Mon, 25 Feb 2008 04:59:17 -0500
parents 52d58b0463ed
children 26d8a92644de
files src/ChangeLog src/graphics.cc src/graphics.h.in
diffstat 3 files changed, 59 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,14 @@
 2008-02-25  John W. Eaton  <jwe@octave.org>
 
+	* graphics.h.in (row_vector_property::row_vector_property):
+	Set default constraints here.
+	(row_vector_property::add_constraint): New function.
+	(row_vector_property::validate): Delete decl.
+	(axes::properties::init): Use single-arg add_constraint function
+	for xlim, ylim, zlim, clim, and alim properties.
+
+	* graphics.cc (row_vector_property::validate): Delete.
+
 	* graphics.cc (axes::properties::update_camera,
 	axes::properties::update_aspectratios):
 	Avoid shadow warnings from GCC.
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -491,36 +491,6 @@
   return xok;
 }
 
-bool
-row_vector_property::validate (const octave_value& v)
-{
-  bool xok = false;
-
-  // FIXME: should we always support []?
-  if (v.is_empty () && v.is_double_type ())
-    return true;
-
-  // check value type
-  if (type_constraints.size () > 0)
-    {
-      for (std::list<std::string>::const_iterator it = type_constraints.begin ();
-           ! xok && it != type_constraints.end (); ++it)
-        if ((*it) == v.type_name ())
-          xok = true;
-    }
-  else
-    xok = v.is_double_type ();
-
-  if (xok)
-    {
-      dim_vector vdims = v.dims ();
-
-      xok = vdims.length () != 2 || (vdims(0) != 1 && vdims(1) != 1);
-    }
-
-  return xok;
-}
-
 void
 handle_property::set (const octave_value& v)
 {
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -728,32 +728,55 @@
 public:
   row_vector_property (const std::string& nm, const graphics_handle& h,
 		       const octave_value& m)
-    : array_property (nm, h, m) { }
+    : array_property (nm, h, m)
+  {
+    add_constraint (dim_vector (-1, 1));
+    add_constraint (dim_vector (1, -1));
+  }
 
   void set (const octave_value& v)
-    {
-      array_property::set (v);
-
-      if (! error_state)
-	{
-	  dim_vector dv = data.dims ();
-
-	  if (dv(0) > 1 && dv(1) == 1)
-	    {
-	      int tmp = dv(0);
-	      dv(0) = dv(1);
-	      dv(1) = tmp;
-
-	      data = data.reshape (dv);
-	    }
-	}
-    }
+  {
+    array_property::set (v);
+
+    if (! error_state)
+      {
+	dim_vector dv = data.dims ();
+
+	if (dv(0) > 1 && dv(1) == 1)
+	  {
+	    int tmp = dv(0);
+	    dv(0) = dv(1);
+	    dv(1) = tmp;
+
+	    data = data.reshape (dv);
+	  }
+      }
+  }
+
+  void add_constraint (const std::string& type)
+  {
+    array_property::add_constraint (type);
+  }
+
+  void add_constraint (const dim_vector& dims)
+  {
+    array_property::add_constraint (dims);
+  }
+
+  void add_constraint (octave_idx_type len)
+  {
+    size_constraints.remove (dim_vector (1, -1));
+    size_constraints.remove (dim_vector (-1, 1));
+
+    add_constraint (dim_vector (1, len));
+    add_constraint (dim_vector (len, 1));
+  }
 
   row_vector_property& operator = (const octave_value& val)
-    {
-      set (val);
-      return *this;
-    }
+  {
+    set (val);
+    return *this;
+  }
 
 private:
   OCTINTERP_API bool validate (const octave_value& v);
@@ -2465,6 +2488,11 @@
         colororder.add_constraint (dim_vector (-1, 3));
         dataaspectratio.add_constraint (dim_vector (1, 3));
         plotboxaspectratio.add_constraint (dim_vector (1, 3));
+	xlim.add_constraint (2);
+	ylim.add_constraint (2);
+	zlim.add_constraint (2);
+	clim.add_constraint (2);
+	alim.add_constraint (2);
         xtick.add_constraint (dim_vector (1, -1));
         ytick.add_constraint (dim_vector (1, -1));
         ztick.add_constraint (dim_vector (1, -1));