24 #if !defined (octave_oct_map_h)
25 #define octave_oct_map_h 1
39 class fields_rep :
public std::map<std::string, octave_idx_type>
68 if (--rep->count == 0)
72 void make_unique (
void)
78 if (--rep->count == 0)
91 if (--rep->count == 0)
110 {
return rep->find (k); }
118 bool isfield (
const std::string& name)
const;
141 {
return rep == other.
rep; }
159 : xkeys (k), xvals (k.nfields ()) { }
164 : xkeys (k), xvals (k.
length ()) { }
167 : xkeys (m.xkeys), xvals(m.xvals) { }
188 {
return xkeys.key (p); }
190 {
return xkeys.index (p); }
193 {
return xvals[xkeys.index (p)]; }
196 {
return xvals[xkeys.index (p)]; }
208 bool isfield (
const std::string& name)
const
209 {
return xkeys.isfield (name); }
211 bool contains (
const std::string& name)
const
212 {
return isfield (name); }
215 {
return xkeys.fieldnames (); }
218 {
return fieldnames (); }
224 void setfield (
const std::string& key,
const octave_value& val);
226 { setfield (k, val); }
229 void rmfield (
const std::string& key);
230 void del (
const std::string& k) { rmfield (k); }
260 {
return v.scalar_map_value (); }
268 : xkeys (k), xvals (k.nfields ()), dimensions () { }
271 : xkeys (k), xvals (k.nfields (),
Cell (dv)), dimensions (dv) { }
280 : xkeys (k), xvals (k.
length (),
Cell (1, 1)), dimensions (1, 1) { }
283 : xkeys (k), xvals (k.
length (),
Cell (dv)), dimensions (dv) { }
286 : xkeys (m.xkeys), xvals (m.xvals), dimensions (m.dimensions) { }
312 {
return xkeys.key (p); }
314 {
return xkeys.index (p); }
317 {
return xvals[xkeys.index (p)]; }
320 {
return xvals[xkeys.index (p)]; }
332 bool isfield (
const std::string& name)
const
333 {
return xkeys.isfield (name); }
335 bool contains (
const std::string& name)
const
336 {
return isfield (name); }
339 {
return xkeys.fieldnames (); }
342 {
return fieldnames (); }
345 Cell getfield (
const std::string& key)
const;
349 void setfield (
const std::string& key,
const Cell& val);
350 void assign (
const std::string& k,
const Cell& val)
351 { setfield (k, val); }
354 void rmfield (
const std::string& key);
355 void del (
const std::string& k) { rmfield (k); }
364 Cell contents (
const std::string& k)
const;
365 Cell& contents (
const std::string& k);
376 bool is_empty (
void)
const {
return dimensions.any_zero (); }
390 {
return checkelem (n); }
392 {
return checkelem (i, j); }
396 {
return checkelem (ra_idx); }
404 int ndims (
void)
const {
return dimensions.length (); }
410 void resize (
const dim_vector& dv,
bool fill =
false);
421 bool resize_ok =
false)
const;
424 bool resize_ok =
false)
const;
444 void delete_elements (
int dim,
const idx_vector& i);
465 void optimize_dimensions (
void);
476 {
return v.map_value (); }
488 typedef std::map<std::string, Cell>::iterator
iterator;
500 : map (), key_list (), dimensions (1, 1)
503 key_list.push_back (k);
508 : map (), key_list (), dimensions (dv)
512 std::string k = sv[i];
514 key_list.push_back (k);
519 : map (), key_list (), dimensions (vals.dims ())
522 key_list.push_back (k);
526 : map (), key_list (), dimensions (1, val_list.
length ())
529 key_list.push_back (k);
533 : map (m.map), key_list (m.key_list), dimensions (m.dimensions) { }
558 void del (
const std::string& k)
560 iterator p = map.find (k);
567 =
std::find (key_list.begin (), key_list.end (), k);
569 assert (q != key_list.end ());
575 iterator
begin (
void) {
return iterator (map.begin ()); }
576 const_iterator
begin (
void)
const {
return const_iterator (map.begin ()); }
578 iterator
end (
void) {
return iterator (map.end ()); }
579 const_iterator
end (
void)
const {
return const_iterator (map.end ()); }
581 std::string
key (const_iterator p)
const {
return p->first; }
583 Cell& contents (
const std::string& k);
584 Cell contents (
const std::string& k)
const;
587 {
return p->second; }
589 Cell contents (const_iterator p)
const
590 {
return p->second; }
592 int intfield (
const std::string& k,
int def_val = 0)
const;
595 const std::string& def_val = std::string ())
const;
597 iterator
seek (
const std::string& k) {
return map.find (k); }
598 const_iterator
seek (
const std::string& k)
const {
return map.find (k); }
600 bool contains (
const std::string& k)
const
601 {
return (seek (k) != map.end ()); }
617 int ndims (
void)
const {
return dimensions.length (); }
623 void resize (
const dim_vector& dv,
bool fill =
false);
642 bool resize_ok =
false)
const;
647 std::map<std::string, Cell>
map;
656 void maybe_add_to_key_list (
const std::string& k)
659 key_list.push_back (k);