diff src/ov-class.h @ 9522:e79470be3ecb

implement subsasgn this-arg optimization
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 13 Aug 2009 15:51:57 +0200
parents e08d72bb988e
children 8e5009334661
line wrap: on
line diff
--- a/src/ov-class.h	Thu Aug 13 11:52:07 2009 +0200
+++ b/src/ov-class.h	Thu Aug 13 15:51:57 2009 +0200
@@ -1,6 +1,7 @@
 /*
 
 Copyright (C) 2007, 2008, 2009 John W. Eaton
+Copyright (C) 2009 VZLU Prague
 
 This file is part of Octave.
 
@@ -35,6 +36,7 @@
 #include "oct-alloc.h"
 #include "oct-map.h"
 #include "ov-base.h"
+#include "ov-struct.h"
 #include "ov-typeinfo.h"
 
 class octave_value_list;
@@ -44,19 +46,19 @@
 // Data structures.
 
 class
-octave_class : public octave_base_value
+octave_class : public octave_struct
 {
 public:
 
   octave_class (void)
-    : octave_base_value () { }
+    : octave_struct (), obsolete_copies (0) { }
 
   octave_class (const Octave_map& m, const std::string& id)
-    : octave_base_value (), map (m), c_name (id) { }
+    : octave_struct (m), c_name (id), obsolete_copies (0) { }
 
   octave_class (const octave_class& s)
-    : octave_base_value (s), map (s.map), c_name (s.c_name),
-      parent_list (s.parent_list) { }
+    : octave_struct (s), c_name (s.c_name),
+      parent_list (s.parent_list), obsolete_copies (0) { }
 
   octave_class (const Octave_map& m, const std::string& id, 
                 const octave_value_list& parents);
@@ -65,6 +67,8 @@
 
   octave_base_value *clone (void) const { return new octave_class (*this); }
 
+  octave_base_value *unique_clone (void);
+
   octave_base_value *empty_clone (void) const
   {
     return new octave_class (Octave_map (map.keys ()), class_name ());
@@ -72,6 +76,8 @@
 
   Cell dotref (const octave_value_list& idx);
 
+  octave_value dotasgn (const octave_value_list& idx, const octave_value& rhs);
+
   Matrix size (void);
 
   octave_idx_type numel (const octave_value_list&); 
@@ -83,13 +89,14 @@
       return tmp.length () > 0 ? tmp(0) : octave_value ();
     }
 
+  octave_value subsref (const std::string& type,
+			const std::list<octave_value_list>& idx,
+                        bool auto_add);
+
   octave_value_list subsref (const std::string& type,
 			     const std::list<octave_value_list>& idx,
 			     int nargout);
 
-  static octave_value numeric_conv (const Cell& val,
-				    const std::string& type);
-
   void assign(const std::string& k, const octave_value& rhs)
   { map.assign (k, rhs); };
 
@@ -101,34 +108,12 @@
 
   dim_vector dims (void) const { return map.dims (); }
 
-  size_t byte_size (void) const;
-
-  // This is the number of elements in each field.  The total number
-  // of elements is numel () * nfields ().
-  octave_idx_type numel (void) const
-  {
-    dim_vector dv = dims ();
-    return dv.numel ();
-  }
-
-  octave_idx_type nfields (void) const { return map.nfields (); }
-
   size_t nparents (void) const { return parent_list.size (); }
 
-  octave_value reshape (const dim_vector& new_dims) const
-    { return map.reshape (new_dims); }
-
-  octave_value resize (const dim_vector& dv, bool = false) const
-    { Octave_map tmap = map; tmap.resize (dv); return tmap; }
-
-  bool is_defined (void) const { return true; }
-
   bool is_map (void) const { return false; }
 
   bool is_object (void) const { return true; }
 
-  Octave_map map_value (void) const { return map; }
-
   string_vector map_keys (void) const;
 
   std::list<std::string> parent_class_name_list (void) const
@@ -171,9 +156,11 @@
 
   mxArray *as_mxArray (void) const;
 
-private:
+protected:
 
-  Octave_map map;
+  void gripe_failed_assignment (void);
+
+private:
 
   DECLARE_OCTAVE_ALLOCATOR
 
@@ -196,6 +183,8 @@
 
   bool in_class_method (void) const;
 
+  int obsolete_copies;
+
 public:
   // The list of field names and parent classes defines a class.  We
   // keep track of each class that has been created so that we know