You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.8KB

  1. //
  2. // "$Id: Fl_Tree_Item_Array.H 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. #ifndef _FL_TREE_ITEM_ARRAY_H
  5. #define _FL_TREE_ITEM_ARRAY_H
  6. #include "Fl_Export.H"
  7. class FL_EXPORT Fl_Tree_Item; // forward decl must *precede* first doxygen comment block
  8. // or doxygen will not document our class..
  9. //////////////////////////
  10. // FL/Fl_Tree_Item_Array.H
  11. //////////////////////////
  12. //
  13. // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
  14. // Copyright (C) 2009-2010 by Greg Ercolano.
  15. //
  16. // This library is free software; you can redistribute it and/or
  17. // modify it under the terms of the GNU Library General Public
  18. // License as published by the Free Software Foundation; either
  19. // version 2 of the License, or (at your option) any later version.
  20. //
  21. // This library is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. // Library General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU Library General Public
  27. // License along with this library; if not, write to the Free Software
  28. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  29. // USA.
  30. //
  31. ///
  32. /// \file
  33. /// \brief This file defines a class that manages an array of Fl_Tree_Item pointers.
  34. ///
  35. /// \brief Manages an array of Fl_Tree_Item pointers.
  36. ///
  37. /// Because FLTK 1.x.x. has mandated that templates and STL not be used,
  38. /// we use this class to dynamically manage the arrays.
  39. ///
  40. /// None of the methods do range checking on index values; the caller
  41. /// must be sure that index values are within the range 0<index<total()
  42. /// (unless otherwise noted).
  43. ///
  44. class FL_EXPORT Fl_Tree_Item_Array {
  45. Fl_Tree_Item **_items; // items array
  46. int _total; // #items in array
  47. int _size; // #items *allocated* for array
  48. int _chunksize; // #items to enlarge mem allocation
  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. Fl_Tree_Item *asave = _items[ax];
  69. _items[ax] = _items[bx];
  70. _items[bx] = asave;
  71. }
  72. void clear();
  73. void add(Fl_Tree_Item *val);
  74. void insert(int pos, Fl_Tree_Item *new_item);
  75. void remove(int index);
  76. int remove(Fl_Tree_Item *item);
  77. };
  78. #endif /*_FL_TREE_ITEM_ARRAY_H*/
  79. //
  80. // End of "$Id: Fl_Tree_Item_Array.H 7903 2010-11-28 21:06:39Z matt $".
  81. //