diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-10-22 19:30:37 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-10-22 19:35:17 +0200 |
| commit | 1209e9dcd7e1e97bedc747d06ba4eea837562158 (patch) | |
| tree | 7897d3c61368958f191bfe684b96d1d08467a2bb /FL/Fl_Int_Vector.H | |
| parent | 05ac0247cbd902f910fa89f8d4f4fde9de904b0f (diff) | |
Make Fl_String and Fl_Int_Vector private (#789)
- add CMake option 'OPTION_USE_STD'
- add configure option '--enable-use_std'
- move FL/Fl_String.H to src/Fl_String.H
- move FL/Fl_Int_Vector.H to src/Fl_Int_Vector.H
- remove Fl_String from demo program examples/callbacks.cxx
- remove Fl_Int_Vector from public header FL/Fl_Table.H
- some methods of Fl_Table are no longer inline
- add CMake option OPTION_USE_STD to allow std::string in some
selected functions and methods
Experimental, may be removed before release:
- use either Fl_Int_Vector or std::vector in Fl_Table depending
on CMake OPTION_USE_STD or configure --enable-use_std
Move all fl_filename* functions that use Fl_String to fluid
Main changes in fluid:
- add fluid_filename.h and .cxx
- include "fluid_filename.h" rather than <FL/filename.H>
Update fl_input(), fl_password() and test/ask
- add maxchar parameter to fl_input() and fl_password()
- fl_input_str() and fl_password_str() are optional and return
std::string if enabled (FLTK_USE_STD)
Diffstat (limited to 'FL/Fl_Int_Vector.H')
| -rw-r--r-- | FL/Fl_Int_Vector.H | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/FL/Fl_Int_Vector.H b/FL/Fl_Int_Vector.H deleted file mode 100644 index d21e8668c..000000000 --- a/FL/Fl_Int_Vector.H +++ /dev/null @@ -1,166 +0,0 @@ -// -// An STL-ish vector without templates for the Fast Light Tool Kit (FLTK). -// -// Copyright 2002 by Greg Ercolano. -// Copyright 2022-2023 by Bill Spitzak and others. -// -// This library is free software. Distribution and use rights are outlined in -// the file "COPYING" which should have been included with this file. If this -// file is missing or damaged, see the license at: -// -// https://www.fltk.org/COPYING.php -// -// Please see the following page on how to report bugs and issues: -// -// https://www.fltk.org/bugs.php -// - -#ifndef Fl_Int_Vector_H -#define Fl_Int_Vector_H - -#include <FL/Fl_Export.H> - -/** \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 <stdio.h> - #include <FL/Fl_Int_Vector.H> - int main() { - Fl_Int_Vector v; - - // Create an array of values 11,22,33: - v.push_back(11); // add first element - v.push_back(22); // add second element - v.push_back(33); // add third element - - // Assignment by subscript - v[1] = 222; // changes 2nd element from 22 to 222 - - // Loop through printing the values - for ( unsigned int i=0; i<v.size(); i++ ) - printf("%d ", v[i]); // access the elements - printf("\n"); - - // Clear the array - v.size(0); - } - \endcode - - \todo - - Add other std::vector methods like erase(), etc. - - Make memory blocking size flexible, and add related methods like capacity(), reserve(), shrink_to_fit(), etc. - - Add non-std methods that are nevertheless needed, e.g. insert(index,val), delete(index), delete(start, end), swap(a_idx,b_idx) -*/ -class FL_EXPORT Fl_Int_Vector { - int *arr_; - unsigned int size_; - - /** - Initialize internals. - Private: For use internally by the class's ctors only. - */ - void init() { - arr_ = 0; - size_ = 0; - } - void copy(int *newarr, unsigned int newsize); - -public: - /** Create an empty vector of integers. */ - Fl_Int_Vector() { - init(); - } - - ~Fl_Int_Vector(); - - /** Copy constructor. */ - Fl_Int_Vector(Fl_Int_Vector &o) { - init(); - copy(o.arr_, o.size_); - } - - /** - Assignment operator. Similar to the copy constructor, - creates a separate copy of the source array, freeing any - previous contents in the current integer array. - */ - Fl_Int_Vector &operator=(Fl_Int_Vector &o) { - init(); - copy(o.arr_, o.size_); - return *this; - } - - /** - Access the specified integer element at index position \p x. - \warning No range checking is done on \p x, which must be less than size(). - */ - int operator[](int x) const { - return arr_[x]; - } - - /** - Access the specified integer element at index position \p x as a reference. - - This allows assignment by index through the returned reference, e.g. arr[1] = 222; - where arr[1] ends up being a reference to ptr[1], and then 222 is assigned to that ref. - - \warning No range checking is done on \p x, which must be less than size(). - */ - int &operator[](int x) { - return arr_[x]; - } - - /** Return the number of integer elements in the array. */ - unsigned int size() const { - return size_; - } - - void size(unsigned int count); - - /** - Removes the last element the last element and returns its value. - - \warning You must not call pop_back() if the array is empty, i.e. if (size() == 0). - \todo Internals should maybe assert(size_ != 0) - */ - int pop_back() { - int tmp = arr_[size_ - 1]; - size_--; - return tmp; - } - - /** Appends \p val to the array, enlarging the array by one. */ - void push_back(int val) { - unsigned int x = size_; - size(size_ + 1); - arr_[x] = val; - } - - /** - Return the last element in the array. - \warning You must not call back() if the array is empty, i.e. if (size() == 0). - \todo Internals should maybe assert(size_ != 0) - */ - int back() const { - return arr_[size_ - 1]; - } - - /** - Checks if array has no elements. - Same as a test for (size() == 0). - */ - bool empty() const { - return (size_ == 0) ? true : false; - } -}; - -#endif // Fl_Int_Vector_H |
