[ox] Add HashMap<String, T> to serializaton handlers
This commit is contained in:
26
deps/ox/src/ox/std/hashmap.hpp
vendored
26
deps/ox/src/ox/std/hashmap.hpp
vendored
@@ -16,6 +16,9 @@ namespace ox {
|
||||
template<typename K, typename T>
|
||||
class HashMap {
|
||||
|
||||
using key_t = K;
|
||||
using value_t = T;
|
||||
|
||||
private:
|
||||
struct Pair {
|
||||
K key = {};
|
||||
@@ -31,6 +34,8 @@ class HashMap {
|
||||
|
||||
~HashMap();
|
||||
|
||||
bool operator==(const HashMap &other) const;
|
||||
|
||||
HashMap &operator=(HashMap &other);
|
||||
|
||||
/**
|
||||
@@ -47,6 +52,8 @@ class HashMap {
|
||||
|
||||
std::size_t size() const noexcept;
|
||||
|
||||
const Vector<K> &keys() const noexcept;
|
||||
|
||||
private:
|
||||
void expand();
|
||||
|
||||
@@ -78,6 +85,20 @@ HashMap<K, T>::~HashMap() {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
bool HashMap<K, T>::operator==(const HashMap &other) const {
|
||||
if (m_keys != other.m_keys) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m_keys.size(); i++) {
|
||||
auto &k = m_keys[i];
|
||||
if (at(k) != other.at(k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &other) {
|
||||
this->~HashMap<K, T>();
|
||||
@@ -115,6 +136,11 @@ std::size_t HashMap<K, T>::size() const noexcept {
|
||||
return m_keys.size();
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
const Vector<K> &HashMap<K, T>::keys() const noexcept {
|
||||
return m_keys;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
void HashMap<K, T>::expand() {
|
||||
Vector<Pair*> r;
|
||||
|
2
deps/ox/src/ox/std/string.cpp
vendored
2
deps/ox/src/ox/std/string.cpp
vendored
@@ -39,7 +39,7 @@ String::String(const char *str, std::size_t size) noexcept {
|
||||
m_buff[size] = 0;
|
||||
}
|
||||
|
||||
String::String(String &other) noexcept {
|
||||
String::String(const String &other) noexcept {
|
||||
m_buff = other.m_buff;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/string.hpp
vendored
2
deps/ox/src/ox/std/string.hpp
vendored
@@ -29,7 +29,7 @@ class String {
|
||||
|
||||
String(const char *str, std::size_t size) noexcept;
|
||||
|
||||
String(String&) noexcept;
|
||||
String(const String&) noexcept;
|
||||
|
||||
String(String&&) noexcept;
|
||||
|
||||
|
8
deps/ox/src/ox/std/vector.hpp
vendored
8
deps/ox/src/ox/std/vector.hpp
vendored
@@ -27,13 +27,13 @@ class Vector {
|
||||
|
||||
explicit Vector(std::size_t size) noexcept;
|
||||
|
||||
Vector(Vector &other) noexcept;
|
||||
Vector(const Vector &other) noexcept;
|
||||
|
||||
Vector(Vector &&other) noexcept;
|
||||
|
||||
~Vector() noexcept;
|
||||
|
||||
Vector &operator=(Vector &other) noexcept;
|
||||
Vector &operator=(const Vector &other) noexcept;
|
||||
|
||||
Vector &operator=(Vector &&other) noexcept;
|
||||
|
||||
@@ -97,7 +97,7 @@ Vector<T>::Vector(std::size_t size) noexcept {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vector<T>::Vector(Vector<T> &other) noexcept {
|
||||
Vector<T>::Vector(const Vector<T> &other) noexcept {
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
m_items = reinterpret_cast<T*>(new AllocAlias<T>[m_cap]);
|
||||
@@ -128,7 +128,7 @@ Vector<T>::~Vector() noexcept {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vector<T> &Vector<T>::operator=(Vector<T> &other) noexcept {
|
||||
Vector<T> &Vector<T>::operator=(const Vector<T> &other) noexcept {
|
||||
this->~Vector<T>();
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
|
Reference in New Issue
Block a user