[Teton] Load a font file and write a character to the screen.

This commit is contained in:
Drew Galbraith 2023-11-21 19:14:02 -08:00
parent 96063126cb
commit fe44804dd9
19 changed files with 412 additions and 17 deletions

View file

@ -6,6 +6,7 @@
#include "glacier/container/linked_list.h"
#include "glacier/container/pair.h"
#include "glacier/status/error.h"
#include "glacier/string/string.h"
namespace glcr {
@ -22,6 +23,18 @@ struct HashFunc<uint64_t> {
}
};
template <>
struct HashFunc<String> {
uint64_t operator()(const String& value) {
// FIXME: Write a real hash function.
uint64_t acc = 0;
for (uint64_t i = 0; i < value.length(); i++) {
acc += value[i];
}
return 0xABBAABBAABBAABBA ^ acc;
}
};
template <typename K, typename V, class H = HashFunc<K>>
class HashMap {
public:

View file

@ -28,6 +28,46 @@ String::String(const char* cstr, uint64_t str_len) : length_(str_len) {
String::String(StringView str) : String(str.data(), str.size()) {}
String::String(const String& other) : String(other.cstr_, other.length_) {}
String& String::operator=(const String& other) {
if (cstr_) {
delete cstr_;
}
length_ = other.length_;
cstr_ = new char[length_ + 1];
for (uint64_t i = 0; i < length_; i++) {
cstr_[i] = other.cstr_[i];
}
cstr_[length_] = '\0';
return *this;
}
String::String(String&& other) : cstr_(other.cstr_), length_(other.length_) {
other.cstr_ = nullptr;
other.length_ = 0;
}
String& String::operator=(String&& other) {
if (cstr_) {
delete cstr_;
}
cstr_ = other.cstr_;
length_ = other.length_;
other.cstr_ = nullptr;
other.length_ = 0;
return *this;
}
String::~String() {
if (cstr_) {
delete cstr_;
}
}
bool String::operator==(const String& other) {
if (other.length_ != length_) {
return false;

View file

@ -13,7 +13,12 @@ class String {
String(const char* cstr, uint64_t str_len);
String(StringView str);
String(const String&) = delete;
String(const String&);
String& operator=(const String&);
String(String&&);
String& operator=(String&&);
~String();
const char* cstr() const { return cstr_; }
uint64_t length() const { return length_; }