26 #if defined (HAVE_CONFIG_H)
50 (*
m_rep)[fields(i)] = i;
58 (*m_rep)[std::string (*fields++)] =
n++;
70 auto p =
m_rep->find (field);
71 return (p !=
m_rep->end ()) ? p->second : -1;
77 auto p =
m_rep->find (field);
78 if (p !=
m_rep->end ())
84 return (*
m_rep)[field] =
n;
91 auto p =
m_rep->find (field);
92 if (p ==
m_rep->end ())
99 for (
auto& fld_idx : *
m_rep)
101 if (fld_idx.second >=
n)
117 for (
auto& fld_idx : *
m_rep)
132 auto q = other.
begin ();
133 for (; p !=
end () && q != other.
end (); p++, q++)
135 if (p->first == q->first)
136 perm[p->second] = q->second;
141 retval = (p ==
end () && q == other.
end ());
163 for (
auto& fld_idx : *
this)
164 retval.
xelem (fld_idx.second) = fld_idx.first;
170 (
const std::map<std::string, octave_value>&
m)
172 std::size_t sz =
m.size ();
175 for (
const auto& k_v :
m)
237 error (
"orderfields: structs must have same fields up to order");
263 : m_keys (
m.m_keys), m_vals (), m_dimensions (1, 1)
270 m_vals[i].xelem (0) =
m.m_vals[i];
288 error (
"octave_map::setfield: internal error");
335 error (
"orderfields: structs must have same fields up to order");
482 dummy = dummy.
permute (vec, inv);
536 retval.
m_vals.reserve (nf);
605 retval.
m_vals.reserve (nf);
626 retval.
m_vals.reserve (nf);
633 field_list[i] = map_list[i].
m_vals[j];
660 template <
typename map>
666 new_map_list[idx] = map_list[idx];
678 new_map_list[i], perm);
681 catch (octave::execution_exception& ee)
683 error (ee,
"cat: field names mismatch in concatenating structs");
693 if (dim == -1 || dim == -2)
696 error (
"cat: invalid dimension");
699 retval = map_list[0];
703 for (idx = 0; idx <
n; idx++)
716 bool all_same =
true;
725 do_cat (dim,
n, map_list, retval);
733 do_cat (dim,
n, new_map_list, retval);
757 if (dim == -1 || dim == -2)
760 error (
"cat: invalid dimension");
763 retval = map_list[0];
768 for (idx = 0; idx <
n; idx++)
779 bool all_same =
true;
792 if (all_same && nf > 0)
793 do_cat (dim,
n, map_list, retval);
803 do_cat (dim,
n, new_map_list, retval);
812 error (
"dimension mismatch in struct concatenation");
860 dummy = dummy.
index (i, resize_ok);
871 bool resize_ok)
const
885 dummy = dummy.
index (i, j, resize_ok);
909 dummy = dummy.
index (ia, resize_ok);
938 retval =
index (i, resize_ok);
949 retval =
index (i, j, resize_ok);
957 for (k = 0; k < n_idx; k++)
958 ia(k) = idx(k).index_vector ();
960 retval =
index (ia, resize_ok);
965 catch (octave::index_exception& ie)
968 ie.set_pos_if_unset (n_idx, k+1);
979 return index (octave::idx_vector::colon, k);
986 octave::idx_vector::colon);
1008 dummy.assign (i, rhs_dummy);;
1029 catch (octave::execution_exception& ee)
1031 error (ee,
"incompatible fields in struct assignment");
1056 dummy.assign (i, j, rhs_dummy);;
1077 catch (octave::execution_exception& ee)
1079 error (ee,
"incompatible fields in struct assignment");
1104 dummy.assign (ia, rhs_dummy);;
1125 catch (octave::execution_exception& ee)
1127 error (ee,
"incompatible fields in struct assignment");
1173 for (k = 0; k < n_idx; k++)
1174 ia(k) = idx(k).index_vector ();
1181 catch (octave::index_exception& ie)
1184 ie.set_pos_if_unset (n_idx, k+1);
1298 ia(i) = idx(i).index_vector ();
1300 catch (octave::index_exception& ie)
1303 ie.set_pos_if_unset (n_idx, i+1);
1323 for (
auto pa =
cbegin (); pa !=
cend (); pa++)
1327 if (pb == rb.
cend ())
1328 error (
"field name mismatch in structure concatenation");
1340 error (
"invalid structure concatenation");
1354 error (
"internal error: dimension mismatch across fields in struct");
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
OCTARRAY_API void clear(void)
OCTARRAY_API Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_API void delete_elements(const octave::idx_vector &i)
Deleting elements.
OCTARRAY_API Array< T, Alloc > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
Cell & insert(const Cell &a, octave_idx_type r, octave_idx_type c)
void assign(const octave_value_list &idx, const Cell &rhs, const octave_value &fill_val=Matrix())
Vector representing the dimensions (size) of an Array.
OCTAVE_API bool concat(const dim_vector &dvb, int dim)
This corresponds to cat().
void resize(int n, int fill_value=0)
bool all_zero(void) const
void chop_trailing_singletons(void)
OCTAVE_API dim_vector squeeze(void) const
void orderfields(Array< octave_idx_type > &perm)
const_iterator begin(void) const
octave_idx_type rmfield(const std::string &name)
static fields_rep * nil_rep(void)
string_vector fieldnames(void) const
octave_idx_type nfields(void) const
bool equal_up_to_order(const octave_fields &other, octave_idx_type *perm) const
bool is_same(const octave_fields &other) const
bool isfield(const std::string &name) const
const_iterator end(void) const
octave_idx_type getfield(const std::string &name) const
void resize(const dim_vector &dv, bool fill=false)
Cell getfield(const std::string &key) const
static void do_cat(int dim, octave_idx_type n, const octave_scalar_map *map_list, octave_map &retval)
void rmfield(const std::string &key)
octave_scalar_map fast_elem_extract(octave_idx_type n) const
octave_map reshape(const dim_vector &dv) const
octave_idx_type nfields(void) const
void optimize_dimensions(void)
const_iterator cend(void) const
octave_map permute(const Array< int > &vec, bool inv=false) const
octave_map transpose(void) const
void delete_elements(const octave::idx_vector &i)
void setfield(const std::string &key, const Cell &val)
octave_map page(octave_idx_type k) const
const_iterator seek(const std::string &k) const
octave_map concat(const octave_map &rb, const Array< octave_idx_type > &ra_idx)
void assign(const std::string &k, const Cell &val)
void extract_scalar(octave_scalar_map &dest, octave_idx_type index) const
std::string key(const_iterator p) const
octave_map orderfields(void) const
const_iterator end(void) const
string_vector keys(void) const
const_iterator cbegin(void) const
const Cell & contents(const_iterator p) const
dim_vector dims(void) const
bool fast_elem_insert(octave_idx_type n, const octave_scalar_map &rhs)
static octave_map cat(int dim, octave_idx_type n, const octave_scalar_map *map_list)
octave_scalar_map elem(octave_idx_type n) const
std::vector< Cell > m_vals
octave_idx_type index(const_iterator p) const
octave_map column(octave_idx_type k) const
octave_map squeeze(void) const
octave_scalar_map orderfields(void) const
const octave_value & contents(const_iterator p) const
octave_idx_type nfields(void) const
void setfield(const std::string &key, const octave_value &val)
void rmfield(const std::string &key)
std::vector< octave_value > m_vals
octave_value getfield(const std::string &key) const
octave_idx_type length(void) const
std::string & xelem(octave_idx_type i)
octave_idx_type numel(void) const
void error(const char *fmt,...)
void error_unless(bool cond)
octave::idx_vector idx_vector
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void permute_to_correct_order1(const octave_scalar_map &ref, const octave_scalar_map &src, octave_scalar_map &dest, Array< octave_idx_type > &perm)
static void permute_to_correct_order(octave_idx_type n, octave_idx_type nf, octave_idx_type idx, const map *map_list, map *new_map_list)
const octave_base_value const Array< octave_idx_type > & ra_idx
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))