mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
byuu says: Changelog: - fixed bug in Emulator::Game::Memory::operator bool() - nall: renamed view<string> back to `string_view` - nall:: implemented `array_view` - Game Boy: split cartridge-specific input mappings (rumble, accelerometer) to their own separate ports - Game Boy: fixed MBC7 accelerometer x-axis - icarus: Game Boy, Super Famicom, Mega Drive cores output internal header game titles to heuristics manifests - higan, icarus, hiro/gtk: improve viewport geometry configuration; fixed higan crashing bug with XShm driver - higan: connect Video::poll(),update() functionality - hiro, ruby: several compilation / bugfixes, should get the macOS port compiling again, hopefully [Sintendo] - ruby/video/xshm: fix crashing bug on window resize - a bit hacky; it's throwing BadAccess Xlib warnings, but they're not fatal, so I am catching and ignoring them - bsnes: removed Application::Windows::onModalChange hook that's no longer needed [Screwtape]
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#pragma once
|
|
|
|
namespace nall {
|
|
|
|
struct string_pascal {
|
|
using type = string_pascal;
|
|
|
|
string_pascal(const char* text = nullptr) {
|
|
if(text && *text) {
|
|
uint size = strlen(text);
|
|
_data = memory::allocate<char>(sizeof(uint) + size + 1);
|
|
((uint*)_data)[0] = size;
|
|
memory::copy(_data + sizeof(uint), text, size);
|
|
_data[sizeof(uint) + size] = 0;
|
|
}
|
|
}
|
|
|
|
string_pascal(const string& text) {
|
|
if(text.size()) {
|
|
_data = memory::allocate<char>(sizeof(uint) + text.size() + 1);
|
|
((uint*)_data)[0] = text.size();
|
|
memory::copy(_data + sizeof(uint), text.data(), text.size());
|
|
_data[sizeof(uint) + text.size()] = 0;
|
|
}
|
|
}
|
|
|
|
string_pascal(const string_pascal& source) { operator=(source); }
|
|
string_pascal(string_pascal&& source) { operator=(move(source)); }
|
|
|
|
~string_pascal() {
|
|
if(_data) memory::free(_data);
|
|
}
|
|
|
|
explicit operator bool() const { return _data; }
|
|
operator const char*() const { return _data ? _data + sizeof(uint) : nullptr; }
|
|
operator string() const { return _data ? string{_data + sizeof(uint)} : ""; }
|
|
|
|
auto operator=(const string_pascal& source) -> type& {
|
|
if(this == &source) return *this;
|
|
if(_data) { memory::free(_data); _data = nullptr; }
|
|
if(source._data) {
|
|
uint size = source.size();
|
|
_data = memory::allocate<char>(sizeof(uint) + size);
|
|
memory::copy(_data, source._data, sizeof(uint) + size);
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
auto operator=(string_pascal&& source) -> type& {
|
|
if(this == &source) return *this;
|
|
if(_data) memory::free(_data);
|
|
_data = source._data;
|
|
source._data = nullptr;
|
|
return *this;
|
|
}
|
|
|
|
auto operator==(string_view source) const -> bool {
|
|
return size() == source.size() && memory::compare(data(), source.data(), size()) == 0;
|
|
}
|
|
|
|
auto operator!=(string_view source) const -> bool {
|
|
return size() != source.size() || memory::compare(data(), source.data(), size()) != 0;
|
|
}
|
|
|
|
auto data() const -> char* {
|
|
if(!_data) return nullptr;
|
|
return _data + sizeof(uint);
|
|
}
|
|
|
|
auto size() const -> uint {
|
|
if(!_data) return 0;
|
|
return ((uint*)_data)[0];
|
|
}
|
|
|
|
protected:
|
|
char* _data = nullptr;
|
|
};
|
|
|
|
}
|