Mercurial > hg > octave-nkf
changeset 5880:84ca47e311b3
[project @ 2006-07-06 22:34:48 by jwe]
author | jwe |
---|---|
date | Thu, 06 Jul 2006 22:36:00 +0000 |
parents | 4f1112bfafce |
children | 70b3f8f1a793 |
files | liboctave/ChangeLog liboctave/str-vec.cc liboctave/str-vec.h src/ChangeLog src/DLD-FUNCTIONS/__glpk__.cc src/oct-map.cc src/oct-map.h src/ov-struct.cc |
diffstat | 8 files changed, 130 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2006-07-06 John W. Eaton <jwe@octave.org> + + * str-vec.cc (string_vector::string_vector (std::list<std::string>&)): + New constructor. + * str-vec.h: Provide decl. + 2006-07-01 David Bateman <dbateman@free.fr> * dSparse.cc (tinverse): Check for rows with no elements and zero
--- a/liboctave/str-vec.cc +++ b/liboctave/str-vec.cc @@ -40,6 +40,20 @@ #include "lo-utils.h" #include "str-vec.h" +string_vector::string_vector (const std::list<std::string>& lst) +{ + size_t n = lst.size (); + + resize (n); + + octave_idx_type i = 0; + + for (std::list<std::string>::const_iterator p = lst.begin (); + p != lst.end (); + p++) + elem(i++) = *p; +} + // Create a string vector from a NULL terminated list of C strings. string_vector::string_vector (const char * const *s)
--- a/liboctave/str-vec.h +++ b/liboctave/str-vec.h @@ -25,6 +25,7 @@ #define octave_str_vec_h 1 #include <iostream> +#include <list> #include <string> #include "Array.h" @@ -44,6 +45,8 @@ string_vector (const string_vector& s) : Array<std::string> (s) { } + string_vector (const std::list<std::string>& lst); + string_vector (const char * const *s); string_vector (const char * const *s, octave_idx_type n);
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ +2006-07-06 John W. Eaton <jwe@octave.org> + + * DLD-FUNCTIONS/__glpk__.cc (F__glpk__): Declare mrowsc volatile. + + * ov-struct.cc (octave_struct::print_raw): Print keys in key_list + order. + + * oct-map.h (Octave_map::key_list): New data member. + (Octave_map::maybe_add_to_key_list): New function. + (Octave_map::key_list_iterator, Octave_map::const_key_list_iterator): + New typedefs. + (Octave_map::del): Also delete key from key_list. + * oct-map.cc (Octave_map::keys): Compute return value from + key_list instead of map. + (Octave_map::assign, Octave_map::contents): Call maybe_add_to_key_list. + * oct-map.h, oct-map.cc (Octave_map::Octave_map): + Insert keys in key_list. + + * oct-map.h (Octave_map::Octave_map (const dim_vector&, + const string_vector&)): New arg, key_list_arg. + * oct-map.cc: Move definition here. + 2006-07-05 John W. Eaton <jwe@octave.org> * mex.cc (mexGetVariable): Rename from mexGetArray, swap arguments.
--- a/src/DLD-FUNCTIONS/__glpk__.cc +++ b/src/DLD-FUNCTIONS/__glpk__.cc @@ -431,7 +431,7 @@ //-- 1nd Input. A column array containing the objective function //-- coefficients. - int mrowsc = args(0).rows(); + volatile int mrowsc = args(0).rows(); Matrix C (args(0).matrix_value ());
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -31,9 +31,25 @@ #include "oct-map.h" #include "utils.h" +Octave_map::Octave_map (const dim_vector& dv, + const string_vector& key_list_arg) + : map (), key_list (), dimensions (dv) +{ + Cell c (dv); + + for (octave_idx_type i = 0; i < key_list_arg.length (); i++) + { + std::string k = key_list_arg[i]; + map[k] = c; + key_list.push_back (k); + } +} + Cell& Octave_map::contents (const std::string& k) { + maybe_add_to_key_list (k); + return map[k]; } @@ -75,15 +91,14 @@ string_vector Octave_map::keys (void) const { - octave_idx_type len = length (); - - string_vector names (len); + if (length () != key_list.size ()) + { + std::cerr << "length () = " << length () << std::endl; + std::cerr << "key_list.size () = " << key_list.size () << std::endl; + abort (); + } - octave_idx_type i = 0; - for (const_iterator p = begin (); p != end (); p++) - names[i++] = key (p); - - return names; + return string_vector (key_list); } Octave_map @@ -326,6 +341,8 @@ dimensions = new_dims; + maybe_add_to_key_list (k); + map[k] = tmp; } @@ -337,6 +354,8 @@ { if (empty ()) { + maybe_add_to_key_list (k); + map[k] = Cell (rhs); dimensions = dim_vector (1, 1); @@ -346,7 +365,11 @@ dim_vector dv = dims (); if (dv.all_ones ()) - map[k] = Cell (rhs); + { + maybe_add_to_key_list (k); + + map[k] = Cell (rhs); + } else error ("invalid structure assignment"); } @@ -359,6 +382,8 @@ { if (empty ()) { + maybe_add_to_key_list (k); + map[k] = rhs; dimensions = rhs.dims (); @@ -366,7 +391,11 @@ else { if (dims () == rhs.dims ()) - map[k] = rhs; + { + maybe_add_to_key_list (k); + + map[k] = rhs; + } else error ("invalid structure assignment"); }
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -39,30 +39,44 @@ typedef std::map<std::string, Cell>::iterator iterator; typedef std::map<std::string, Cell>::const_iterator const_iterator; + typedef std::list<std::string>::iterator key_list_iterator; + typedef std::list<std::string>::const_iterator const_key_list_iterator; + // Warning! You should always use at least two dimensions. - Octave_map (const dim_vector& dv = dim_vector (0, 0)) - : map (), dimensions (dv) { } + Octave_map (const dim_vector& dv = dim_vector (0, 0), + const string_vector& key_list_arg = string_vector ()); Octave_map (const std::string& k, const octave_value& value) - : map (), dimensions (1, 1) - { map[k] = value; } + : map (), key_list (), dimensions (1, 1) + { + map[k] = value; + key_list.push_back (k); + } Octave_map (const std::string& k, const Cell& vals) - : map (), dimensions (vals.dims ()) - { map[k] = vals; } + : map (), key_list (), dimensions (vals.dims ()) + { + map[k] = vals; + key_list.push_back (k); + } Octave_map (const std::string& k, const octave_value_list& val_list) - : map (), dimensions (1, val_list.length ()) - { map[k] = val_list; } + : map (), key_list (), dimensions (1, val_list.length ()) + { + map[k] = val_list; + key_list.push_back (k); + } - Octave_map (const Octave_map& m) : map (m.map), dimensions (m.dimensions) { } + Octave_map (const Octave_map& m) + : map (m.map), key_list (m.key_list), dimensions (m.dimensions) { } Octave_map& operator = (const Octave_map& m) { if (this != &m) { map = m.map; + key_list = m.key_list; dimensions = m.dimensions; } @@ -81,6 +95,10 @@ iterator p = map.find (k); if (p != map.end ()) map.erase (p); + + key_list_iterator q = find (key_list.begin (), key_list.end (), k); + if (q != key_list.end ()) + key_list.erase (q); } iterator begin (void) { return iterator (map.begin ()); } @@ -151,8 +169,20 @@ // The map of names to values. std::map<std::string, Cell> map; + // An extra list of keys, so we can keep track of the order the keys + // are added for compatibility with you know what. + std::list<std::string> key_list; + // The current size. mutable dim_vector dimensions; + + void maybe_add_to_key_list (const std::string& k) + { + key_list_iterator p = find (key_list.begin (), key_list.end (), k); + + if (p == key_list.end ()) + key_list.push_back (k); + } }; #endif
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -416,10 +416,6 @@ void octave_struct::print_raw (std::ostream& os, bool) const { - // FIXME -- would be nice to print the output in some - // standard order. Maybe all substructures first, maybe - // alphabetize entries, etc. - unwind_protect::begin_frame ("octave_struct_print"); unwind_protect_int (Vstruct_levels_to_print); @@ -450,10 +446,13 @@ increment_indent_level (); } - for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++) + string_vector key_list = map.keys (); + + for (octave_idx_type i = 0; i < key_list.length (); i++) { - std::string key = map.key (p); - Cell val = map.contents (p); + std::string key = key_list[i]; + + Cell val = map.contents (key); octave_value tmp = (n == 1) ? val(0) : octave_value (val, true);