Mercurial > octave
changeset 23678:dcba41788495
new struct/map constructors
* oct-map.h, oct-map.cc (octave_scalar_map::octave_scalar_map
(const std::map<std::string, octave_value>&)): New constructor.
* ov-struct.h (octave_scalar_struct::octave_scalar_struct
(const std::map<std::string, octave_value>&)): New constructor.
* ov.h, ov.cc (octave_value::octave_value
(const std::map<std::string, octave_value>&)): New constructor.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 22 Jun 2017 15:10:57 -0400 |
parents | 66c4d224f7cb |
children | ece6f43304e5 |
files | libinterp/corefcn/oct-map.cc libinterp/corefcn/oct-map.h libinterp/octave-value/ov-struct.h libinterp/octave-value/ov.cc libinterp/octave-value/ov.h |
diffstat | 5 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/oct-map.cc Thu Jun 22 15:08:29 2017 -0400 +++ b/libinterp/corefcn/oct-map.cc Thu Jun 22 15:10:57 2017 -0400 @@ -167,6 +167,19 @@ return retval; } +octave_scalar_map::octave_scalar_map + (const std::map<std::string, octave_value>& m) +{ + size_t sz = m.size (); + xvals.resize (sz); + size_t i = 0; + for (const auto& k_v : m) + { + xkeys.getfield (k_v.first); + xvals[i++] = k_v.second; + } +} + octave_value octave_scalar_map::getfield (const std::string& k) const {
--- a/libinterp/corefcn/oct-map.h Thu Jun 22 15:08:29 2017 -0400 +++ b/libinterp/corefcn/oct-map.h Thu Jun 22 15:10:57 2017 -0400 @@ -161,7 +161,9 @@ : xkeys (k), xvals (k.numel ()) { } octave_scalar_map (const octave_scalar_map& m) - : xkeys (m.xkeys), xvals(m.xvals) { } + : xkeys (m.xkeys), xvals (m.xvals) { } + + octave_scalar_map (const std::map<std::string, octave_value>& m); octave_scalar_map& operator = (const octave_scalar_map& m) {
--- a/libinterp/octave-value/ov-struct.h Thu Jun 22 15:08:29 2017 -0400 +++ b/libinterp/octave-value/ov-struct.h Thu Jun 22 15:10:57 2017 -0400 @@ -173,6 +173,9 @@ octave_scalar_struct (const octave_scalar_map& m) : octave_base_value (), map (m) { } + octave_scalar_struct (const std::map<std::string, octave_value>& m) + : octave_base_value (), map (m) { } + octave_scalar_struct (const octave_scalar_struct& s) : octave_base_value (), map (s.map) { }
--- a/libinterp/octave-value/ov.cc Thu Jun 22 15:08:29 2017 -0400 +++ b/libinterp/octave-value/ov.cc Thu Jun 22 15:10:57 2017 -0400 @@ -1089,6 +1089,10 @@ : rep (new octave_scalar_struct (m)) { } +octave_value::octave_value (const std::map<std::string, octave_value>& m) + : rep (new octave_scalar_struct (m)) +{ } + octave_value::octave_value (const octave_map& m, const std::string& id, const std::list<std::string>& plist) : rep (new octave_class (m, id, plist))
--- a/libinterp/octave-value/ov.h Thu Jun 22 15:08:29 2017 -0400 +++ b/libinterp/octave-value/ov.h Thu Jun 22 15:10:57 2017 -0400 @@ -31,6 +31,7 @@ #include <iosfwd> #include <string> #include <list> +#include <map> #include "Range.h" #include "data-conv.h" @@ -279,6 +280,7 @@ octave_value (const Range& r, bool force_range = false); octave_value (const octave_map& m); octave_value (const octave_scalar_map& m); + octave_value (const std::map<std::string, octave_value>&); octave_value (const octave_map& m, const std::string& id, const std::list<std::string>& plist); octave_value (const octave_scalar_map& m, const std::string& id,