Rename Array to Vector

Finally get rid of the C style vector, rename the template class to its proper name
This commit is contained in:
topjohnwu
2018-11-08 05:03:59 -05:00
parent b6965105b7
commit 8745c7884e
15 changed files with 52 additions and 56 deletions

View File

@ -4,13 +4,13 @@
#include "cpputils.h"
template <class T>
class Array {
class Vector {
public:
Array() : _data(0), _size(0), _capacity(0) {}
~Array() { delete []_data; }
Vector() : _data(0), _size(0), _capacity(0) {}
~Vector() { delete []_data; }
class iterator {
friend class Array;
friend class Vector;
public:
iterator(T* n= 0): _node(n) {}
@ -67,7 +67,7 @@ public:
T* _node;
};
Array &operator=(const Array& a) {
Vector &operator=(const Vector& a) {
delete [] _data;
_data = nullptr;
_size = a._size;
@ -80,7 +80,7 @@ public:
return *this;
}
Array &operator=(Array&& a) {
Vector &operator=(Vector&& a) {
delete [] _data;
_size = a._size;
_capacity = a._capacity;
@ -188,4 +188,4 @@ private:
};
template<class T>
int(* Array<T>::_cmp)(T&, T&) = nullptr;
int(* Vector<T>::_cmp)(T&, T&) = nullptr;

View File

@ -13,14 +13,13 @@
#ifdef __cplusplus
#include "array.h"
#include "Vector.h"
#include "CharArray.h"
#include "cpputils.h"
int file_to_array(const char *filename, Array<CharArray> &arr);
int file_to_vector(const char *filename, Vector<CharArray> &arr);
char *strdup2(const char *s, size_t *size = nullptr);
extern "C" {
#endif
@ -29,7 +28,7 @@ extern "C" {
#define UID_SYSTEM (get_system_uid())
#define UID_RADIO (get_radio_uid())
// xwrap.c
// xwrap.cpp
FILE *xfopen(const char *pathname, const char *mode);
FILE *xfdopen(int fd, const char *mode);
@ -85,7 +84,7 @@ ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count);
pid_t xfork();
int xpoll(struct pollfd *fds, nfds_t nfds, int timeout);
// misc.c
// misc.cpp
unsigned get_shell_uid();
unsigned get_system_uid();
@ -108,7 +107,7 @@ ssize_t __getline(char **lineptr, size_t *n, FILE *stream);
ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
int __fsetxattr(int fd, const char *name, const void *value, size_t size, int flags);
// file.c
// file.cpp
#define align(p, a) (((p) + (a) - 1) / (a) * (a))
#define align_off(p, a) (align(p, a) - (p))