Mercurial > octave-nkf
comparison src/oct-map.h @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | fd0a3ac60b0e |
children | a21a3875ca83 |
comparison
equal
deleted
inserted
replaced
11585:1473d0cf86d2 | 11586:12df7854fa7c |
---|---|
31 #include "oct-obj.h" | 31 #include "oct-obj.h" |
32 | 32 |
33 class string_vector; | 33 class string_vector; |
34 | 34 |
35 // A class holding a map field->index. Supports reference-counting. | 35 // A class holding a map field->index. Supports reference-counting. |
36 class OCTINTERP_API | 36 class OCTINTERP_API |
37 octave_fields | 37 octave_fields |
38 { | 38 { |
39 class fields_rep : public std::map<std::string, octave_idx_type> | 39 class fields_rep : public std::map<std::string, octave_idx_type> |
40 { | 40 { |
41 public: | 41 public: |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 octave_fields (const octave_fields& o) : rep (o.rep) { rep->count++; } | 81 octave_fields (const octave_fields& o) : rep (o.rep) { rep->count++; } |
82 | 82 |
83 octave_fields& | 83 octave_fields& |
84 operator = (const octave_fields& o) | 84 operator = (const octave_fields& o) |
85 { | 85 { |
86 o.rep->count++; | 86 o.rep->count++; |
87 if (--rep->count == 0) | 87 if (--rep->count == 0) |
88 delete rep; | 88 delete rep; |
100 const_iterator end (void) const { return rep->end (); } | 100 const_iterator end (void) const { return rep->end (); } |
101 | 101 |
102 std::string key (const_iterator p) const { return p->first; } | 102 std::string key (const_iterator p) const { return p->first; } |
103 octave_idx_type index (const_iterator p) const { return p->second; } | 103 octave_idx_type index (const_iterator p) const { return p->second; } |
104 | 104 |
105 const_iterator seek (const std::string& k) const | 105 const_iterator seek (const std::string& k) const |
106 { return rep->find (k); } | 106 { return rep->find (k); } |
107 | 107 |
108 // high-level methods. | 108 // high-level methods. |
109 | 109 |
110 // number of fields. | 110 // number of fields. |
178 const_iterator begin (void) const { return xkeys.begin (); } | 178 const_iterator begin (void) const { return xkeys.begin (); } |
179 const_iterator end (void) const { return xkeys.end (); } | 179 const_iterator end (void) const { return xkeys.end (); } |
180 | 180 |
181 const_iterator seek (const std::string& k) const { return xkeys.seek (k); } | 181 const_iterator seek (const std::string& k) const { return xkeys.seek (k); } |
182 | 182 |
183 std::string key (const_iterator p) const | 183 std::string key (const_iterator p) const |
184 { return xkeys.key (p); } | 184 { return xkeys.key (p); } |
185 octave_idx_type index (const_iterator p) const | 185 octave_idx_type index (const_iterator p) const |
186 { return xkeys.index (p); } | 186 { return xkeys.index (p); } |
187 | 187 |
188 const octave_value& contents (const_iterator p) const | 188 const octave_value& contents (const_iterator p) const |
189 { return xvals[xkeys.index (p)]; } | 189 { return xvals[xkeys.index (p)]; } |
190 | 190 |
191 octave_value& contents (iterator p) | 191 octave_value& contents (iterator p) |
192 { return xvals[xkeys.index (p)]; } | 192 { return xvals[xkeys.index (p)]; } |
193 | 193 |
199 | 199 |
200 // number of fields. | 200 // number of fields. |
201 octave_idx_type nfields (void) const { return xkeys.nfields (); } | 201 octave_idx_type nfields (void) const { return xkeys.nfields (); } |
202 | 202 |
203 // check whether a field exists. | 203 // check whether a field exists. |
204 bool isfield (const std::string& name) const | 204 bool isfield (const std::string& name) const |
205 { return xkeys.isfield (name); } | 205 { return xkeys.isfield (name); } |
206 | 206 |
207 bool contains (const std::string& name) const | 207 bool contains (const std::string& name) const |
208 { return isfield (name); } | 208 { return isfield (name); } |
209 | 209 |
210 string_vector fieldnames (void) const | 210 string_vector fieldnames (void) const |
211 { return xkeys.fieldnames (); } | 211 { return xkeys.fieldnames (); } |
212 | 212 |
301 const_iterator begin (void) const { return xkeys.begin (); } | 301 const_iterator begin (void) const { return xkeys.begin (); } |
302 const_iterator end (void) const { return xkeys.end (); } | 302 const_iterator end (void) const { return xkeys.end (); } |
303 | 303 |
304 const_iterator seek (const std::string& k) const { return xkeys.seek (k); } | 304 const_iterator seek (const std::string& k) const { return xkeys.seek (k); } |
305 | 305 |
306 std::string key (const_iterator p) const | 306 std::string key (const_iterator p) const |
307 { return xkeys.key (p); } | 307 { return xkeys.key (p); } |
308 octave_idx_type index (const_iterator p) const | 308 octave_idx_type index (const_iterator p) const |
309 { return xkeys.index (p); } | 309 { return xkeys.index (p); } |
310 | 310 |
311 const Cell& contents (const_iterator p) const | 311 const Cell& contents (const_iterator p) const |
312 { return xvals[xkeys.index (p)]; } | 312 { return xvals[xkeys.index (p)]; } |
313 | 313 |
314 Cell& contents (iterator p) | 314 Cell& contents (iterator p) |
315 { return xvals[xkeys.index (p)]; } | 315 { return xvals[xkeys.index (p)]; } |
316 | 316 |
322 | 322 |
323 // number of fields. | 323 // number of fields. |
324 octave_idx_type nfields (void) const { return xkeys.nfields (); } | 324 octave_idx_type nfields (void) const { return xkeys.nfields (); } |
325 | 325 |
326 // check whether a field exists. | 326 // check whether a field exists. |
327 bool isfield (const std::string& name) const | 327 bool isfield (const std::string& name) const |
328 { return xkeys.isfield (name); } | 328 { return xkeys.isfield (name); } |
329 | 329 |
330 bool contains (const std::string& name) const | 330 bool contains (const std::string& name) const |
331 { return isfield (name); } | 331 { return isfield (name); } |
332 | 332 |
333 string_vector fieldnames (void) const | 333 string_vector fieldnames (void) const |
334 { return xkeys.fieldnames (); } | 334 { return xkeys.fieldnames (); } |
335 | 335 |
341 | 341 |
342 // set contents of a given field. add if not exist. checks for | 342 // set contents of a given field. add if not exist. checks for |
343 // correct dimensions. | 343 // correct dimensions. |
344 void setfield (const std::string& key, const Cell& val); | 344 void setfield (const std::string& key, const Cell& val); |
345 void assign (const std::string& k, const Cell& val) | 345 void assign (const std::string& k, const Cell& val) |
346 { setfield (k, val); } | 346 { setfield (k, val); } |
347 | 347 |
348 // remove a given field. do nothing if not exist. | 348 // remove a given field. do nothing if not exist. |
349 void rmfield (const std::string& key); | 349 void rmfield (const std::string& key); |
350 void del (const std::string& k) { rmfield (k); } | 350 void del (const std::string& k) { rmfield (k); } |
351 | 351 |
388 | 388 |
389 octave_scalar_map | 389 octave_scalar_map |
390 operator () (const Array<octave_idx_type>& ra_idx) const | 390 operator () (const Array<octave_idx_type>& ra_idx) const |
391 { return checkelem (ra_idx); } | 391 { return checkelem (ra_idx); } |
392 | 392 |
393 octave_map squeeze (void) const; | 393 octave_map squeeze (void) const; |
394 | 394 |
395 octave_map permute (const Array<int>& vec, bool inv = false) const; | 395 octave_map permute (const Array<int>& vec, bool inv = false) const; |
396 | 396 |
397 dim_vector dims (void) const { return dimensions; } | 397 dim_vector dims (void) const { return dimensions; } |
398 | 398 |
399 int ndims (void) const { return dimensions.length (); } | 399 int ndims (void) const { return dimensions.length (); } |
400 | 400 |
417 | 417 |
418 octave_map index (const Array<idx_vector>& ia, | 418 octave_map index (const Array<idx_vector>& ia, |
419 bool resize_ok = false) const; | 419 bool resize_ok = false) const; |
420 | 420 |
421 octave_map index (const octave_value_list&, bool resize_ok = false) const; | 421 octave_map index (const octave_value_list&, bool resize_ok = false) const; |
422 | 422 |
423 octave_map column (octave_idx_type k) const; | 423 octave_map column (octave_idx_type k) const; |
424 octave_map page (octave_idx_type k) const; | 424 octave_map page (octave_idx_type k) const; |
425 | 425 |
426 void assign (const idx_vector& i, const octave_map& rhs); | 426 void assign (const idx_vector& i, const octave_map& rhs); |
427 | 427 |
428 void assign (const idx_vector& i, const idx_vector& j, const octave_map& rhs); | 428 void assign (const idx_vector& i, const idx_vector& j, const octave_map& rhs); |
429 | 429 |
430 void assign (const Array<idx_vector>& ia, const octave_map& rhs); | 430 void assign (const Array<idx_vector>& ia, const octave_map& rhs); |
431 | 431 |
432 void assign (const octave_value_list&, const octave_map& rhs); | 432 void assign (const octave_value_list&, const octave_map& rhs); |
433 | 433 |
434 void assign (const octave_value_list& idx, const std::string& k, | 434 void assign (const octave_value_list& idx, const std::string& k, |
435 const Cell& rhs); | 435 const Cell& rhs); |
436 | 436 |
437 void delete_elements (const idx_vector& i); | 437 void delete_elements (const idx_vector& i); |
438 | 438 |
455 octave_fields xkeys; | 455 octave_fields xkeys; |
456 std::vector<Cell> xvals; | 456 std::vector<Cell> xvals; |
457 dim_vector dimensions; | 457 dim_vector dimensions; |
458 | 458 |
459 void optimize_dimensions (void); | 459 void optimize_dimensions (void); |
460 void extract_scalar (octave_scalar_map& dest, | 460 void extract_scalar (octave_scalar_map& dest, |
461 octave_idx_type index) const; | 461 octave_idx_type index) const; |
462 static void do_cat (int dim, octave_idx_type n, | 462 static void do_cat (int dim, octave_idx_type n, |
463 const octave_scalar_map *map_list, octave_map& retval); | 463 const octave_scalar_map *map_list, octave_map& retval); |
464 static void do_cat (int dim, octave_idx_type n, | 464 static void do_cat (int dim, octave_idx_type n, |
465 const octave_map *map_list, octave_map& retval); | 465 const octave_map *map_list, octave_map& retval); |
466 }; | 466 }; |
467 | 467 |
468 template<> | 468 template<> |
469 inline octave_map octave_value_extract<octave_map> (const octave_value& v) | 469 inline octave_map octave_value_extract<octave_map> (const octave_value& v) |
539 return *this; | 539 return *this; |
540 } | 540 } |
541 | 541 |
542 ~Octave_map (void) { } | 542 ~Octave_map (void) { } |
543 | 543 |
544 Octave_map squeeze (void) const; | 544 Octave_map squeeze (void) const; |
545 | 545 |
546 Octave_map permute (const Array<int>& vec, bool inv = false) const; | 546 Octave_map permute (const Array<int>& vec, bool inv = false) const; |
547 | 547 |
548 // This is the number of keys. | 548 // This is the number of keys. |
549 octave_idx_type nfields (void) const { return map.size (); } | 549 octave_idx_type nfields (void) const { return map.size (); } |
550 | 550 |
551 void del (const std::string& k) | 551 void del (const std::string& k) |
628 | 628 |
629 Octave_map& assign (const std::string& k, const octave_value& rhs); | 629 Octave_map& assign (const std::string& k, const octave_value& rhs); |
630 | 630 |
631 Octave_map& assign (const std::string& k, const Cell& rhs); | 631 Octave_map& assign (const std::string& k, const Cell& rhs); |
632 | 632 |
633 Octave_map index (const octave_value_list& idx, | 633 Octave_map index (const octave_value_list& idx, |
634 bool resize_ok = false) const; | 634 bool resize_ok = false) const; |
635 | 635 |
636 private: | 636 private: |
637 | 637 |
638 // The map of names to values. | 638 // The map of names to values. |