Rename larray to vector

This commit is contained in:
Gary Talent 2017-12-23 20:08:45 -06:00
parent 61de47fd00
commit 1d65ca210f
3 changed files with 39 additions and 23 deletions

View File

@ -198,7 +198,7 @@ map<string, int(*)(string)> tests = {
auto dataIn = "test string"; auto dataIn = "test string";
auto dataOutLen = 1024 * 64; auto dataOutLen = 1024 * 64;
auto dataOut = new char[dataOutLen]; auto dataOut = new char[dataOutLen];
vector<uint64_t> inodes; std::vector<uint64_t> inodes;
const auto size = 1024 * 1024; const auto size = 1024 * 1024;
auto buff = new uint8_t[size]; auto buff = new uint8_t[size];
@ -234,7 +234,7 @@ map<string, int(*)(string)> tests = {
auto dataIn = "test string"; auto dataIn = "test string";
auto dataOutLen = ox_strlen(dataIn) + 1; auto dataOutLen = ox_strlen(dataIn) + 1;
auto dataOut = new char[dataOutLen]; auto dataOut = new char[dataOutLen];
vector<uint64_t> inodes; std::vector<uint64_t> inodes;
const auto size = 1024 * 1024; const auto size = 1024 * 1024;
auto buff = new uint8_t[size]; auto buff = new uint8_t[size];
@ -263,7 +263,7 @@ map<string, int(*)(string)> tests = {
auto dataIn = "test string"; auto dataIn = "test string";
auto dataOutLen = ox_strlen(dataIn) + 1; auto dataOutLen = ox_strlen(dataIn) + 1;
auto dataOut = new char[dataOutLen]; auto dataOut = new char[dataOutLen];
vector<uint64_t> inodes; std::vector<uint64_t> inodes;
const auto size = 1024 * 1024; const auto size = 1024 * 1024;
auto buff = new uint8_t[size]; auto buff = new uint8_t[size];
@ -298,8 +298,8 @@ map<string, int(*)(string)> tests = {
auto dataIn = "test string"; auto dataIn = "test string";
auto dataOutLen = ox_strlen(dataIn) + 1; auto dataOutLen = ox_strlen(dataIn) + 1;
auto dataOut = new char[dataOutLen]; auto dataOut = new char[dataOutLen];
vector<uint64_t> inodes; std::vector<uint64_t> inodes;
vector<DirectoryListing<string>> files; std::vector<DirectoryListing<string>> files;
const auto size = 1024 * 1024; const auto size = 1024 * 1024;
auto buff = new uint8_t[size]; auto buff = new uint8_t[size];

View File

@ -7,7 +7,6 @@
*/ */
#pragma once #pragma once
#include "array.hpp"
#include "bitops.hpp" #include "bitops.hpp"
#include "byteswap.hpp" #include "byteswap.hpp"
#include "memops.hpp" #include "memops.hpp"
@ -15,3 +14,4 @@
#include "strops.hpp" #include "strops.hpp"
#include "string.hpp" #include "string.hpp"
#include "types.hpp" #include "types.hpp"
#include "vector.hpp"

View File

@ -13,28 +13,30 @@
namespace ox { namespace ox {
template<typename T> template<typename T>
class larray { class Vector {
private: private:
size_t m_size = 0; size_t m_size = 0;
T *m_items = nullptr; T *m_items = nullptr;
public: public:
larray() = default; Vector() = default;
explicit larray(size_t size); explicit Vector(size_t size);
larray(larray &other); Vector(Vector &other);
larray(larray &&other); Vector(Vector &&other);
~larray(); ~Vector();
size_t size() const; size_t size() const;
larray &operator=(larray &other); void resize(size_t size);
larray &operator=(larray &&other); Vector &operator=(Vector &other);
Vector &operator=(Vector &&other);
T &operator[](size_t i); T &operator[](size_t i);
@ -43,13 +45,13 @@ class larray {
}; };
template<typename T> template<typename T>
larray<T>::larray(size_t size) { Vector<T>::Vector(size_t size) {
m_size = size; m_size = size;
m_items = new T[m_size]; m_items = new T[m_size];
} }
template<typename T> template<typename T>
larray<T>::larray(larray<T> &other) { Vector<T>::Vector(Vector<T> &other) {
m_size = size; m_size = size;
m_items = new T[m_size]; m_items = new T[m_size];
for (size_t i = 0; i < m_size; i++) { for (size_t i = 0; i < m_size; i++) {
@ -58,7 +60,7 @@ larray<T>::larray(larray<T> &other) {
} }
template<typename T> template<typename T>
larray<T>::larray(larray<T> &&other) { Vector<T>::Vector(Vector<T> &&other) {
m_size = other.m_size; m_size = other.m_size;
m_items = other.m_items; m_items = other.m_items;
other.m_size = 0; other.m_size = 0;
@ -66,14 +68,16 @@ larray<T>::larray(larray<T> &&other) {
} }
template<typename T> template<typename T>
larray<T>::~larray() { Vector<T>::~Vector() {
if (m_items) { if (m_items) {
delete m_items; delete m_items;
m_items = nullptr;
} }
} }
template<typename T> template<typename T>
larray<T> &larray<T>::operator=(larray<T> &other) { Vector<T> &Vector<T>::operator=(Vector<T> &other) {
~Vector<T>();
m_size = size; m_size = size;
m_items = new T[m_size]; m_items = new T[m_size];
for (size_t i = 0; i < m_size; i++) { for (size_t i = 0; i < m_size; i++) {
@ -83,7 +87,8 @@ larray<T> &larray<T>::operator=(larray<T> &other) {
} }
template<typename T> template<typename T>
larray<T> &larray<T>::operator=(larray<T> &&other) { Vector<T> &Vector<T>::operator=(Vector<T> &&other) {
~Vector<T>();
m_size = other.m_size; m_size = other.m_size;
m_items = other.m_items; m_items = other.m_items;
other.m_size = 0; other.m_size = 0;
@ -92,17 +97,28 @@ larray<T> &larray<T>::operator=(larray<T> &&other) {
} }
template<typename T> template<typename T>
size_t larray<T>::size() const { size_t Vector<T>::size() const {
return m_size; return m_size;
}; };
template<typename T> template<typename T>
T &larray<T>::operator[](size_t i) { void Vector<T>::resize(size_t size) {
auto oldItems = m_items;
m_items = new T[size];
const auto itRange = size > m_size ? m_size : size;
for (size_t i = 0; i < itRange; i++) {
m_items[i] = oldItems[i];
}
m_size = size;
}
template<typename T>
T &Vector<T>::operator[](size_t i) {
return *(m_items[i]); return *(m_items[i]);
} }
template<typename T> template<typename T>
const T &larray<T>::operator[](size_t i) const { const T &Vector<T>::operator[](size_t i) const {
return *(m_items[i]); return *(m_items[i]);
} }