Fl_Tree_Item_Array.H 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // "$Id: Fl_Tree_Item_Array.H 10071 2014-01-20 21:23:24Z greg.ercolano $"
  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. #if FLTK_ABI_VERSION >= 10303
  46. enum {
  47. MANAGE_ITEM = 1, ///> manage the Fl_Tree_Item's internals (internal use only)
  48. };
  49. char _flags; // flags to control behavior
  50. #endif
  51. void enlarge(int count);
  52. public:
  53. Fl_Tree_Item_Array(int new_chunksize = 10); // CTOR
  54. ~Fl_Tree_Item_Array(); // DTOR
  55. Fl_Tree_Item_Array(const Fl_Tree_Item_Array *o); // COPY CTOR
  56. /// Return the item and index \p i.
  57. Fl_Tree_Item *operator[](int i) {
  58. return(_items[i]);
  59. }
  60. /// Const version of operator[](int i)
  61. const Fl_Tree_Item *operator[](int i) const {
  62. return(_items[i]);
  63. }
  64. /// Return the total items in the array, or 0 if empty.
  65. int total() const {
  66. return(_total);
  67. }
  68. /// Swap the two items at index positions \p ax and \p bx.
  69. #if FLTK_ABI_VERSION >= 10301
  70. // NEW -- code moved to .cxx
  71. void swap(int ax, int bx);
  72. #else /*FLTK_ABI_VERSION*/
  73. // OLD
  74. void swap(int ax, int bx) {
  75. Fl_Tree_Item *asave = _items[ax];
  76. _items[ax] = _items[bx];
  77. _items[bx] = asave;
  78. }
  79. #endif /*FLTK_ABI_VERSION*/
  80. void clear();
  81. void add(Fl_Tree_Item *val);
  82. void insert(int pos, Fl_Tree_Item *new_item);
  83. void replace(int pos, Fl_Tree_Item *new_item);
  84. void remove(int index);
  85. int remove(Fl_Tree_Item *item);
  86. #if FLTK_ABI_VERSION >= 10303
  87. /// Option to control if Fl_Tree_Item_Array's destructor will also destroy the Fl_Tree_Item's.
  88. /// If set: items and item array is destroyed.
  89. /// If clear: only the item array is destroyed, not items themselves.
  90. void manage_item_destroy(int val) {
  91. if ( val ) _flags |= MANAGE_ITEM; else _flags &= ~MANAGE_ITEM;
  92. }
  93. int manage_item_destroy() const {
  94. return _flags & MANAGE_ITEM ? 1 : 0;
  95. }
  96. #endif
  97. };
  98. #endif /*_FL_TREE_ITEM_ARRAY_H*/
  99. //
  100. // End of "$Id: Fl_Tree_Item_Array.H 10071 2014-01-20 21:23:24Z greg.ercolano $".
  101. //