From 8b72f0c6681d0d13506ff56985052b9a81760cdc Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Sun, 6 Nov 2022 20:21:46 -0800 Subject: Add doxygen docs for Fl_Int_Vector. While adding the docs, noticed some things that need modification for proper public use. These are highlighted as \todo items and \warning items, which will be fixed in a separate commit forthcoming. -erco --- FL/Fl_Int_Vector.H | 72 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/Fl_Int_Vector.cxx | 16 ++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/FL/Fl_Int_Vector.H b/FL/Fl_Int_Vector.H index 1ab092a18..89e2d29af 100644 --- a/FL/Fl_Int_Vector.H +++ b/FL/Fl_Int_Vector.H @@ -20,9 +20,51 @@ #include +/** \file FL/Fl_Int_Vector.H + An STL-ish vector implemented without templates. +*/ + +/** + An STL-ish vector without templates. + + Handles dynamic memory management of an integer array, and allows + array elements to be accessed with zero based indexing: v[0], v[1].. + + Common use: + \code + #include + int main() { + Fl_Int_Vector v; + + // Create an array of values 1,2,3: + v.push_back(1); // add first element + v.push_back(2); // add second element + v.push_back(3); // add third element + + // Loop through printing the values + for ( unsigned int i=0; i #include +/** + Make a copy of another array. + Private: For use internally by the class's copy ctors only. +*/ void Fl_Int_Vector::copy(int *newarr, unsigned int newsize) { size(newsize); memcpy(arr_, newarr, newsize * sizeof(int)); } +/** Destructor - frees the internal array and destroys the class. */ Fl_Int_Vector::~Fl_Int_Vector() { if (arr_) free(arr_); } +/** + Set the size of the array to \p count. + + A size of zero empties the array completely and frees all memory. + + \warning + - Only advised use currently is to shrink the array size, i.e. (count < size()). + - Currently enlarging the array leaves the new values uninitialized. + - When assignment via indexes is supported, i.e. v[x] = 123, array enlargement should zero new values + \todo Check if count > size, and if so init new values to 0. +*/ void Fl_Int_Vector::size(unsigned int count) { if (count <= 0) { if (arr_) -- cgit v1.2.3