Fl_Tree_Item_Array.H 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // "$Id: Fl_Tree_Item_Array.H 9706 2012-11-06 20:46:14Z matt $"
  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. void enlarge(int count);
  46. public:
  47. Fl_Tree_Item_Array(int new_chunksize = 10); // CTOR
  48. ~Fl_Tree_Item_Array(); // DTOR
  49. Fl_Tree_Item_Array(const Fl_Tree_Item_Array *o); // COPY CTOR
  50. /// Return the item and index \p i.
  51. Fl_Tree_Item *operator[](int i) {
  52. return(_items[i]);
  53. }
  54. /// Const version of operator[](int i)
  55. const Fl_Tree_Item *operator[](int i) const {
  56. return(_items[i]);
  57. }
  58. /// Return the total items in the array, or 0 if empty.
  59. int total() const {
  60. return(_total);
  61. }
  62. /// Swap the two items at index positions \p ax and \p bx.
  63. #if FLTK_ABI_VERSION >= 10301
  64. // NEW -- code moved to .cxx
  65. void swap(int ax, int bx);
  66. #else /*FLTK_ABI_VERSION*/
  67. // OLD
  68. void swap(int ax, int bx) {
  69. Fl_Tree_Item *asave = _items[ax];
  70. _items[ax] = _items[bx];
  71. _items[bx] = asave;
  72. }
  73. #endif /*FLTK_ABI_VERSION*/
  74. void clear();
  75. void add(Fl_Tree_Item *val);
  76. void insert(int pos, Fl_Tree_Item *new_item);
  77. void remove(int index);
  78. int remove(Fl_Tree_Item *item);
  79. };
  80. #endif /*_FL_TREE_ITEM_ARRAY_H*/
  81. //
  82. // End of "$Id: Fl_Tree_Item_Array.H 9706 2012-11-06 20:46:14Z matt $".
  83. //