26 #if ! defined (octave_oct_map_h)
27 #define octave_oct_map_h 1
29 #include "octave-config.h"
45 class fields_rep :
public std::map<std::string, octave_idx_type>
49 fields_rep () : std::map<std::string, octave_idx_type> (), m_count (1) { }
51 fields_rep (
const fields_rep& other)
52 : std::map<std::string, octave_idx_type> (other), m_count (1) { }
54 fields_rep& operator = (
const fields_rep&) =
delete;
56 ~fields_rep () =
default;
58 octave::refcount<octave_idx_type> m_count;
63 static fields_rep * nil_rep ();
73 if (--m_rep->m_count == 0)
79 if (m_rep->m_count > 1)
81 fields_rep *
r =
new fields_rep (*m_rep);
83 if (--m_rep->m_count == 0)
98 if (--m_rep->m_count == 0)
121 {
return m_rep->find (k); }
129 bool isfield (
const std::string& name)
const;
152 {
return m_rep == other.m_rep; }
169 : m_keys (k), m_vals (k.nfields ()) { }
172 : m_keys (k), m_vals (k.
numel ()) { }
193 {
return m_keys.key (p); }
195 {
return m_keys.index (p); }
198 {
return m_vals[m_keys.index (p)]; }
201 {
return m_vals[m_keys.index (p)]; }
204 {
return m_vals[i]; }
207 {
return m_vals[i]; }
214 {
return m_keys.isfield (name); }
217 {
return isfield (name); }
220 {
return m_keys.fieldnames (); }
223 {
return fieldnames (); }
229 void setfield (
const std::string& key,
const octave_value& val);
231 { setfield (k, val); }
234 void rmfield (
const std::string& key);
235 void del (
const std::string& k) { rmfield (k); }
258 std::vector<octave_value> m_vals;
272 : m_keys (k), m_vals (k.nfields ()), m_dimensions () { }
275 : m_keys (k), m_vals (k.nfields (),
Cell (dv)), m_dimensions (dv) { }
282 : m_keys (k), m_vals (k.
numel (),
Cell (1, 1)), m_dimensions (1, 1) { }
285 : m_keys (k), m_vals (k.
numel (),
Cell (dv)), m_dimensions (dv) { }
289 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (
octave_map)
306 {
return m_keys.key (p); }
308 {
return m_keys.index (p); }
311 {
return m_vals[m_keys.index (p)]; }
314 {
return m_vals[m_keys.index (p)]; }
317 {
return m_vals[i]; }
320 {
return m_vals[i]; }
327 {
return m_keys.isfield (name); }
330 {
return isfield (name); }
333 {
return m_keys.fieldnames (); }
336 {
return fieldnames (); }
339 Cell getfield (
const std::string& key)
const;
343 void setfield (
const std::string& key,
const Cell& val);
345 { setfield (k, val); }
348 void rmfield (
const std::string& key);
349 void del (
const std::string& k) { rmfield (k); }
358 Cell contents (
const std::string& k)
const;
359 Cell& contents (
const std::string& k);
370 bool isempty ()
const {
return m_dimensions.any_zero (); }
383 {
return elem (i, j); }
399 {
return elem (i, j); }
411 int ndims ()
const {
return m_dimensions.ndims (); }
417 void resize (
const dim_vector& dv,
bool fill =
false);
428 bool resize_ok =
false)
const;
431 bool resize_ok =
false)
const;
470 std::vector<Cell> m_vals;
473 void optimize_dimensions ();
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Vector representing the dimensions (size) of an Array.
const_iterator end() const
std::map< std::string, octave_idx_type >::const_iterator const_iterator
std::string key(const_iterator p) const
const_iterator cbegin() const
const_iterator begin() const
octave_idx_type nfields() const
bool is_same(const octave_fields &other) const
octave_fields(const octave_fields &o)
const_iterator seek(const std::string &k) const
const_iterator cend() const
octave_idx_type index(const_iterator p) const
const_iterator cbegin() const
void del(const std::string &k)
const Cell & contents(octave_idx_type i) const
octave_idx_type nfields() const
octave_idx_type cols() const
octave_idx_type length() const
const_iterator end() const
octave_idx_type rows() const
string_vector keys() const
octave_scalar_map checkelem(const Array< octave_idx_type > &ra_idx) const
octave_scalar_map checkelem(octave_idx_type n) const
string_vector fieldnames() const
octave_fields::const_iterator const_iterator
octave_idx_type columns() const
bool isfield(const std::string &name) const
octave_idx_type numel() const
Cell & contents(iterator p)
const_iterator seek(const std::string &k) const
bool contains(const std::string &name) const
void assign(const std::string &k, const Cell &val)
octave_scalar_map element_type
std::string key(const_iterator p) const
Cell & contents(octave_idx_type i)
octave_map(const dim_vector &dv, const string_vector &k)
octave_map(const string_vector &k)
const Cell & contents(const_iterator p) const
octave_map(const dim_vector &dv, const octave_fields &k)
const_iterator cend() const
octave_idx_type index(const_iterator p) const
octave_scalar_map checkelem(octave_idx_type i, octave_idx_type j) const
octave_map(const octave_fields &k)
octave_map(const dim_vector &dv)
octave_fields::const_iterator const_iterator
const_iterator cend() const
string_vector keys() const
const_iterator cbegin() const
const_iterator end() const
octave_scalar_map(const octave_fields &k)
octave_value & contents(octave_idx_type i)
bool contains(const std::string &name) const
const octave_value & contents(const_iterator p) const
const octave_value & contents(octave_idx_type i) const
string_vector fieldnames() const
bool isfield(const std::string &name) const
octave_scalar_map(const string_vector &k)
void assign(const std::string &k, const octave_value &val)
octave_value & contents(iterator p)
octave_idx_type index(const_iterator p) const
const_iterator seek(const std::string &k) const
void del(const std::string &k)
octave_idx_type nfields() const
std::string key(const_iterator p) const
octave_scalar_map scalar_map_value() const
octave_map map_value() const
octave::idx_vector idx_vector
octave_scalar_map octave_value_extract< octave_scalar_map >(const octave_value &v)
octave_map octave_value_extract< octave_map >(const octave_value &v)
T::size_type numel(const T &str)
const octave_base_value const Array< octave_idx_type > & ra_idx