[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
OOP load update
From: |
Robert T. Short |
Subject: |
OOP load update |
Date: |
Tue, 05 May 2009 10:49:34 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.21) Gecko/20090402 SeaMonkey/1.1.16 |
Attached is a fix so that the load command works with legacy objects.
It works for binary and hdf5 formats, but the save command doesn't work
with ASCII files, so I haven't fixed the load command. Will work on
that later.
This is the last major issue with legacy objects. There are scads of
minor issues left.
Bob
--
Robert T. Short, Ph.D.
PhaseLocked Systems
# HG changeset patch
# User Robert T. Short <address@hidden>
# Date 1241544631 25200
# Node ID 91378b29a535fb93b4a3503b48fcf4b9c57603cd
# Parent 742cf6388a8f1d2c84b580535be09cfce92ac5db
* file-ops.h (tail()) New function.
* ov-class.h (reconstruct_parents): New function.
* ov-class.cc (added reconstruct_parents method): Fix parent list
when a load is performed.
(load_hdf5, load_binary): Fix parent list when a load is performed.
(get_current_method_class): Cleaned up method class extraction.
* ov-base.h (find_parent_class): Removed pointless FIXME.
* Associated changelog entries.
diff -r 742cf6388a8f -r 91378b29a535 liboctave/ChangeLog
--- a/liboctave/ChangeLog Sat May 02 07:20:35 2009 -0700
+++ b/liboctave/ChangeLog Tue May 05 10:30:31 2009 -0700
@@ -1,3 +1,7 @@
+2009-05-04 Robert T. Short <address@hidden>
+
+ * file-ops.h (tail()) New function.
+
2009-04-16 Jaroslav Hajek <address@hidden>
* idx-vector.cc (idx_vector::idx_range_rep::idx_range_rep (const
diff -r 742cf6388a8f -r 91378b29a535 liboctave/file-ops.h
--- a/liboctave/file-ops.h Sat May 02 07:20:35 2009 -0700
+++ b/liboctave/file-ops.h Tue May 05 10:30:31 2009 -0700
@@ -109,6 +109,18 @@
return static_members::dir_sep_chars ();
}
+ // Return the tail member of a path.
+ static std::string tail (std::string path)
+ {
+ size_t ipos = path.find_last_of (dir_sep_char ());
+
+ if (ipos != std::string::npos)
+ ipos++;
+ else
+ ipos = 0;
+ return path.substr (ipos);
+ }
+
private:
// Use a singleton class for these data members instead of just
diff -r 742cf6388a8f -r 91378b29a535 src/ChangeLog
--- a/src/ChangeLog Sat May 02 07:20:35 2009 -0700
+++ b/src/ChangeLog Tue May 05 10:30:31 2009 -0700
@@ -1,3 +1,12 @@
+b2009-05-04 Robert T. Short <address@hidden>
+
+ * ov-class.h (reconstruct_parents): New function.
+ * ov-class.cc (added reconstruct_parents method): Fix parent list
+ when a load is performed.
+ (load_hdf5, load_binary): Fix parent list when a load is performed.
+ (get_current_method_class): Cleaned up method class extraction.
+ * ov-base.h (find_parent_class): Removed pointless FIXME.
+
2009-05-01 John W. Eaton <address@hidden>
* error.cc (Vlast_error_file, Vlast_error_name, Vlast_error_line,
diff -r 742cf6388a8f -r 91378b29a535 src/ov-base.h
--- a/src/ov-base.h Sat May 02 07:20:35 2009 -0700
+++ b/src/ov-base.h Tue May 05 10:30:31 2009 -0700
@@ -458,7 +458,6 @@
virtual string_vector parent_class_names (void) const;
- // FIXME -- should this warn if called for a non-class type?
virtual octave_base_value *find_parent_class (const std::string&)
{ return 0; }
diff -r 742cf6388a8f -r 91378b29a535 src/ov-class.cc
--- a/src/ov-class.cc Sat May 02 07:20:35 2009 -0700
+++ b/src/ov-class.cc Tue May 05 10:30:31 2009 -0700
@@ -33,6 +33,7 @@
#include "Cell.h"
#include "defun.h"
#include "error.h"
+#include "file-ops.h"
#include "gripes.h"
#include "load-path.h"
#include "ls-hdf5.h"
@@ -98,15 +99,13 @@
{
std::string retval;
- // FIXME -- is there a better way to do this?
octave_function *fcn = octave_call_stack::current ();
std::string my_dir = fcn->dir_name ();
- size_t ipos = my_dir.find_last_of ("@");
+ std::string method_class = file_ops::tail (my_dir);
- if (ipos != std::string::npos)
- retval = my_dir.substr (ipos+1);
+ retval = method_class.substr (1);
return retval;
}
@@ -814,6 +813,65 @@
}
}
+// Load/save does not provide enough information to reconstruct the
+// class inheritance structure. reconstruct_parents () attempts to
+// do so. If successful, a "true" value is returned.
+//
+// Note that we don't check the loaded object structure against the
+// class structure here so the user's loadobj method has a chance
+// to do its magic.
+bool
+octave_class::reconstruct_parents (void)
+{
+ bool retval = true, might_have_inheritance = false;
+ std::string dbgstr = "dork";
+
+ // First, check to see if there might be an issue with inheritance.
+ for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++)
+ {
+ std::string key = map.key (p);
+ Cell val = map.contents (p);
+ if ( val(0).is_object() )
+ {
+ dbgstr = "blork";
+ if( key == val(0).class_name() )
+ {
+ might_have_inheritance = true;
+ dbgstr = "cork";
+ break;
+ }
+ }
+ }
+
+ if (might_have_inheritance)
+ {
+ octave_class::exemplar_const_iterator it
+ = octave_class::exemplar_map.find (c_name);
+
+ if (it == octave_class::exemplar_map.end ())
+ retval = false;
+ else
+ {
+ octave_class::exemplar_info exmplr = it->second;
+ parent_list = exmplr.parents ();
+ for (std::list<std::string>::iterator pit = parent_list.begin ();
+ pit != parent_list.end ();
+ pit++)
+ {
+ dbgstr = *pit;
+ bool dbgbool = map.contains (*pit);
+ if (!dbgbool)
+ {
+ retval = false;
+ break;
+ }
+ }
+ }
+ }
+
+ return retval;
+}
+
bool
octave_class::save_ascii (std::ostream& os)
{
@@ -1033,15 +1091,20 @@
{
map = m;
- if (load_path::find_method (class_name(), "loadobj") != std::string())
+ if (!reconstruct_parents ())
+ error("unable to reconstruct object inheritance");
+ else
{
- octave_value in = new octave_class (*this);
- octave_value_list tmp = feval ("loadobj", in, 1);
+ if (load_path::find_method (c_name, "loadobj") != std::string())
+ {
+ octave_value in = new octave_class (*this);
+ octave_value_list tmp = feval ("loadobj", in, 1);
- if (! error_state)
- map = tmp(0).map_value ();
- else
- success = false;
+ if (! error_state)
+ map = tmp(0).map_value ();
+ else
+ success = false;
+ }
}
}
else
@@ -1253,21 +1316,26 @@
{
map = m;
- if (load_path::find_method (class_name(), "loadobj") != std::string())
+ if (!reconstruct_parents ())
+ error("unable to reconstruct object inheritance");
+ else
{
- octave_value in = new octave_class (*this);
- octave_value_list tmp = feval ("loadobj", in, 1);
+ if (load_path::find_method (c_name, "loadobj") != std::string())
+ {
+ octave_value in = new octave_class (*this);
+ octave_value_list tmp = feval ("loadobj", in, 1);
- if (! error_state)
- {
- map = tmp(0).map_value ();
- retval = true;
+ if (! error_state)
+ {
+ map = tmp(0).map_value ();
+ retval = true;
+ }
+ else
+ retval = false;
}
else
- retval = false;
+ retval = true;
}
- else
- retval = true;
}
error_cleanup:
diff -r 742cf6388a8f -r 91378b29a535 src/ov-class.h
--- a/src/ov-class.h Sat May 02 07:20:35 2009 -0700
+++ b/src/ov-class.h Tue May 05 10:30:31 2009 -0700
@@ -144,6 +144,8 @@
void print_with_name (std::ostream& os, const std::string& name,
bool print_padding = true) const;
+ bool reconstruct_parents (void);
+
bool save_ascii (std::ostream& os);
bool load_ascii (std::istream& is);
- OOP load update,
Robert T. Short <=
- OOP load update, John W. Eaton, 2009/05/05
- Re: OOP load update, Robert T. Short, 2009/05/05
- Re: OOP load update, WMennerich, 2009/05/05
- Re: OOP load update, Robert T. Short, 2009/05/05
- Re: OOP load update, John W. Eaton, 2009/05/05
- Re: OOP load update, Robert T. Short, 2009/05/05
- Re: OOP load update, John W. Eaton, 2009/05/05
- Re: OOP load update, Judd Storrs, 2009/05/05
- Re: OOP load update, Judd Storrs, 2009/05/05