FLTK 1.4.4: Fl_Int_Vector.H Source File

FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Int_Vector.H
1//
2// An STL-ish vector without templates for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 2002 by Greg Ercolano.
5// Copyright 2022-2023 by Bill Spitzak and others.
6//
7// This library is free software. Distribution and use rights are outlined in
8// the file "COPYING" which should have been included with this file. If this
9// file is missing or damaged, see the license at:
10//
11// https://www.fltk.org/COPYING.php
12//
13// Please see the following page on how to report bugs and issues:
14//
15// https://www.fltk.org/bugs.php
16//
17
18#ifndef Fl_Int_Vector_H
19#define Fl_Int_Vector_H
20
26
27#include <FL/Fl_Export.H>
28
32
71class FL_EXPORT Fl_Int_Vector {
72 int *arr_;
73 unsigned int size_;
74
79 void init() {
80 arr_ = 0;
81 size_ = 0;
82 }
83 void copy(int *newarr, unsigned int newsize);
84
85public:
87 Fl_Int_Vector() {
88 init();
89 }
90
91 ~Fl_Int_Vector();
92
94 Fl_Int_Vector(Fl_Int_Vector &o) {
95 init();
96 copy(o.arr_, o.size_);
97 }
98
104 Fl_Int_Vector &operator=(Fl_Int_Vector &o) {
105 init();
106 copy(o.arr_, o.size_);
107 return *this;
108 }
109
114 int operator[](int x) const {
115 return arr_[x];
116 }
117
126 int &operator[](int x) {
127 return arr_[x];
128 }
129
131 unsigned int size() const {
132 return size_;
133 }
134
135 void size(unsigned int count);
136
143 int pop_back() {
144 int tmp = arr_[size_ - 1];
145 size_--;
146 return tmp;
147 }
148
150 void push_back(int val) {
151 unsigned int x = size_;
152 size(size_ + 1);
153 arr_[x] = val;
154 }
155
161 int back() const {
162 return arr_[size_ - 1];
163 }
164
169 bool empty() const {
170 return (size_ == 0) ? true : false;
171 }
172};
173
178
179#endif // Fl_Int_Vector_H