summaryrefslogtreecommitdiff
path: root/src/Fl_Int_Vector.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2022-11-06 15:01:47 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2022-11-06 16:32:29 +0100
commit8b92935b1e2964889d76fe64374be1ab3b040027 (patch)
tree6ee9a567ca8a92eef53cf15c9ac6fca6f3cfc8cb /src/Fl_Int_Vector.cxx
parentc4bb4e192ed4661f4a74e31b1f5ae8116c59cc9e (diff)
Add Fl_Int_Vector: "an STL-ish vector without templates"
Code copied from Fl_Table and reformatted. Thanks to Greg for the original code.
Diffstat (limited to 'src/Fl_Int_Vector.cxx')
-rw-r--r--src/Fl_Int_Vector.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Fl_Int_Vector.cxx b/src/Fl_Int_Vector.cxx
new file mode 100644
index 000000000..361dd2634
--- /dev/null
+++ b/src/Fl_Int_Vector.cxx
@@ -0,0 +1,43 @@
+//
+// An STL-ish vector without templates for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2002 by Greg Ercolano.
+// Copyright 2022 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
+//
+
+#include <FL/Fl_Int_Vector.H>
+#include <stdlib.h>
+
+void Fl_Int_Vector::copy(int *newarr, unsigned int newsize) {
+ size(newsize);
+ memcpy(arr_, newarr, newsize * sizeof(int));
+}
+
+Fl_Int_Vector::~Fl_Int_Vector() {
+ if (arr_)
+ free(arr_);
+}
+
+void Fl_Int_Vector::size(unsigned int count) {
+ if (count <= 0) {
+ if (arr_)
+ free(arr_);
+ arr_ = 0;
+ size_ = 0;
+ return;
+ }
+ if (count > size_) {
+ arr_ = (int *)realloc(arr_, count * sizeof(int));
+ size_ = count;
+ }
+}