mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-23 03:15:58 -04:00
Add msvcstl (#81)
* implement gd::string for windows Co-authored-by: matcool <26722564+matcool@users.noreply.github.com>
This commit is contained in:
parent
2034b3e62d
commit
9a51843727
7 changed files with 51 additions and 49 deletions
bindings
cmake
codegen/src
loader/include
|
@ -2,7 +2,6 @@
|
|||
// clang-format off
|
||||
class GDString {
|
||||
void winDtor() = win 0xf6e0;
|
||||
char const* winCStr() = win 0xf710;
|
||||
GDString& winAssign(GDString const&, size_t, size_t) = win 0xf720;
|
||||
GDString& winAssign(char const*) = win 0xf680;
|
||||
GDString& winAssign(char const*, size_t) = win 0xf840;
|
||||
|
|
|
@ -64,6 +64,7 @@ elseif (GEODE_TARGET_PLATFORM STREQUAL "Win32")
|
|||
${GEODE_LOADER_PATH}/include/link/libcocos2d.lib
|
||||
${GEODE_LOADER_PATH}/include/link/libExtensions.lib
|
||||
${GEODE_LOADER_PATH}/include/link/libcurl.lib
|
||||
${GEODE_LOADER_PATH}/include/link/gdstring.lib
|
||||
)
|
||||
|
||||
# Windows links against .lib and not .dll
|
||||
|
|
|
@ -76,7 +76,11 @@ std::string generateBindingHeader(Root& root, ghc::filesystem::path const& singl
|
|||
);
|
||||
|
||||
std::string single_output;
|
||||
single_output += format_strings::class_includes;
|
||||
if (cls.name != "GDString") {
|
||||
single_output += format_strings::class_includes;
|
||||
} else {
|
||||
single_output += "#pragma once\n#include <Geode/platform/platform.hpp>\n";
|
||||
}
|
||||
|
||||
for (auto dep : cls.depends) {
|
||||
if (can_find(dep, "cocos2d::")) continue;
|
||||
|
|
|
@ -1,2 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/platform/platform.hpp>
|
||||
|
||||
#if defined(GEODE_IS_WINDOWS)
|
||||
#include "msvcstl.hpp"
|
||||
#else
|
||||
#include "gnustl.hpp"
|
||||
// #include "msvcstl.hpp"
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/platform/platform.hpp>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// #include <Geode/binding/GDString.hpp>
|
||||
|
||||
//#include "../utils/platform.hpp"
|
||||
#include <Geode/binding/GDString.hpp>
|
||||
|
||||
namespace geode::base {
|
||||
uintptr_t get();
|
||||
|
@ -570,6 +566,4 @@ namespace gd {
|
|||
~map() {}
|
||||
};
|
||||
}
|
||||
#else
|
||||
namespace gd = std;
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/platform/platform.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <Geode/binding/GDString.hpp>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
// #include <Geode/binding/GDString.hpp>
|
||||
|
||||
#if defined(GEODE_IS_WINDOWS)
|
||||
|
||||
namespace gd {
|
||||
struct InternalString {
|
||||
|
@ -21,10 +18,20 @@ namespace gd {
|
|||
size_t m_capacity;
|
||||
};
|
||||
|
||||
class GEODE_DLL string : protected GDString {
|
||||
class string : GDString {
|
||||
private:
|
||||
InternalString m_data;
|
||||
|
||||
char* get_data() {
|
||||
if (m_data.m_capacity < 16) return m_data.m_storage;
|
||||
return m_data.m_pointer;
|
||||
}
|
||||
|
||||
const char* get_data() const {
|
||||
if (m_data.m_capacity < 16) return m_data.m_storage;
|
||||
return m_data.m_pointer;
|
||||
}
|
||||
|
||||
public:
|
||||
template <class... Params>
|
||||
string(Params&&... params) {
|
||||
|
@ -40,58 +47,48 @@ namespace gd {
|
|||
(void)this->winDtor();
|
||||
}
|
||||
|
||||
/*template <class... Params>
|
||||
decltype(auto) operator=(Params&&... params) ->
|
||||
decltype(this->operator=(std::forward<Params>(params)...)) { auto val =
|
||||
std::string(this->winCStr(), m_data.m_length);
|
||||
val.operator=(std::forward<Params>(params)...);
|
||||
(void)this->winAssign(val.c_str(), val.size());
|
||||
}*/
|
||||
|
||||
template <class... Params>
|
||||
string& operator=(Params&&... params) {
|
||||
auto val = std::string(this->winCStr(), m_data.m_length);
|
||||
val.operator=(std::forward<Params>(params)...);
|
||||
(void)this->winAssign(val.c_str(), val.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class... Params>
|
||||
string& assign(Params&&... params) {
|
||||
auto val = std::string(this->winCStr(), m_data.m_length);
|
||||
val.assign(std::forward<Params>(params)...);
|
||||
(void)this->winAssign(val.c_str(), val.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
char& at(size_t pos) {
|
||||
if (pos >= m_data.m_length) throw std::out_of_range("gd::string::at");
|
||||
return (*this)[pos];
|
||||
}
|
||||
|
||||
char const& at(size_t pos) const {
|
||||
if (pos >= m_data.m_length) throw std::out_of_range("gd::string::at");
|
||||
return (*this)[pos];
|
||||
}
|
||||
|
||||
char& operator[](size_t pos) {
|
||||
return this->winCStr()[pos];
|
||||
return this->get_data()[pos];
|
||||
}
|
||||
|
||||
char const& operator[](size_t pos) const {
|
||||
return this->winCStr()[pos];
|
||||
return this->get_data()[pos];
|
||||
}
|
||||
|
||||
char* data() {
|
||||
return this->winCStr();
|
||||
return this->get_data();
|
||||
}
|
||||
|
||||
char const* data() const {
|
||||
return this->winCStr();
|
||||
return this->get_data();
|
||||
}
|
||||
|
||||
char const* c_str() const {
|
||||
return this->winCStr();
|
||||
return this->get_data();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return m_data.m_length;
|
||||
}
|
||||
|
||||
operator std::string() const {
|
||||
return std::string(this->c_str(), this->size());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
template <class T>
|
||||
using vector = std::vector<T>;
|
||||
|
||||
template <class K, class V>
|
||||
using map = std::map<K, V>;
|
||||
}
|
||||
|
|
BIN
loader/include/link/gdstring.lib
Normal file
BIN
loader/include/link/gdstring.lib
Normal file
Binary file not shown.
Loading…
Reference in a new issue