Fl_Tree_Item_Array.H 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // "$Id: Fl_Tree_Item_Array.H 11679 2016-04-23 04:30:39Z manolo $"
  3. //
  4. #ifndef _FL_TREE_ITEM_ARRAY_H
  5. #define _FL_TREE_ITEM_ARRAY_H
  6. #include <FL/Fl.H>
  7. #include "Fl_Export.H"
  8. class FL_EXPORT Fl_Tree_Item; // forward decl must *precede* first doxygen comment block
  9. // or doxygen will not document our class..
  10. //////////////////////////
  11. // FL/Fl_Tree_Item_Array.H
  12. //////////////////////////
  13. //
  14. // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
  15. // Copyright (C) 2009-2010 by Greg Ercolano.
  16. //
  17. // This library is free software. Distribution and use rights are outlined in
  18. // the file "COPYING" which should have been included with this file. If this
  19. // file is missing or damaged, see the license at:
  20. //
  21. // http://www.fltk.org/COPYING.php
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. ///
  28. /// \file
  29. /// \brief This file defines a class that manages an array of Fl_Tree_Item pointers.
  30. ///
  31. /// \brief Manages an array of Fl_Tree_Item pointers.
  32. ///
  33. /// Because FLTK 1.x.x. has mandated that templates and STL not be used,
  34. /// we use this class to dynamically manage the arrays.
  35. ///
  36. /// None of the methods do range checking on index values; the caller
  37. /// must be sure that index values are within the range 0<index<total()
  38. /// (unless otherwise noted).
  39. ///
  40. class FL_EXPORT Fl_Tree_Item_Array {
  41. Fl_Tree_Item **_items; // items array
  42. int _total; // #items in array
  43. int _size; // #items *allocated* for array
  44. int _chunksize; // #items to enlarge mem allocation
  45. enum {
  46. MANAGE_ITEM = 1, ///> manage the Fl_Tree_Item's internals (internal use only)
  47. };
  48. char _flags; // flags to control behavior
  49. void enlarge(int count);
  50. public:
  51. Fl_Tree_Item_Array(int new_chunksize = 10); // CTOR
  52. ~Fl_Tree_Item_Array(); // DTOR
  53. Fl_Tree_Item_Array(const Fl_Tree_Item_Array *o); // COPY CTOR
  54. /// Return the item and index \p i.
  55. Fl_Tree_Item *operator[](int i) {
  56. return(_items[i]);
  57. }
  58. /// Const version of operator[](int i)
  59. const Fl_Tree_Item *operator[](int i) const {
  60. return(_items[i]);
  61. }
  62. /// Return the total items in the array, or 0 if empty.
  63. int total() const {
  64. return(_total);
  65. }
  66. /// Swap the two items at index positions \p ax and \p bx.
  67. void swap(int ax, int bx);
  68. int move(int to, int from);
  69. int deparent(int pos);
  70. int reparent(Fl_Tree_Item *item, Fl_Tree_Item *newparent, int pos);
  71. void clear();
  72. void add(Fl_Tree_Item *val);
  73. void insert(int pos, Fl_Tree_Item *new_item);
  74. void replace(int pos, Fl_Tree_Item *new_item);
  75. void remove(int index);
  76. int remove(Fl_Tree_Item *item);
  77. /// Option to control if Fl_Tree_Item_Array's destructor will also destroy the Fl_Tree_Item's.
  78. /// If set: items and item array is destroyed.
  79. /// If clear: only the item array is destroyed, not items themselves.
  80. void manage_item_destroy(int val) {
  81. if ( val ) _flags |= MANAGE_ITEM; else _flags &= ~MANAGE_ITEM;
  82. }
  83. int manage_item_destroy() const {
  84. return _flags & MANAGE_ITEM ? 1 : 0;
  85. }
  86. };
  87. #endif /*_FL_TREE_ITEM_ARRAY_H*/
  88. //
  89. // End of "$Id: Fl_Tree_Item_Array.H 11679 2016-04-23 04:30:39Z manolo $".
  90. //