diff --git a/hecl/CMakeLists.txt b/hecl/CMakeLists.txt index fd3cf2d2b..819b71d6a 100644 --- a/hecl/CMakeLists.txt +++ b/hecl/CMakeLists.txt @@ -2,7 +2,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDARD project(hecl) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(MSVC) diff --git a/hecl/driver/ToolCook.hpp b/hecl/driver/ToolCook.hpp index 94a52676d..47a92f331 100644 --- a/hecl/driver/ToolCook.hpp +++ b/hecl/driver/ToolCook.hpp @@ -51,8 +51,8 @@ public: LogModule.report(logvisor::Fatal, _S("hecl cook can only process multiple items in the same project; ") _S("'%s' and '%s' are different projects"), - m_fallbackProj->getProjectRootPath().getAbsolutePath().c_str(), - root.getAbsolutePath().c_str()); + m_fallbackProj->getProjectRootPath().getAbsolutePath().data(), + root.getAbsolutePath().data()); m_selectedItems.emplace_back(*m_useProj, subPath); } } diff --git a/hecl/driver/ToolExtract.hpp b/hecl/driver/ToolExtract.hpp index 5d9210da8..3444930e0 100644 --- a/hecl/driver/ToolExtract.hpp +++ b/hecl/driver/ToolExtract.hpp @@ -159,9 +159,9 @@ public: for (SpecExtractPass& ds : m_specPasses) { if (XTERM_COLOR) - hecl::Printf(_S("" MAGENTA BOLD "Using DataSpec %s:" NORMAL "\n"), ds.m_entry->m_name); + hecl::Printf(_S("" MAGENTA BOLD "Using DataSpec %s:" NORMAL "\n"), ds.m_entry->m_name.data()); else - hecl::Printf(_S("Using DataSpec %s:\n"), ds.m_entry->m_name); + hecl::Printf(_S("Using DataSpec %s:\n"), ds.m_entry->m_name.data()); int lineIdx = 0; ds.m_instance->doExtract(m_einfo, diff --git a/hecl/driver/ToolPackage.hpp b/hecl/driver/ToolPackage.hpp index 013b8393e..02a8770b5 100644 --- a/hecl/driver/ToolPackage.hpp +++ b/hecl/driver/ToolPackage.hpp @@ -23,9 +23,9 @@ class ToolPackage final : public ToolBase void CheckFile(const hecl::ProjectPath& path) { - if (!hecl::StrCmp(path.getLastComponent(), _S("!world.blend"))) + if (!hecl::StrCmp(path.getLastComponent().data(), _S("!world.blend"))) AddSelectedItem(path); - else if (!hecl::StrCmp(path.getLastComponent(), _S("!original_ids.yaml"))) + else if (!hecl::StrCmp(path.getLastComponent().data(), _S("!original_ids.yaml"))) { auto pathComps = path.getPathComponents(); if (pathComps.size() == 2 && pathComps[0] != _S("out")) @@ -100,8 +100,8 @@ public: LogModule.report(logvisor::Fatal, _S("hecl package can only process multiple items in the same project; ") _S("'%s' and '%s' are different projects"), - m_fallbackProj->getProjectRootPath().getAbsolutePath().c_str(), - root.getAbsolutePath().c_str()); + m_fallbackProj->getProjectRootPath().getAbsolutePath().data(), + root.getAbsolutePath().data()); FindSelectedItems({*m_useProj, subPath}, true); } @@ -172,7 +172,7 @@ public: hecl::Printf(_S("ABOUT TO PACKAGE:\n")); for (auto& item : m_selectedItems) - hecl::Printf(_S("%s\n"), item.getRelativePath().c_str()); + hecl::Printf(_S("%s\n"), item.getRelativePath().data()); if (continuePrompt()) { @@ -180,7 +180,7 @@ public: for (const hecl::ProjectPath& path : m_selectedItems) { if (!m_useProj->packagePath(path, {}, m_fast, &cp)) - LogModule.report(logvisor::Error, _S("Unable to package %s"), path.getAbsolutePath().c_str()); + LogModule.report(logvisor::Error, _S("Unable to package %s"), path.getAbsolutePath().data()); } cp.waitUntilComplete(); } diff --git a/hecl/driver/ToolSpec.hpp b/hecl/driver/ToolSpec.hpp index 3fe7d1cae..49014e5b6 100644 --- a/hecl/driver/ToolSpec.hpp +++ b/hecl/driver/ToolSpec.hpp @@ -95,10 +95,10 @@ public: for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { if (XTERM_COLOR) - hecl::Printf(_S("" BOLD CYAN "%s" NORMAL "\n"), spec->m_name); + hecl::Printf(_S("" BOLD CYAN "%s" NORMAL "\n"), spec->m_name.data()); else - hecl::Printf(_S("%s\n"), spec->m_name); - hecl::Printf(_S(" %s\n"), spec->m_desc); + hecl::Printf(_S("%s\n"), spec->m_name.data()); + hecl::Printf(_S(" %s\n"), spec->m_desc.data()); } return 0; } @@ -109,9 +109,9 @@ public: for (auto& spec : specs) { if (XTERM_COLOR) - hecl::Printf(_S("" BOLD CYAN "%s" NORMAL ""), spec.spec.m_name); + hecl::Printf(_S("" BOLD CYAN "%s" NORMAL ""), spec.spec.m_name.data()); else - hecl::Printf(_S("%s"), spec.spec.m_name); + hecl::Printf(_S("%s"), spec.spec.m_name.data()); if (spec.active) { if (XTERM_COLOR) @@ -119,7 +119,7 @@ public: else hecl::Printf(_S(" [ENABLED]")); } - hecl::Printf(_S("\n %s\n"), spec.spec.m_desc); + hecl::Printf(_S("\n %s\n"), spec.spec.m_desc.data()); } return 0; } @@ -137,7 +137,7 @@ public: hecl::ToLower(compName); if (!itName.compare(compName)) { - opSpecs.push_back(spec.spec.m_name); + opSpecs.emplace_back(spec.spec.m_name); break; } } diff --git a/hecl/extern/athena b/hecl/extern/athena index b55f26513..f5dabee0a 160000 --- a/hecl/extern/athena +++ b/hecl/extern/athena @@ -1 +1 @@ -Subproject commit b55f26513179f4c5ea57f788c9e491f429be521b +Subproject commit f5dabee0a785d30476937296e999db442f1005f9 diff --git a/hecl/extern/boo b/hecl/extern/boo index 420dcee55..cb5d22eed 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 420dcee55234c718f757cb6370bbef4779bc4470 +Subproject commit cb5d22eed61f6de468e3e3bc718c705b398b6c65 diff --git a/hecl/include/hecl/Blender/BlenderConnection.hpp b/hecl/include/hecl/Blender/BlenderConnection.hpp index 6d41ba242..718a9bb17 100644 --- a/hecl/include/hecl/Blender/BlenderConnection.hpp +++ b/hecl/include/hecl/Blender/BlenderConnection.hpp @@ -26,7 +26,7 @@ #include "hecl/HMDLMeta.hpp" #include #include -#include +#include "optional.hpp" namespace hecl { @@ -389,7 +389,7 @@ public: if (m_parent->m_loadedType != BlendType::Mesh && m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not a MESH or ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("MESHAABB"); char readBuf[256]; @@ -786,11 +786,11 @@ public: Mesh::SurfProgFunc surfProg=[](int){}); /** Compile mesh by name (AREA blends only) */ - Mesh compileMesh(const std::string& name, HMDLTopology topology, int skinSlotCount=10, + Mesh compileMesh(std::string_view name, HMDLTopology topology, int skinSlotCount=10, Mesh::SurfProgFunc surfProg=[](int){}); /** Compile collision mesh by name (AREA blends only) */ - ColMesh compileColMesh(const std::string& name); + ColMesh compileColMesh(std::string_view name); /** Compile all meshes as collision meshes (CMESH blends only) */ std::vector compileColMeshes(); @@ -806,7 +806,7 @@ public: std::vector compileLights(); /** Compile GUI into FRME data (FRAME blends only) */ - void compileGuiFrame(const std::string& pathOut, int version); + void compileGuiFrame(std::string_view pathOut, int version); /** Gather all texture paths in scene */ std::vector getTextures(); @@ -901,11 +901,11 @@ public: Actor compileActor(); Actor compileActorCharacterOnly(); - Actor::Action compileActionChannelsOnly(const std::string& name); + Actor::Action compileActionChannelsOnly(std::string_view name); std::vector getArmatureNames(); std::vector getSubtypeNames(); std::vector getActionNames(); - std::vector getSubtypeOverlayNames(const std::string& name); + std::vector getSubtypeOverlayNames(std::string_view name); struct Matrix3f { @@ -913,10 +913,10 @@ public: inline atVec3f& operator[](size_t idx) {return m[idx];} inline const atVec3f& operator[](size_t idx) const {return m[idx];} }; - std::unordered_map getBoneMatrices(const std::string& name); + std::unordered_map getBoneMatrices(std::string_view name); - bool renderPvs(const std::string& path, const atVec3f& location); - bool renderPvsLight(const std::string& path, const std::string& lightName); + bool renderPvs(std::string_view path, const atVec3f& location); + bool renderPvsLight(std::string_view path, std::string_view lightName); MapArea compileMapArea(); MapUniverse compileMapUniverse(); diff --git a/hecl/include/hecl/CVar.hpp b/hecl/include/hecl/CVar.hpp index 636e153e6..d93e749c6 100755 --- a/hecl/include/hecl/CVar.hpp +++ b/hecl/include/hecl/CVar.hpp @@ -66,16 +66,16 @@ public: using EType = DNACVAR::EType; using EFlags = DNACVAR::EFlags; - CVar(const std::string& name, const std::string& value, const std::string& help, EType type, EFlags flags, CVarManager& parent); - CVar(const std::string& name, const std::string& value, const std::string& help, EFlags flags, CVarManager& parent); - CVar(const std::string& name, float value, const std::string& help, EFlags flags, CVarManager& parent); - CVar(const std::string& name, bool value, const std::string& help, EFlags flags, CVarManager& parent); - CVar(const std::string& name, int value, const std::string& help, EFlags flags, CVarManager& parent); - CVar(const std::string& name, const atVec4f& value, const std::string& help, EFlags flags, CVarManager& parent); + CVar(std::string_view name, std::string_view value, std::string_view help, EType type, EFlags flags, CVarManager& parent); + CVar(std::string_view name, std::string_view value, std::string_view help, EFlags flags, CVarManager& parent); + CVar(std::string_view name, float value, std::string_view help, EFlags flags, CVarManager& parent); + CVar(std::string_view name, bool value, std::string_view help, EFlags flags, CVarManager& parent); + CVar(std::string_view name, int value, std::string_view help, EFlags flags, CVarManager& parent); + CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags, CVarManager& parent); - const std::string& name() const { return m_name; } - const std::string& rawHelp() const { return m_help; } + std::string_view name() const { return m_name; } + std::string_view rawHelp() const { return m_help; } std::string help() const; atVec4f toVec4f(bool* isValid = nullptr) const; @@ -89,8 +89,8 @@ public: bool fromFloat(float val); bool fromBoolean(bool val); bool fromInteger(int val); - bool fromLiteral(const std::string& val); - bool fromLiteral(const std::wstring& val); + bool fromLiteral(std::string_view val); + bool fromLiteral(std::wstring_view val); bool isFloat() const { return m_type == EType::Float; } bool isBoolean() const { return m_type == EType::Boolean; } diff --git a/hecl/include/hecl/CVarManager.hpp b/hecl/include/hecl/CVarManager.hpp index 83870b626..2133e31cd 100755 --- a/hecl/include/hecl/CVarManager.hpp +++ b/hecl/include/hecl/CVarManager.hpp @@ -16,7 +16,7 @@ class CVarManager final { using CVarContainer = DNACVAR::CVarContainer; template - CVar* _newCVar(const std::string& name, const std::string& help, const T& value, CVar::EFlags flags) + CVar* _newCVar(std::string_view name, std::string_view help, const T& value, CVar::EFlags flags) { CVar* ret(new CVar(name, value, help, flags, *this)); if (registerCVar(ret)) @@ -41,20 +41,20 @@ public: ~CVarManager(); void update(); - CVar* newCVar(const std::string& name, const std::string& help, const atVec4f& value, CVar::EFlags flags) + CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags) { return _newCVar(name, help, value, flags); } - CVar* newCVar(const std::string& name, const std::string& help, const std::string& value, CVar::EFlags flags) - { return _newCVar(name, help, value, flags); } - CVar* newCVar(const std::string& name, const std::string& help, bool value, CVar::EFlags flags) + CVar* newCVar(std::string_view name, std::string_view help, std::string_view value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, bool value, CVar::EFlags flags) { return _newCVar(name, help, value, flags); } - CVar* newCVar(const std::string& name, const std::string& help, float value, CVar::EFlags flags) + CVar* newCVar(std::string_view name, std::string_view help, float value, CVar::EFlags flags) { return _newCVar(name, help, value, flags); } - CVar* newCVar(const std::string& name, const std::string& help, int value, CVar::EFlags flags) + CVar* newCVar(std::string_view name, std::string_view help, int value, CVar::EFlags flags) { return _newCVar(name, help, value, flags); } bool registerCVar(CVar* cvar); - CVar* findCVar(std::string name); + CVar* findCVar(std::string_view name); std::vector archivedCVars() const; std::vector cvars() const; diff --git a/hecl/include/hecl/Database.hpp b/hecl/include/hecl/Database.hpp index 6248a5221..38628bd90 100644 --- a/hecl/include/hecl/Database.hpp +++ b/hecl/include/hecl/Database.hpp @@ -145,11 +145,11 @@ extern std::vector DATA_SPEC_REGISTRY; */ struct DataSpecEntry { - const SystemChar* m_name; - const SystemChar* m_desc; + SystemStringView m_name; + SystemStringView m_desc; std::function m_factory; - DataSpecEntry(const SystemChar* name, const SystemChar* desc, + DataSpecEntry(SystemStringView name, SystemStringView desc, std::function&& factory) : m_name(name), m_desc(desc), m_factory(std::move(factory)) {} }; @@ -228,10 +228,10 @@ protected: {return FourCC("NULL");} public: - ObjectBase(const SystemString& path) + ObjectBase(SystemStringView path) : m_path(path) {} - const SystemString& getPath() const {return m_path;} + SystemStringView getPath() const {return m_path;} }; @@ -278,12 +278,12 @@ public: std::vector m_lines; FILE* m_lockedFile = NULL; public: - ConfigFile(const Project& project, const SystemString& name, - const SystemString& subdir=_S("/.hecl/")); + ConfigFile(const Project& project, SystemStringView name, + SystemStringView subdir=_S("/.hecl/")); std::vector& lockAndRead(); - void addLine(const std::string& line); - void removeLine(const std::string& refLine); - bool checkForLine(const std::string& refLine); + void addLine(std::string_view line); + void removeLine(std::string_view refLine); + bool checkForLine(std::string_view refLine); void unlockAndDiscard(); bool unlockAndCommit(); }; diff --git a/hecl/include/hecl/Frontend.hpp b/hecl/include/hecl/Frontend.hpp index ff2cd944d..010f2bae3 100644 --- a/hecl/include/hecl/Frontend.hpp +++ b/hecl/include/hecl/Frontend.hpp @@ -29,17 +29,16 @@ class Diagnostics std::string m_backend = "Backend"; std::string sourceDiagString(const SourceLocation& l, bool ansi=false) const; public: - void reset(const std::string& name, const std::string& source) {m_name = name; m_source = source;} - void reset(const std::string& name) {m_name = name; m_source.clear();} - void setBackend(const std::string& backend) {m_backend = backend;} - void setBackend(const char* backend) {m_backend = backend;} + void reset(std::string_view name, std::string_view source) {m_name = name; m_source = source;} + void reset(std::string_view name) {m_name = name; m_source.clear();} + void setBackend(std::string_view backend) {m_backend = backend;} void reportParserErr(const SourceLocation& l, const char* format, ...); void reportLexerErr(const SourceLocation& l, const char* format, ...); void reportCompileErr(const SourceLocation& l, const char* format, ...); void reportBackendErr(const SourceLocation& l, const char* format, ...); - const std::string& getName() const {return m_name;} - const std::string& getSource() const {return m_source;} + std::string_view getName() const {return m_name;} + std::string_view getSource() const {return m_source;} }; class Parser @@ -61,11 +60,11 @@ public: }; private: Diagnostics& m_diag; - const std::string* m_source = nullptr; - std::string::const_iterator m_sourceIt; + std::string_view m_source; + std::string_view::const_iterator m_sourceIt; std::vector m_parenStack; bool m_reset = false; - void skipWhitespace(std::string::const_iterator& it); + void skipWhitespace(std::string_view::const_iterator& it); public: struct Token { @@ -107,7 +106,7 @@ public: return nullptr; } }; - void reset(const std::string& source); + void reset(std::string_view source); Token consumeToken(); SourceLocation getLocation() const; @@ -399,7 +398,7 @@ class Frontend Parser m_parser; Lexer m_lexer; public: - IR compileSource(const std::string& source, const std::string& diagName) + IR compileSource(std::string_view source, std::string_view diagName) { Hash hash(source); m_diag.reset(diagName, source); diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index 88b987d25..783e71e28 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -24,13 +24,13 @@ class FileStoreManager SystemString m_domain; SystemString m_storeRoot; public: - FileStoreManager(const SystemString& domain); - const SystemString& getDomain() const {return m_domain;} + FileStoreManager(SystemStringView domain); + SystemStringView getDomain() const {return m_domain;} /** * @brief Returns the full path to the file store, including domain * @return Full path to store e.g /home/foo/.hecl/bar */ - const SystemString& getStoreRoot() const {return m_storeRoot;} + SystemStringView getStoreRoot() const {return m_storeRoot;} }; /** @@ -57,7 +57,7 @@ class ShaderTag : public Hash }; public: ShaderTag() = default; - ShaderTag(const std::string& source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, uint8_t t, boo::Primitive pt, + ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, uint8_t t, boo::Primitive pt, Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling) : Hash(source), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s), m_texMtxCount(t), m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)), @@ -273,17 +273,17 @@ public: * for encoding the pipeline state. This must be called before building shaders */ void setRenderTargetSamples(unsigned samps) {m_factory->m_rtHint = samps;} - std::shared_ptr buildShader(const ShaderTag& tag, const std::string& source, - const std::string& diagName, + std::shared_ptr buildShader(const ShaderTag& tag, std::string_view source, + std::string_view diagName, boo::IGraphicsDataFactory& factory); std::shared_ptr buildShader(const ShaderTag& tag, const hecl::Frontend::IR& ir, - const std::string& diagName, + std::string_view diagName, boo::IGraphicsDataFactory& factory); - std::shared_ptr buildExtendedShader(const ShaderTag& tag, const std::string& source, - const std::string& diagName, + std::shared_ptr buildExtendedShader(const ShaderTag& tag, std::string_view source, + std::string_view diagName, boo::IGraphicsDataFactory& factory); std::shared_ptr buildExtendedShader(const ShaderTag& tag, const hecl::Frontend::IR& ir, - const std::string& diagName, + std::string_view diagName, boo::IGraphicsDataFactory& factory); }; diff --git a/hecl/include/hecl/SystemChar.hpp b/hecl/include/hecl/SystemChar.hpp index 9bdeb7ec4..daa45d5a0 100644 --- a/hecl/include/hecl/SystemChar.hpp +++ b/hecl/include/hecl/SystemChar.hpp @@ -15,7 +15,8 @@ #include #endif #include -#include +#include +#include #include namespace hecl @@ -29,6 +30,7 @@ namespace hecl typedef wchar_t SystemChar; static inline size_t StrLen(const SystemChar* str) {return wcslen(str);} typedef std::wstring SystemString; +typedef std::wstring_view SystemStringView; static inline void ToLower(SystemString& str) {std::transform(str.begin(), str.end(), str.begin(), towlower);} static inline void ToUpper(SystemString& str) @@ -41,6 +43,7 @@ typedef struct _stat Sstat; typedef char SystemChar; static inline size_t StrLen(const SystemChar* str) {return strlen(str);} typedef std::string SystemString; +typedef std::string_view SystemStringView; static inline void ToLower(SystemString& str) {std::transform(str.begin(), str.end(), str.begin(), tolower);} static inline void ToUpper(SystemString& str) diff --git a/hecl/include/hecl/hecl.hpp b/hecl/include/hecl/hecl.hpp index 2b76ccf9d..3b8ce9f85 100644 --- a/hecl/include/hecl/hecl.hpp +++ b/hecl/include/hecl/hecl.hpp @@ -49,11 +49,11 @@ struct DataSpecEntry; extern unsigned VerbosityLevel; extern logvisor::Module LogModule; -std::string WideToUTF8(const std::wstring& src); -std::string Char16ToUTF8(const std::u16string& src); -std::wstring Char16ToWide(const std::u16string& src); -std::wstring UTF8ToWide(const std::string& src); -std::u16string UTF8ToChar16(const std::string& src); +std::string WideToUTF8(std::wstring_view src); +std::string Char16ToUTF8(std::u16string_view src); +std::wstring Char16ToWide(std::u16string_view src); +std::wstring UTF8ToWide(std::string_view src); +std::u16string UTF8ToChar16(std::string_view src); /* humanize_number port from FreeBSD's libutil */ enum class HNFlags @@ -77,63 +77,51 @@ ENABLE_BITWISE_ENUM(HNScale) std::string HumanizeNumber(int64_t quotient, size_t len, const char* suffix, int scale, HNFlags flags); #if HECL_UCS2 -class SystemUTF8View +class SystemUTF8Conv { std::string m_utf8; public: - explicit SystemUTF8View(const SystemString& str) + explicit SystemUTF8Conv(SystemStringView str) : m_utf8(WideToUTF8(str)) {} - operator const std::string&() const {return m_utf8;} - const std::string& str() const {return m_utf8;} + std::string_view str() const {return m_utf8;} const char* c_str() const {return m_utf8.c_str();} - std::string operator+(const std::string& other) const {return m_utf8 + other;} - std::string operator+(const char* other) const {return m_utf8 + other;} + std::string operator+(std::string_view other) const {return m_utf8 + other;} }; -inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);} -inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);} -class SystemStringView +inline std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) {return lhs + std::string(rhs);} +class SystemStringConv { std::wstring m_sys; public: - explicit SystemStringView(const std::string& str) + explicit SystemStringConv(std::string_view str) : m_sys(UTF8ToWide(str)) {} - operator const std::wstring&() const {return m_sys;} - const std::wstring& sys_str() const {return m_sys;} + SystemStringView sys_str() const {return m_sys;} const SystemChar* c_str() const {return m_sys.c_str();} - std::wstring operator+(const std::wstring& other) const {return m_sys + other;} - std::wstring operator+(const wchar_t* other) const {return m_sys + other;} + std::wstring operator+(const std::wstring_view other) const {return m_sys + other;} }; -inline std::wstring operator+(const std::wstring& lhs, const SystemStringView& rhs) {return lhs + std::wstring(rhs);} -inline std::wstring operator+(const wchar_t* lhs, const SystemStringView& rhs) {return lhs + std::wstring(rhs);} +inline std::wstring operator+(std::wstring_view lhs, const SystemStringConv& rhs) {return lhs + std::wstring(rhs);} #else -class SystemUTF8View +class SystemUTF8Conv { - const std::string& m_utf8; + std::string_view m_utf8; public: - explicit SystemUTF8View(const SystemString& str) + explicit SystemUTF8Conv(SystemStringView str) : m_utf8(str) {} - operator const std::string&() const {return m_utf8;} - const std::string& str() const {return m_utf8;} - const char* c_str() const {return m_utf8.c_str();} - std::string operator+(const std::string& other) const {return std::string(m_utf8) + other;} - std::string operator+(const char* other) const {return std::string(m_utf8) + other;} + std::string_view str() const {return m_utf8;} + const char* c_str() const {return m_utf8.data();} + std::string operator+(std::string_view other) const {return std::string(m_utf8) + other.data();} }; -inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);} -inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);} -class SystemStringView +inline std::string operator+(std::string_view lhs, const SystemUTF8Conv& rhs) {return std::string(lhs) + rhs.c_str();} +class SystemStringConv { - const std::string& m_sys; + std::string_view m_sys; public: - explicit SystemStringView(const std::string& str) + explicit SystemStringConv(std::string_view str) : m_sys(str) {} - operator const std::string&() const {return m_sys;} - const std::string& sys_str() const {return m_sys;} - const SystemChar* c_str() const {return m_sys.c_str();} - std::string operator+(const std::string& other) const {return m_sys + other;} - std::string operator+(const char* other) const {return m_sys + other;} + SystemStringView sys_str() const {return m_sys;} + const SystemChar* c_str() const {return m_sys.data();} + std::string operator+(std::string_view other) const {return std::string(m_sys) + other.data();} }; -inline std::string operator+(const std::string& lhs, const SystemStringView& rhs) {return lhs + std::string(rhs);} -inline std::string operator+(const char* lhs, const SystemStringView& rhs) {return lhs + std::string(rhs);} +inline std::string operator+(std::string_view lhs, const SystemStringConv& rhs) {return std::string(lhs) + rhs.c_str();} #endif void SanitizePath(std::string& path); @@ -226,7 +214,7 @@ static SystemString GetcwdStr() return SystemString(); } -static inline bool IsAbsolute(const SystemString& path) +static inline bool IsAbsolute(SystemStringView path) { #if _WIN32 if (path.size() && (path[0] == _S('\\') || path[0] == _S('/'))) @@ -532,9 +520,9 @@ public: operator bool() const {return hash != 0;} Hash(const void* buf, size_t len) : hash(XXH64((uint8_t*)buf, len, 0)) {} - Hash(const std::string& str) + Hash(std::string_view str) : hash(XXH64((uint8_t*)str.data(), str.size(), 0)) {} - Hash(const std::wstring& str) + Hash(std::wstring_view str) : hash(XXH64((uint8_t*)str.data(), str.size()*2, 0)) {} Hash(uint64_t hashin) : hash(hashin) {} @@ -576,21 +564,21 @@ public: */ struct CaseInsensitiveCompare { - bool operator()(const std::string& lhs, const std::string& rhs) const + bool operator()(std::string_view lhs, std::string_view rhs) const { #if _WIN32 - if (_stricmp(lhs.c_str(), rhs.c_str()) < 0) + if (_stricmp(lhs.data(), rhs.data()) < 0) #else - if (strcasecmp(lhs.c_str(), rhs.c_str()) < 0) + if (strcasecmp(lhs.data(), rhs.data()) < 0) #endif return true; return false; } #if _WIN32 - bool operator()(const std::wstring& lhs, const std::wstring& rhs) const + bool operator()(std::wstring_view lhs, std::wstring_view rhs) const { - if (_wcsicmp(lhs.c_str(), rhs.c_str()) < 0) + if (_wcsicmp(lhs.data(), rhs.data()) < 0) return true; return false; } @@ -627,10 +615,7 @@ private: std::vector m_entries; public: - DirectoryEnumerator(const hecl::SystemString& path, Mode mode=Mode::DirsThenFilesSorted, - bool sizeSort=false, bool reverse=false, bool noHidden=false) - : DirectoryEnumerator(path.c_str(), mode, sizeSort, reverse, noHidden) {} - DirectoryEnumerator(const hecl::SystemChar* path, Mode mode=Mode::DirsThenFilesSorted, + DirectoryEnumerator(SystemStringView path, Mode mode=Mode::DirsThenFilesSorted, bool sizeSort=false, bool reverse=false, bool noHidden=false); operator bool() const {return m_entries.size() != 0;} @@ -671,7 +656,7 @@ public: * @brief Construct a representation of a project root path * @param path valid filesystem-path (relative or absolute) to project root */ - ProjectRootPath(const SystemString& path) : m_projRoot(path) + ProjectRootPath(SystemStringView path) : m_projRoot(path) { SanitizePath(m_projRoot); m_hash = Hash(m_projRoot); @@ -681,14 +666,14 @@ public: * @brief Access fully-canonicalized absolute path * @return Absolute path reference */ - const SystemString& getAbsolutePath() const {return m_projRoot;} + SystemStringView getAbsolutePath() const {return m_projRoot;} /** * @brief Make absolute path project relative * @param absPath Absolute path * @return SystemString of path relative to project root */ - SystemString getProjectRelativeFromAbsolute(const SystemString& absPath) const + SystemString getProjectRelativeFromAbsolute(SystemStringView absPath) const { if (absPath.size() > m_projRoot.size()) { @@ -705,7 +690,7 @@ public: } } LogModule.report(logvisor::Fatal, "unable to resolve '%s' as project relative '%s'", - absPath.c_str(), m_projRoot.c_str()); + absPath.data(), m_projRoot.c_str()); return SystemString(); } @@ -729,12 +714,12 @@ public: * @brief Obtain c-string of final path component * @return Final component c-string (may be empty) */ - const SystemChar* getLastComponent() const + SystemStringView getLastComponent() const { size_t pos = m_projRoot.rfind(_S('/')); if (pos == SystemString::npos) - return m_projRoot.c_str() + m_projRoot.size(); - return m_projRoot.c_str() + pos + 1; + return {}; + return {m_projRoot.c_str() + pos + 1, size_t(m_projRoot.size() - pos - 1)}; } }; @@ -813,12 +798,12 @@ public: * @param project previously constructed Project to use root path of * @param path valid filesystem-path (relative or absolute) to subpath */ - ProjectPath(Database::Project& project, const SystemString& path) {assign(project, path);} - void assign(Database::Project& project, const SystemString& path); + ProjectPath(Database::Project& project, SystemStringView path) {assign(project, path);} + void assign(Database::Project& project, SystemStringView path); #if HECL_UCS2 - ProjectPath(Database::Project& project, const std::string& path) {assign(project, path);} - void assign(Database::Project& project, const std::string& path); + ProjectPath(Database::Project& project, std::string_view path) {assign(project, path);} + void assign(Database::Project& project, std::string_view path); #endif /** @@ -826,12 +811,12 @@ public: * @param parentPath previously constructed ProjectPath which ultimately connects to a ProjectRootPath * @param path valid filesystem-path (relative or absolute) to subpath */ - ProjectPath(const ProjectPath& parentPath, const SystemString& path) {assign(parentPath, path);} - void assign(const ProjectPath& parentPath, const SystemString& path); + ProjectPath(const ProjectPath& parentPath, SystemStringView path) {assign(parentPath, path);} + void assign(const ProjectPath& parentPath, SystemStringView path); #if HECL_UCS2 - ProjectPath(const ProjectPath& parentPath, const std::string& path) {assign(parentPath, path);} - void assign(const ProjectPath& parentPath, const std::string& path); + ProjectPath(const ProjectPath& parentPath, std::string_view path) {assign(parentPath, path);} + void assign(const ProjectPath& parentPath, std::string_view path); #endif /** @@ -882,13 +867,13 @@ public: * @brief Access fully-canonicalized absolute path * @return Absolute path reference */ - const SystemString& getAbsolutePath() const {return m_absPath;} + SystemStringView getAbsolutePath() const {return m_absPath;} /** * @brief Access fully-canonicalized project-relative path * @return Relative pointer to within absolute-path or "." for project root-directory (use isRoot to detect) */ - const SystemString& getRelativePath() const + SystemStringView getRelativePath() const { if (m_relPath.size()) return m_relPath; @@ -923,44 +908,43 @@ public: * @brief Obtain c-string of final path component (stored within relative path) * @return Final component c-string (may be empty) */ - const SystemChar* getLastComponent() const + SystemStringView getLastComponent() const { size_t pos = m_relPath.rfind(_S('/')); if (pos == SystemString::npos) - return m_relPath.c_str() + m_relPath.size(); - return m_relPath.c_str() + pos + 1; + return {}; + return {m_relPath.c_str() + pos + 1, m_relPath.size() - pos - 1}; } - const char* getLastComponentUTF8() const + SystemStringView getLastComponentUTF8() const { size_t pos = m_relPath.rfind(_S('/')); #if HECL_UCS2 if (pos == SystemString::npos) - return m_utf8RelPath.c_str() + m_utf8RelPath.size(); - return m_utf8RelPath.c_str() + pos + 1; + return {}; + return {m_utf8RelPath.c_str() + pos + 1, size_t(m_utf8RelPath.size() - pos - 1)}; #else if (pos == SystemString::npos) - return m_relPath.c_str() + m_relPath.size(); - return m_relPath.c_str() + pos + 1; + return {}; + return {m_relPath.c_str() + pos + 1, size_t(m_relPath.size() - pos - 1)}; #endif } /** * @brief Obtain c-string of extension of final path component (stored within relative path) - * @return Final component extension c-string (may be nullptr) + * @return Final component extension c-string (may be empty) */ - const SystemChar* getLastComponentExt() const + SystemStringView getLastComponentExt() const { - const SystemChar* lastCompOrig = getLastComponent(); - const SystemChar* lastComp = lastCompOrig; - while (*lastComp != _S('\0')) - ++lastComp; - while (lastComp != lastCompOrig) + SystemStringView lastCompOrig = getLastComponent().data(); + const SystemChar* end = lastCompOrig.data() + lastCompOrig.size(); + const SystemChar* lastComp = end; + while (lastComp != lastCompOrig.data()) { if (*lastComp == _S('.')) - return lastComp + 1; + return {lastComp + 1, size_t(end - lastComp - 1)}; --lastComp; } - return nullptr; + return {}; } /** @@ -1038,7 +1022,7 @@ public: * @brief Access fully-canonicalized absolute path in UTF-8 * @return Absolute path reference */ - const std::string& getAbsolutePathUTF8() const + std::string_view getAbsolutePathUTF8() const { #if HECL_UCS2 return m_utf8AbsPath; @@ -1047,7 +1031,7 @@ public: #endif } - const std::string& getRelativePathUTF8() const + std::string_view getRelativePathUTF8() const { #if HECL_UCS2 return m_utf8RelPath; @@ -1056,12 +1040,12 @@ public: #endif } - const SystemString& getAuxInfo() const + SystemStringView getAuxInfo() const { return m_auxInfo; } - const std::string& getAuxInfoUTF8() const + std::string_view getAuxInfoUTF8() const { #if HECL_UCS2 return m_utf8AuxInfo; @@ -1074,25 +1058,15 @@ public: * @brief Construct a path with the aux info overwritten with specified string * @param auxStr string to replace existing auxInfo with */ - ProjectPath ensureAuxInfo(const SystemChar* auxStr) const + ProjectPath ensureAuxInfo(SystemStringView auxStr) const { - return ProjectPath(getProject(), getRelativePath() + _S('|') + auxStr); - } - - ProjectPath ensureAuxInfo(const SystemString& auxStr) const - { - return ProjectPath(getProject(), getRelativePath() + _S('|') + auxStr); + return ProjectPath(getProject(), SystemString(getRelativePath()) + _S('|') + auxStr.data()); } #if HECL_UCS2 - ProjectPath ensureAuxInfo(const char* auxStr) const + ProjectPath ensureAuxInfo(std::string_view auxStr) const { - return ProjectPath(getProject(), getRelativePath() + _S('|') + UTF8ToWide(auxStr)); - } - - ProjectPath ensureAuxInfo(const std::string& auxStr) const - { - return ProjectPath(getProject(), getRelativePath() + _S('|') + UTF8ToWide(auxStr)); + return ProjectPath(getProject(), SystemString(getRelativePath()) + _S('|') + UTF8ToWide(auxStr)); } #endif @@ -1244,23 +1218,21 @@ public: class StringUtils { public: - static bool BeginsWith(const SystemString& str, const SystemChar* test) + static bool BeginsWith(SystemStringView str, SystemStringView test) { - size_t len = StrLen(test); - if (len > str.size()) + if (test.size() > str.size()) return false; - return !StrNCmp(str.data(), test, len); + return !StrNCmp(str.data(), test.data(), test.size()); } - static bool EndsWith(const SystemString& str, const SystemChar* test) + static bool EndsWith(SystemStringView str, SystemStringView test) { - size_t len = StrLen(test); - if (len > str.size()) + if (test.size() > str.size()) return false; - return !StrNCmp(&*(str.end() - len), test, len); + return !StrNCmp(&*(str.end() - test.size()), test.data(), test.size()); } - static std::string TrimWhitespace(const std::string& str) + static std::string TrimWhitespace(std::string_view str) { auto bit = str.begin(); while (bit != str.cend() && isspace(*bit)) @@ -1272,23 +1244,21 @@ public: } #if HECL_UCS2 - static bool BeginsWith(const std::string& str, const char* test) + static bool BeginsWith(std::string_view str, std::string_view test) { - size_t len = strlen(test); - if (len > str.size()) + if (test.size() > str.size()) return false; - return !strncmp(str.data(), test, len); + return !strncmp(str.data(), test.data(), test.size()); } - static bool EndsWith(const std::string& str, const char* test) + static bool EndsWith(std::string_view str, std::string_view test) { - size_t len = strlen(test); - if (len > str.size()) + if (test.size() > str.size()) return false; - return !strncmp(&*(str.end() - len), test, len); + return !strncmp(&*(str.end() - test.size()), test.data(), test.size()); } - static SystemString TrimWhitespace(const SystemString& str) + static SystemString TrimWhitespace(SystemStringView str) { auto bit = str.begin(); while (bit != str.cend() && iswspace(*bit)) @@ -1328,7 +1298,7 @@ public: * @param path absolute or relative file path to search from * @return Newly-constructed root path (bool-evaluating to false if not found) */ -ProjectRootPath SearchForProject(const SystemString& path); +ProjectRootPath SearchForProject(SystemStringView path); /** * @brief Search from within provided directory for the project root @@ -1336,7 +1306,7 @@ ProjectRootPath SearchForProject(const SystemString& path); * @param subpathOut remainder of provided path assigned to this ProjectPath * @return Newly-constructed root path (bool-evaluating to false if not found) */ -ProjectRootPath SearchForProject(const SystemString& path, SystemString& subpathOut); +ProjectRootPath SearchForProject(SystemStringView path, SystemString& subpathOut); /** * @brief Test if given path is a PNG (based on file header) diff --git a/hecl/lib/Blender/BlenderConnection.cpp b/hecl/lib/Blender/BlenderConnection.cpp index 8c2851213..e144a8dc0 100644 --- a/hecl/lib/Blender/BlenderConnection.cpp +++ b/hecl/lib/Blender/BlenderConnection.cpp @@ -35,6 +35,8 @@ template <> struct hash> }; } +using namespace std::literals; + namespace hecl { @@ -603,14 +605,14 @@ bool BlenderConnection::createBlend(const ProjectPath& path, BlendType type) "BlenderConnection::createBlend() musn't be called with stream active"); return false; } - _writeStr(("CREATE \"" + path.getAbsolutePathUTF8() + "\" " + BlendTypeStrs[int(type)] + + _writeStr(("CREATE \""s + path.getAbsolutePathUTF8().data() + "\" " + BlendTypeStrs[int(type)] + " \"" + m_startupBlend + "\"").c_str()); char lineBuf[256]; _readStr(lineBuf, sizeof(lineBuf)); if (!strcmp(lineBuf, "FINISHED")) { /* Delete immediately in case save doesn't occur */ - hecl::Unlink(path.getAbsolutePath().c_str()); + hecl::Unlink(path.getAbsolutePath().data()); m_loadedBlend = path; m_loadedType = type; return true; @@ -628,7 +630,7 @@ bool BlenderConnection::openBlend(const ProjectPath& path, bool force) } if (!force && path == m_loadedBlend) return true; - _writeStr(("OPEN \"" + path.getAbsolutePathUTF8() + "\"").c_str()); + _writeStr(("OPEN \""s + path.getAbsolutePathUTF8().data() + "\"").c_str()); char lineBuf[256]; _readStr(lineBuf, sizeof(lineBuf)); if (!strcmp(lineBuf, "FINISHED")) @@ -680,8 +682,8 @@ void BlenderConnection::deleteBlend() { if (m_loadedBlend) { - hecl::Unlink(m_loadedBlend.getAbsolutePath().c_str()); - BlenderLog.report(logvisor::Info, _S("Deleted '%s'"), m_loadedBlend.getAbsolutePath().c_str()); + hecl::Unlink(m_loadedBlend.getAbsolutePath().data()); + BlenderLog.report(logvisor::Info, _S("Deleted '%s'"), m_loadedBlend.getAbsolutePath().data()); m_loadedBlend = ProjectPath(); } } @@ -930,10 +932,10 @@ BlenderConnection::DataStream::Mesh::Material::Material conn._readBuf(&bufSz, 4); std::string readStr(bufSz, ' '); conn._readBuf(&readStr[0], bufSz); - SystemStringView absolute(readStr); + SystemStringConv absolute(readStr); SystemString relative = - conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(absolute); + conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(absolute.sys_str()); texs.emplace_back(conn.m_loadedBlend.getProject().getProjectWorkingPath(), relative); } @@ -1227,7 +1229,7 @@ BlenderConnection::DataStream::MapUniverse::World::World(BlenderConnection& conn path.assign(pathLen, '\0'); conn._readBuf(&path[0], pathLen); - hecl::SystemStringView sysPath(path); + hecl::SystemStringConv sysPath(path); worldPath.assign(conn.m_loadedBlend.getProject().getProjectWorkingPath(), sysPath.sys_str()); } } @@ -1242,7 +1244,7 @@ BlenderConnection::DataStream::MapUniverse::MapUniverse(BlenderConnection& conn) path.assign(pathLen, '\0'); conn._readBuf(&path[0], pathLen); - hecl::SystemStringView sysPath(path); + hecl::SystemStringConv sysPath(path); SystemString pathRel = conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(sysPath.sys_str()); hexagonPath.assign(conn.m_loadedBlend.getProject().getProjectWorkingPath(), pathRel); @@ -1324,10 +1326,10 @@ BlenderConnection::DataStream::Actor::Subtype::Subtype(BlenderConnection& conn) { meshPath.assign(bufSz, ' '); conn._readBuf(&meshPath[0], bufSz); - SystemStringView meshPathAbs(meshPath); + SystemStringConv meshPathAbs(meshPath); SystemString meshPathRel = - conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs); + conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs.sys_str()); mesh.assign(conn.m_loadedBlend.getProject().getProjectWorkingPath(), meshPathRel); } @@ -1349,10 +1351,10 @@ BlenderConnection::DataStream::Actor::Subtype::Subtype(BlenderConnection& conn) { meshPath.assign(bufSz, ' '); conn._readBuf(&meshPath[0], bufSz); - SystemStringView meshPathAbs(meshPath); + SystemStringConv meshPathAbs(meshPath); SystemString meshPathRel = - conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs); + conn.m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs.sys_str()); overlayMeshes.emplace_back(std::move(overlayName), ProjectPath(conn.m_loadedBlend.getProject().getProjectWorkingPath(), meshPathRel)); } @@ -1432,7 +1434,7 @@ BlenderConnection::DataStream::compileMesh(HMDLTopology topology, { if (m_parent->m_loadedType != BlendType::Mesh) BlenderLog.report(logvisor::Fatal, _S("%s is not a MESH blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; snprintf(req, 128, "MESHCOMPILE %s %d", @@ -1448,43 +1450,43 @@ BlenderConnection::DataStream::compileMesh(HMDLTopology topology, } BlenderConnection::DataStream::Mesh -BlenderConnection::DataStream::compileMesh(const std::string& name, +BlenderConnection::DataStream::compileMesh(std::string_view name, HMDLTopology topology, int skinSlotCount, Mesh::SurfProgFunc surfProg) { if (m_parent->m_loadedType != BlendType::Area) BlenderLog.report(logvisor::Fatal, _S("%s is not an AREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; - snprintf(req, 128, "MESHCOMPILENAME %s %s %d", name.c_str(), + snprintf(req, 128, "MESHCOMPILENAME %s %s %d", name.data(), MeshOutputModeString(topology), skinSlotCount); m_parent->_writeStr(req); char readBuf[256]; m_parent->_readStr(readBuf, 256); if (strcmp(readBuf, "OK")) - BlenderLog.report(logvisor::Fatal, "unable to cook mesh '%s': %s", name.c_str(), readBuf); + BlenderLog.report(logvisor::Fatal, "unable to cook mesh '%s': %s", name.data(), readBuf); return Mesh(*m_parent, topology, skinSlotCount, surfProg); } BlenderConnection::DataStream::ColMesh -BlenderConnection::DataStream::compileColMesh(const std::string& name) +BlenderConnection::DataStream::compileColMesh(std::string_view name) { if (m_parent->m_loadedType != BlendType::Area) BlenderLog.report(logvisor::Fatal, _S("%s is not an AREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; - snprintf(req, 128, "MESHCOMPILENAMECOLLISION %s", name.c_str()); + snprintf(req, 128, "MESHCOMPILENAMECOLLISION %s", name.data()); m_parent->_writeStr(req); char readBuf[256]; m_parent->_readStr(readBuf, 256); if (strcmp(readBuf, "OK")) - BlenderLog.report(logvisor::Fatal, "unable to cook collision mesh '%s': %s", name.c_str(), readBuf); + BlenderLog.report(logvisor::Fatal, "unable to cook collision mesh '%s': %s", name.data(), readBuf); return ColMesh(*m_parent); } @@ -1494,7 +1496,7 @@ BlenderConnection::DataStream::compileColMeshes() { if (m_parent->m_loadedType != BlendType::ColMesh) BlenderLog.report(logvisor::Fatal, _S("%s is not a CMESH blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; snprintf(req, 128, "MESHCOMPILECOLLISIONALL"); @@ -1525,7 +1527,7 @@ BlenderConnection::DataStream::compileAllMeshes(HMDLTopology topology, { if (m_parent->m_loadedType != BlendType::Area) BlenderLog.report(logvisor::Fatal, _S("%s is not an AREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; snprintf(req, 128, "MESHCOMPILEALL %s %d %f", @@ -1545,7 +1547,7 @@ std::vector BlenderConnection::DataStream: { if (m_parent->m_loadedType != BlendType::Area) BlenderLog.report(logvisor::Fatal, _S("%s is not an AREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("LIGHTCOMPILEALL"); @@ -1566,14 +1568,14 @@ std::vector BlenderConnection::DataStream: return ret; } -void BlenderConnection::DataStream::compileGuiFrame(const std::string& pathOut, int version) +void BlenderConnection::DataStream::compileGuiFrame(std::string_view pathOut, int version) { if (m_parent->m_loadedType != BlendType::Frame) BlenderLog.report(logvisor::Fatal, _S("%s is not a FRAME blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[512]; - snprintf(req, 512, "FRAMECOMPILE '%s' %d", pathOut.c_str(), version); + snprintf(req, 512, "FRAMECOMPILE '%s' %d", pathOut.data(), version); m_parent->_writeStr(req); char readBuf[1024]; @@ -1588,13 +1590,13 @@ void BlenderConnection::DataStream::compileGuiFrame(const std::string& pathOut, break; std::string readStr(readBuf); - SystemStringView absolute(readStr); + SystemStringConv absolute(readStr); auto& proj = m_parent->m_loadedBlend.getProject(); SystemString relative; if (PathRelative(absolute.c_str())) relative = absolute.sys_str(); else - relative = proj.getProjectRootPath().getProjectRelativeFromAbsolute(absolute); + relative = proj.getProjectRootPath().getProjectRelativeFromAbsolute(absolute.sys_str()); hecl::ProjectPath path(proj.getProjectWorkingPath(), relative); snprintf(req, 512, "%016" PRIX64 , path.hash().val64()); @@ -1621,10 +1623,10 @@ std::vector BlenderConnection::DataStream::getTextures() m_parent->_readBuf(&bufSz, 4); std::string readStr(bufSz, ' '); m_parent->_readBuf(&readStr[0], bufSz); - SystemStringView absolute(readStr); + SystemStringConv absolute(readStr); SystemString relative = - m_parent->m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(absolute); + m_parent->m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(absolute.sys_str()); texs.emplace_back(m_parent->m_loadedBlend.getProject().getProjectWorkingPath(), relative); } @@ -1635,7 +1637,7 @@ BlenderConnection::DataStream::Actor BlenderConnection::DataStream::compileActor { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("ACTORCOMPILE"); @@ -1652,7 +1654,7 @@ BlenderConnection::DataStream::compileActorCharacterOnly() { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("ACTORCOMPILECHARACTERONLY"); @@ -1665,14 +1667,14 @@ BlenderConnection::DataStream::compileActorCharacterOnly() } BlenderConnection::DataStream::Actor::Action -BlenderConnection::DataStream::compileActionChannelsOnly(const std::string& name) +BlenderConnection::DataStream::compileActionChannelsOnly(std::string_view name) { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; - snprintf(req, 128, "ACTIONCOMPILECHANNELSONLY %s", name.c_str()); + snprintf(req, 128, "ACTIONCOMPILECHANNELSONLY %s", name.data()); m_parent->_writeStr(req); char readBuf[256]; @@ -1688,7 +1690,7 @@ BlenderConnection::DataStream::compileWorld() { if (m_parent->m_loadedType != BlendType::World) BlenderLog.report(logvisor::Fatal, _S("%s is not an WORLD blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("WORLDCOMPILE"); @@ -1704,7 +1706,7 @@ std::vector BlenderConnection::DataStream::getArmatureNames() { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("GETARMATURENAMES"); @@ -1735,7 +1737,7 @@ std::vector BlenderConnection::DataStream::getSubtypeNames() { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("GETSUBTYPENAMES"); @@ -1766,7 +1768,7 @@ std::vector BlenderConnection::DataStream::getActionNames() { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("GETACTIONNAMES"); @@ -1793,14 +1795,14 @@ std::vector BlenderConnection::DataStream::getActionNames() return ret; } -std::vector BlenderConnection::DataStream::getSubtypeOverlayNames(const std::string& name) +std::vector BlenderConnection::DataStream::getSubtypeOverlayNames(std::string_view name) { if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; - snprintf(req, 128, "GETSUBTYPEOVERLAYNAMES %s", name.c_str()); + snprintf(req, 128, "GETSUBTYPEOVERLAYNAMES %s", name.data()); m_parent->_writeStr(req); char readBuf[256]; @@ -1827,17 +1829,17 @@ std::vector BlenderConnection::DataStream::getSubtypeOverlayNames(c } std::unordered_map -BlenderConnection::DataStream::getBoneMatrices(const std::string& name) +BlenderConnection::DataStream::getBoneMatrices(std::string_view name) { if (name.empty()) return {}; if (m_parent->m_loadedType != BlendType::Actor) BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[128]; - snprintf(req, 128, "GETBONEMATRICES %s", name.c_str()); + snprintf(req, 128, "GETBONEMATRICES %s", name.data()); m_parent->_writeStr(req); char readBuf[256]; @@ -1877,17 +1879,17 @@ BlenderConnection::DataStream::getBoneMatrices(const std::string& name) } -bool BlenderConnection::DataStream::renderPvs(const std::string& path, const atVec3f& location) +bool BlenderConnection::DataStream::renderPvs(std::string_view path, const atVec3f& location) { if (path.empty()) return false; if (m_parent->m_loadedType != BlendType::Area) BlenderLog.report(logvisor::Fatal, _S("%s is not an AREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[256]; - snprintf(req, 256, "RENDERPVS %s %f %f %f", path.c_str(), + snprintf(req, 256, "RENDERPVS %s %f %f %f", path.data(), location.vec[0], location.vec[1], location.vec[2]); m_parent->_writeStr(req); @@ -1895,29 +1897,29 @@ bool BlenderConnection::DataStream::renderPvs(const std::string& path, const atV m_parent->_readStr(readBuf, 256); if (strcmp(readBuf, "OK")) BlenderLog.report(logvisor::Fatal, "unable to render PVS for: %s; %s", - m_parent->m_loadedBlend.getAbsolutePathUTF8().c_str(), readBuf); + m_parent->m_loadedBlend.getAbsolutePathUTF8().data(), readBuf); return true; } -bool BlenderConnection::DataStream::renderPvsLight(const std::string& path, const std::string& lightName) +bool BlenderConnection::DataStream::renderPvsLight(std::string_view path, std::string_view lightName) { if (path.empty()) return false; if (m_parent->m_loadedType != BlendType::Area) BlenderLog.report(logvisor::Fatal, _S("%s is not an AREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); char req[256]; - snprintf(req, 256, "RENDERPVSLIGHT %s %s", path.c_str(), lightName.c_str()); + snprintf(req, 256, "RENDERPVSLIGHT %s %s", path.data(), lightName.data()); m_parent->_writeStr(req); char readBuf[256]; m_parent->_readStr(readBuf, 256); if (strcmp(readBuf, "OK")) - BlenderLog.report(logvisor::Fatal, "unable to render PVS light %s for: %s; %s", lightName.c_str(), - m_parent->m_loadedBlend.getAbsolutePathUTF8().c_str(), readBuf); + BlenderLog.report(logvisor::Fatal, "unable to render PVS light %s for: %s; %s", lightName.data(), + m_parent->m_loadedBlend.getAbsolutePathUTF8().data(), readBuf); return true; } @@ -1926,7 +1928,7 @@ BlenderConnection::DataStream::MapArea BlenderConnection::DataStream::compileMap { if (m_parent->m_loadedType != BlendType::MapArea) BlenderLog.report(logvisor::Fatal, _S("%s is not a MAPAREA blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("MAPAREACOMPILE"); @@ -1934,7 +1936,7 @@ BlenderConnection::DataStream::MapArea BlenderConnection::DataStream::compileMap m_parent->_readStr(readBuf, 256); if (strcmp(readBuf, "OK")) BlenderLog.report(logvisor::Fatal, "unable to compile map area: %s; %s", - m_parent->m_loadedBlend.getAbsolutePathUTF8().c_str(), readBuf); + m_parent->m_loadedBlend.getAbsolutePathUTF8().data(), readBuf); return {*m_parent}; } @@ -1943,7 +1945,7 @@ BlenderConnection::DataStream::MapUniverse BlenderConnection::DataStream::compil { if (m_parent->m_loadedType != BlendType::MapUniverse) BlenderLog.report(logvisor::Fatal, _S("%s is not a MAPUNIVERSE blend"), - m_parent->m_loadedBlend.getAbsolutePath().c_str()); + m_parent->m_loadedBlend.getAbsolutePath().data()); m_parent->_writeStr("MAPUNIVERSECOMPILE"); @@ -1951,7 +1953,7 @@ BlenderConnection::DataStream::MapUniverse BlenderConnection::DataStream::compil m_parent->_readStr(readBuf, 256); if (strcmp(readBuf, "OK")) BlenderLog.report(logvisor::Fatal, "unable to compile map universe: %s; %s", - m_parent->m_loadedBlend.getAbsolutePathUTF8().c_str(), readBuf); + m_parent->m_loadedBlend.getAbsolutePathUTF8().data(), readBuf); return {*m_parent}; } diff --git a/hecl/lib/CVar.cpp b/hecl/lib/CVar.cpp index baebbccf1..376fc2234 100755 --- a/hecl/lib/CVar.cpp +++ b/hecl/lib/CVar.cpp @@ -10,24 +10,26 @@ namespace hecl extern CVar* com_developer; extern CVar* com_enableCheats; -CVar::CVar(const std::string& name, const std::string &value, const std::string &help, EType type, EFlags flags, CVarManager& parent) +using namespace std::literals; + +CVar::CVar(std::string_view name, std::string_view value, std::string_view help, EType type, EFlags flags, CVarManager& parent) : m_mgr(parent) { - m_name= name; - m_value = value; - m_defaultValue = value; + m_name = std::string(name); + m_value = std::string(value); + m_defaultValue = std::string(value); m_help = help; m_type = type; m_flags = flags; m_allowedWrite = false; } -CVar::CVar(const std::string& name, const std::string& value, const std::string& help, CVar::EFlags flags, CVarManager& parent) +CVar::CVar(std::string_view name, std::string_view value, std::string_view help, CVar::EFlags flags, CVarManager& parent) : m_mgr(parent) { m_flags = flags; m_allowedWrite = false; - m_name = name; + m_name = std::string(name); m_help = help; m_type = EType::Literal; @@ -43,10 +45,10 @@ CVar::CVar(const std::string& name, const std::string& value, const std::string& m_flags = flags; } -CVar::CVar(const std::string& name, const atVec4f& value, const std::string& help, EFlags flags, CVarManager& parent) +CVar::CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags, CVarManager& parent) : m_mgr(parent) { - m_name= name; + m_name = std::string(name); m_help = help; m_type = EType::Vec4f; m_flags = flags; @@ -64,10 +66,10 @@ CVar::CVar(const std::string& name, const atVec4f& value, const std::string& hel m_flags = flags; } -CVar::CVar(const std::string& name, float value, const std::string& help, EFlags flags, CVarManager& parent) +CVar::CVar(std::string_view name, float value, std::string_view help, EFlags flags, CVarManager& parent) : m_mgr(parent) { - m_name= name; + m_name = std::string(name); m_help = help; m_type = EType::Float; m_flags = flags; @@ -85,10 +87,10 @@ CVar::CVar(const std::string& name, float value, const std::string& help, EFlags m_flags = flags; } -CVar::CVar(const std::string& name, bool value, const std::string& help, CVar::EFlags flags, CVarManager& parent) +CVar::CVar(std::string_view name, bool value, std::string_view help, CVar::EFlags flags, CVarManager& parent) : m_mgr(parent) { - m_name= name; + m_name = std::string(name); m_help = help; m_type = EType::Boolean; m_flags = flags; @@ -106,10 +108,10 @@ CVar::CVar(const std::string& name, bool value, const std::string& help, CVar::E m_flags = flags; } -CVar::CVar(const std::string& name, int value, const std::string& help, CVar::EFlags flags, CVarManager& parent) +CVar::CVar(std::string_view name, int value, std::string_view help, CVar::EFlags flags, CVarManager& parent) : m_mgr(parent) { - m_name= name; + m_name = std::string(name); m_help = help; m_type = EType::Integer; m_flags = flags; @@ -287,9 +289,9 @@ bool CVar::fromBoolean(bool val) return false; if (val) - m_value = "true"; + m_value = "true"sv; else - m_value = "false"; + m_value = "false"sv; setModified(); return true; @@ -313,7 +315,7 @@ bool CVar::fromInteger(int val) return true; } -bool CVar::fromLiteral(const std::string& val) +bool CVar::fromLiteral(std::string_view val) { if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) return false; @@ -331,7 +333,7 @@ bool CVar::fromLiteral(const std::string& val) return true; } -bool CVar::fromLiteral(const std::wstring& val) +bool CVar::fromLiteral(std::wstring_view val) { if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) return false; diff --git a/hecl/lib/CVarManager.cpp b/hecl/lib/CVarManager.cpp index b7fc61664..434748184 100755 --- a/hecl/lib/CVarManager.cpp +++ b/hecl/lib/CVarManager.cpp @@ -41,7 +41,7 @@ void CVarManager::update() bool CVarManager::registerCVar(CVar* cvar) { - std::string tmp = cvar->name(); + std::string tmp(cvar->name()); athena::utility::tolower(tmp); if (m_cvars.find(tmp) != m_cvars.end()) return false; @@ -50,13 +50,15 @@ bool CVarManager::registerCVar(CVar* cvar) return true; } -CVar* CVarManager::findCVar(std::string name) +CVar* CVarManager::findCVar(std::string_view name) { - athena::utility::tolower(name); - if (m_cvars.find(name) == m_cvars.end()) + std::string lower(name); + athena::utility::tolower(lower); + auto search = m_cvars.find(lower); + if (search == m_cvars.end()) return nullptr; - return m_cvars[name]; + return search->second; } std::vector CVarManager::archivedCVars() const @@ -87,7 +89,7 @@ void CVarManager::deserialize(CVar* cvar) #if _WIN32 hecl::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toWideLiteral(); #else - hecl::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toLiteral(); #endif hecl::Sstat st; @@ -147,9 +149,9 @@ void CVarManager::serialize() container.cvarCount = container.cvars.size(); #if _WIN32 - hecl::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toWideLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toWideLiteral(); #else - hecl::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toLiteral(); #endif if (m_useBinary) diff --git a/hecl/lib/ClientProcess.cpp b/hecl/lib/ClientProcess.cpp index 28e79a11d..1d82fab9a 100644 --- a/hecl/lib/ClientProcess.cpp +++ b/hecl/lib/ClientProcess.cpp @@ -35,7 +35,7 @@ void ClientProcess::BufferTransaction::run(BlenderToken& btok) if (r.hasError()) { Log.report(logvisor::Fatal, _S("unable to background-buffer '%s'"), - m_path.getAbsolutePath().c_str()); + m_path.getAbsolutePath().data()); return; } if (m_offset) @@ -162,11 +162,11 @@ bool ClientProcess::syncCook(const hecl::ProjectPath& path, Database::IDataSpec* { if (path.getAuxInfo().empty()) LogModule.report(logvisor::Info, _S("Cooking %s"), - path.getRelativePath().c_str()); + path.getRelativePath().data()); else LogModule.report(logvisor::Info, _S("Cooking %s|%s"), - path.getRelativePath().c_str(), - path.getAuxInfo().c_str()); + path.getRelativePath().data(), + path.getAuxInfo().data()); spec->doCook(path, cooked, false, btok, [](const SystemChar*) {}); } return true; diff --git a/hecl/lib/Frontend/Lexer.cpp b/hecl/lib/Frontend/Lexer.cpp index f1f014d6e..73263acf7 100644 --- a/hecl/lib/Frontend/Lexer.cpp +++ b/hecl/lib/Frontend/Lexer.cpp @@ -345,7 +345,7 @@ void Lexer::consumeAllTokens(Parser& parser) if (hecl::VerbosityLevel > 1) { - printf("%s\n", m_diag.getSource().c_str()); + printf("%s\n", m_diag.getSource().data()); PrintTree(firstNode); printf("\n"); } diff --git a/hecl/lib/Frontend/Parser.cpp b/hecl/lib/Frontend/Parser.cpp index 47eb60120..99bcf4667 100644 --- a/hecl/lib/Frontend/Parser.cpp +++ b/hecl/lib/Frontend/Parser.cpp @@ -8,19 +8,19 @@ namespace hecl namespace Frontend { -void Parser::skipWhitespace(std::string::const_iterator& it) +void Parser::skipWhitespace(std::string_view::const_iterator& it) { - while (it != m_source->cend()) + while (it != m_source.cend()) { - while (it != m_source->cend() && isspace(*it)) + while (it != m_source.cend() && isspace(*it)) ++it; /* Skip comment line */ - if (it != m_source->cend() && *it == '#') + if (it != m_source.cend() && *it == '#') { - while (it != m_source->cend() && *it != '\n') + while (it != m_source.cend() && *it != '\n') ++it; - if (it != m_source->cend() && *it == '\n') + if (it != m_source.cend() && *it == '\n') ++it; continue; } @@ -28,17 +28,17 @@ void Parser::skipWhitespace(std::string::const_iterator& it) } } -void Parser::reset(const std::string& source) +void Parser::reset(std::string_view source) { - m_source = &source; - m_sourceIt = m_source->cbegin(); + m_source = source; + m_sourceIt = m_source.cbegin(); m_parenStack.clear(); m_reset = true; } Parser::Token Parser::consumeToken() { - if (!m_source) + if (m_source.empty()) return Parser::Token(TokenType::None, SourceLocation()); /* If parser has just been reset, emit begin token */ @@ -52,7 +52,7 @@ Parser::Token Parser::consumeToken() skipWhitespace(m_sourceIt); /* Check for source end */ - if (m_sourceIt == m_source->cend()) + if (m_sourceIt == m_source.cend()) return Parser::Token(TokenType::SourceEnd, getLocation()); /* Check for numeric literal */ @@ -72,13 +72,13 @@ Parser::Token Parser::consumeToken() if (*m_sourceIt == '.') { int count = 0; - std::string::const_iterator tmp = m_sourceIt + 1; - if (tmp != m_source->cend()) + std::string_view::const_iterator tmp = m_sourceIt + 1; + if (tmp != m_source.cend()) { for (int i=0 ; i<4 ; ++i) { - std::string::const_iterator tmp2 = tmp + i; - if (tmp2 == m_source->cend()) + std::string_view::const_iterator tmp2 = tmp + i; + if (tmp2 == m_source.cend()) break; char ch = tolower(*tmp2); if (ch >= 'w' && ch <= 'z') @@ -94,7 +94,7 @@ Parser::Token Parser::consumeToken() Parser::Token tok(TokenType::VectorSwizzle, getLocation()); for (int i=0 ; icend() && (isalnum(*tmp) || *tmp == '_') && *tmp != '(') + std::string_view::const_iterator tmp = m_sourceIt + 1; + while (tmp != m_source.cend() && (isalnum(*tmp) || *tmp == '_') && *tmp != '(') ++tmp; - std::string::const_iterator nameEnd = tmp; + std::string_view::const_iterator nameEnd = tmp; skipWhitespace(tmp); if (*tmp == '(') { @@ -172,9 +172,9 @@ Parser::Token Parser::consumeToken() SourceLocation Parser::getLocation() const { - if (!m_source) + if (m_source.empty()) return SourceLocation(); - std::string::const_iterator it = m_source->cbegin(); + std::string_view::const_iterator it = m_source.cbegin(); int line = 0; int col = 0; for (; it != m_sourceIt ; ++it) diff --git a/hecl/lib/Project.cpp b/hecl/lib/Project.cpp index 942c9d9b9..a381aa341 100644 --- a/hecl/lib/Project.cpp +++ b/hecl/lib/Project.cpp @@ -45,10 +45,10 @@ static inline bool CheckNewLineAdvance(std::string::const_iterator& it) return false; } -Project::ConfigFile::ConfigFile(const Project& project, const SystemString& name, - const SystemString& subdir) +Project::ConfigFile::ConfigFile(const Project& project, SystemStringView name, + SystemStringView subdir) { - m_filepath = project.m_rootPath.getAbsolutePath() + subdir + name; + m_filepath = SystemString(project.m_rootPath.getAbsolutePath()) + subdir.data() + name.data(); } std::vector& Project::ConfigFile::lockAndRead() @@ -89,13 +89,13 @@ std::vector& Project::ConfigFile::lockAndRead() return m_lines; } -void Project::ConfigFile::addLine(const std::string& line) +void Project::ConfigFile::addLine(std::string_view line) { if (!checkForLine(line)) - m_lines.push_back(line); + m_lines.emplace_back(line); } -void Project::ConfigFile::removeLine(const std::string& refLine) +void Project::ConfigFile::removeLine(std::string_view refLine) { if (!m_lockedFile) { @@ -116,7 +116,7 @@ void Project::ConfigFile::removeLine(const std::string& refLine) } } -bool Project::ConfigFile::checkForLine(const std::string& refLine) +bool Project::ConfigFile::checkForLine(std::string_view refLine) { if (!m_lockedFile) { @@ -210,15 +210,16 @@ Project::Project(const ProjectRootPath& rootPath) { /* Stat for existing project directory (must already exist) */ Sstat myStat; - if (hecl::Stat(m_rootPath.getAbsolutePath().c_str(), &myStat)) + if (hecl::Stat(m_rootPath.getAbsolutePath().data(), &myStat)) { - LogModule.report(logvisor::Error, _S("unable to stat %s"), m_rootPath.getAbsolutePath().c_str()); + LogModule.report(logvisor::Error, _S("unable to stat %s"), m_rootPath.getAbsolutePath().data()); return; } if (!S_ISDIR(myStat.st_mode)) { - LogModule.report(logvisor::Error, _S("provided path must be a directory; '%s' isn't"), m_rootPath.getAbsolutePath().c_str()); + LogModule.report(logvisor::Error, _S("provided path must be a directory; '%s' isn't"), + m_rootPath.getAbsolutePath().data()); return; } @@ -228,7 +229,7 @@ Project::Project(const ProjectRootPath& rootPath) /* Ensure beacon is valid or created */ ProjectPath beaconPath(m_dotPath, _S("beacon")); - FILE* bf = hecl::Fopen(beaconPath.getAbsolutePath().c_str(), _S("a+b")); + FILE* bf = hecl::Fopen(beaconPath.getAbsolutePath().data(), _S("a+b")); struct BeaconStruct { hecl::FourCC magic; @@ -279,7 +280,7 @@ bool Project::removePaths(const std::vector& paths, bool recursive) { for (const ProjectPath& path : paths) { - std::string recursiveBase = path.getRelativePathUTF8(); + auto recursiveBase = path.getRelativePathUTF8(); for (auto it = existingPaths.begin(); it != existingPaths.end();) { @@ -319,9 +320,9 @@ void Project::rescanDataSpecs() for (const DataSpecEntry* spec : DATA_SPEC_REGISTRY) { hecl::SystemString specStr(spec->m_name); - SystemUTF8View specUTF8(specStr); + SystemUTF8Conv specUTF8(specStr); m_compiledSpecs.push_back({*spec, ProjectPath(m_cookedRoot, hecl::SystemString(spec->m_name) + _S(".spec")), - m_specs.checkForLine(specUTF8) ? true : false}); + m_specs.checkForLine(specUTF8.str())}); } m_specs.unlockAndDiscard(); } @@ -331,8 +332,8 @@ bool Project::enableDataSpecs(const std::vector& specs) m_specs.lockAndRead(); for (const SystemString& spec : specs) { - SystemUTF8View specView(spec); - m_specs.addLine(specView); + SystemUTF8Conv specView(spec); + m_specs.addLine(specView.str()); } bool result = m_specs.unlockAndCommit(); rescanDataSpecs(); @@ -344,8 +345,8 @@ bool Project::disableDataSpecs(const std::vector& specs) m_specs.lockAndRead(); for (const SystemString& spec : specs) { - SystemUTF8View specView(spec); - m_specs.removeLine(specView); + SystemUTF8Conv specView(spec); + m_specs.removeLine(specView.str()); } bool result = m_specs.unlockAndCommit(); rescanDataSpecs(); @@ -446,7 +447,7 @@ static void VisitDirectory(const ProjectPath& dir, /* Pass 2: child files */ int progNum = 0; float progDenom = childFileCount; - progress.changeDir(dir.getLastComponent()); + progress.changeDir(dir.getLastComponent().data()); for (auto& child : children) { if (child.second.getPathType() == ProjectPath::Type::File) @@ -494,7 +495,7 @@ bool Project::cookPath(const ProjectPath& path, FProgress progress, case ProjectPath::Type::File: case ProjectPath::Type::Glob: { - cookProg.changeFile(path.getLastComponent(), 0.0); + cookProg.changeFile(path.getLastComponent().data(), 0.0); VisitFile(path, force, fast, m_cookSpecs, cookProg, cp); break; } diff --git a/hecl/lib/ProjectPath.cpp b/hecl/lib/ProjectPath.cpp index 1e305f3e9..b6d09f1db 100644 --- a/hecl/lib/ProjectPath.cpp +++ b/hecl/lib/ProjectPath.cpp @@ -7,12 +7,12 @@ namespace hecl static const SystemRegex regPATHCOMP(_S("[/\\\\]*([^/\\\\]+)"), SystemRegex::ECMAScript|SystemRegex::optimize); static const SystemRegex regDRIVELETTER(_S("^([^/]*)/"), SystemRegex::ECMAScript|SystemRegex::optimize); -static SystemString CanonRelPath(const SystemString& path) +static SystemString CanonRelPath(SystemStringView path) { /* Tokenize Path */ std::vector comps; hecl::SystemRegexMatch matches; - SystemString in = path; + SystemString in(path); SanitizePath(in); for (; std::regex_search(in, matches, regPATHCOMP) ; in = matches.suffix()) { @@ -24,7 +24,7 @@ static SystemString CanonRelPath(const SystemString& path) if (comps.empty()) { /* Unable to resolve outside project */ - LogModule.report(logvisor::Fatal, _S("Unable to resolve outside project root in %s"), path.c_str()); + LogModule.report(logvisor::Fatal, _S("Unable to resolve outside project root in %s"), path.data()); return _S("."); } comps.pop_back(); @@ -51,7 +51,7 @@ static SystemString CanonRelPath(const SystemString& path) return _S("."); } -static SystemString CanonRelPath(const SystemString& path, const ProjectRootPath& projectRoot) +static SystemString CanonRelPath(SystemStringView path, const ProjectRootPath& projectRoot) { /* Absolute paths not allowed; attempt to make project-relative */ if (IsAbsolute(path)) @@ -59,7 +59,7 @@ static SystemString CanonRelPath(const SystemString& path, const ProjectRootPath return CanonRelPath(path); } -void ProjectPath::assign(Database::Project& project, const SystemString& path) +void ProjectPath::assign(Database::Project& project, SystemStringView path) { m_proj = &project; @@ -74,7 +74,7 @@ void ProjectPath::assign(Database::Project& project, const SystemString& path) usePath = path; m_relPath = CanonRelPath(usePath, project.getProjectRootPath()); - m_absPath = project.getProjectRootPath().getAbsolutePath() + _S('/') + m_relPath; + m_absPath = SystemString(project.getProjectRootPath().getAbsolutePath()) + _S('/') + m_relPath; SanitizePath(m_relPath); SanitizePath(m_absPath); @@ -82,14 +82,14 @@ void ProjectPath::assign(Database::Project& project, const SystemString& path) } #if HECL_UCS2 -void ProjectPath::assign(Database::Project& project, const std::string& path) +void ProjectPath::assign(Database::Project& project, std::string_view path) { std::wstring wpath = UTF8ToWide(path); assign(project, wpath); } #endif -void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path) +void ProjectPath::assign(const ProjectPath& parentPath, SystemStringView path) { m_proj = parentPath.m_proj; @@ -104,7 +104,7 @@ void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path usePath = path; m_relPath = CanonRelPath(parentPath.m_relPath + _S('/') + usePath); - m_absPath = m_proj->getProjectRootPath().getAbsolutePath() + _S('/') + m_relPath; + m_absPath = SystemString(m_proj->getProjectRootPath().getAbsolutePath()) + _S('/') + m_relPath; SanitizePath(m_relPath); SanitizePath(m_absPath); @@ -112,7 +112,7 @@ void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path } #if HECL_UCS2 -void ProjectPath::assign(const ProjectPath& parentPath, const std::string& path) +void ProjectPath::assign(const ProjectPath& parentPath, std::string_view path) { std::wstring wpath = UTF8ToWide(path); assign(parentPath, wpath); @@ -125,7 +125,7 @@ ProjectPath ProjectPath::getCookedPath(const Database::DataSpecEntry& spec) cons ProjectPath ret(m_proj->getProjectCookedPath(spec), woExt.getRelativePath()); if (getAuxInfo().size()) - return ret.getWithExtension((_S('.') + getAuxInfo()).c_str()); + return ret.getWithExtension((SystemString(_S(".")) + getAuxInfo().data()).c_str()); else return ret; } @@ -154,7 +154,7 @@ Time ProjectPath::getModtime() const getGlobResults(globResults); for (ProjectPath& path : globResults) { - if (!hecl::Stat(path.getAbsolutePath().c_str(), &theStat)) + if (!hecl::Stat(path.getAbsolutePath().data(), &theStat)) { if (S_ISREG(theStat.st_mode) && theStat.st_mtime > latestTime) latestTime = theStat.st_mtime; @@ -254,15 +254,15 @@ hecl::DirectoryEnumerator ProjectPath::enumerateDir() const void ProjectPath::getGlobResults(std::vector& outPaths) const { - const SystemString& rootPath = m_proj->getProjectRootPath().getAbsolutePath(); - _recursiveGlob(*m_proj, outPaths, m_relPath, rootPath, rootPath.back() != _S('/')); + auto rootPath = m_proj->getProjectRootPath().getAbsolutePath(); + _recursiveGlob(*m_proj, outPaths, m_relPath, rootPath.data(), rootPath.back() != _S('/')); } -ProjectRootPath SearchForProject(const SystemString& path) +ProjectRootPath SearchForProject(SystemStringView path) { ProjectRootPath testRoot(path); - SystemString::const_iterator begin = testRoot.getAbsolutePath().begin(); - SystemString::const_iterator end = testRoot.getAbsolutePath().end(); + auto begin = testRoot.getAbsolutePath().begin(); + auto end = testRoot.getAbsolutePath().end(); while (begin != end) { SystemString testPath(begin, end); @@ -295,11 +295,11 @@ ProjectRootPath SearchForProject(const SystemString& path) return ProjectRootPath(); } -ProjectRootPath SearchForProject(const SystemString& path, SystemString& subpathOut) +ProjectRootPath SearchForProject(SystemStringView path, SystemString& subpathOut) { ProjectRootPath testRoot(path); - SystemString::const_iterator begin = testRoot.getAbsolutePath().begin(); - SystemString::const_iterator end = testRoot.getAbsolutePath().end(); + auto begin = testRoot.getAbsolutePath().begin(); + auto end = testRoot.getAbsolutePath().end(); while (begin != end) { SystemString testPath(begin, end); @@ -320,7 +320,7 @@ ProjectRootPath SearchForProject(const SystemString& path, SystemString& subpath if (hecl::FourCC(magic) != FOURCC('HECL')) continue; ProjectRootPath newRootPath = ProjectRootPath(testPath); - SystemString::const_iterator origEnd = testRoot.getAbsolutePath().end(); + auto origEnd = testRoot.getAbsolutePath().end(); while (end != origEnd && *end != _S('/') && *end != _S('\\')) ++end; if (end != origEnd && (*end == _S('/') || *end == _S('\\'))) diff --git a/hecl/lib/Runtime/FileStoreManager.cpp b/hecl/lib/Runtime/FileStoreManager.cpp index 50de1ec31..30ea39dd5 100644 --- a/hecl/lib/Runtime/FileStoreManager.cpp +++ b/hecl/lib/Runtime/FileStoreManager.cpp @@ -10,7 +10,7 @@ namespace Runtime { static logvisor::Module Log("FileStoreManager"); -FileStoreManager::FileStoreManager(const SystemString& domain) +FileStoreManager::FileStoreManager(SystemStringView domain) : m_domain(domain) { #if _WIN32 @@ -35,7 +35,8 @@ FileStoreManager::FileStoreManager(const SystemString& domain) path += "/.heclrun"; if (mkdir(path.c_str(), 0755) && errno != EEXIST) Log.report(logvisor::Fatal, "unable to mkdir at %s", path.c_str()); - path += '/' + domain; + path += '/'; + path += domain.data(); if (mkdir(path.c_str(), 0755) && errno != EEXIST) Log.report(logvisor::Fatal, "unable to mkdir at %s", path.c_str()); m_storeRoot = path; diff --git a/hecl/lib/Runtime/ShaderCacheManager.cpp b/hecl/lib/Runtime/ShaderCacheManager.cpp index 1cbebd0e7..d2ec5a2e6 100644 --- a/hecl/lib/Runtime/ShaderCacheManager.cpp +++ b/hecl/lib/Runtime/ShaderCacheManager.cpp @@ -116,8 +116,10 @@ ShaderCacheManager::ShaderCacheManager(const FileStoreManager& storeMgr, ShaderCacheExtensions&& extension) : m_storeMgr(storeMgr), m_extensions(std::move(extension)), - m_idxFr(storeMgr.getStoreRoot() + _S("/shadercache") + gfxFactory->platformName() + _S(".idx"), 32*1024, false), - m_datFr(storeMgr.getStoreRoot() + _S("/shadercache") + gfxFactory->platformName() + _S(".dat"), 32*1024, false) + m_idxFr(SystemString(storeMgr.getStoreRoot()) + _S("/shadercache") + + gfxFactory->platformName() + _S(".idx"), 32*1024, false), + m_datFr(SystemString(storeMgr.getStoreRoot()) + _S("/shadercache") + + gfxFactory->platformName() + _S(".dat"), 32*1024, false) { boo::IGraphicsDataFactory::Platform plat = gfxFactory->platform(); if (m_extensions && m_extensions.m_plat != plat) @@ -378,8 +380,8 @@ ShaderCacheManager::buildFromCache(const ShaderCachedData& foundData, } std::shared_ptr -ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source, - const std::string& diagName, +ShaderCacheManager::buildShader(const ShaderTag& tag, std::string_view source, + std::string_view diagName, boo::IGraphicsDataFactory& factory) { auto search = m_pipelineLookup.find(tag); @@ -392,7 +394,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source, { factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.data(), tag.val64()); boo::ObjToken build = buildFromCache(foundData, ctx); if (build) { @@ -407,13 +409,13 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source, m_pipelineLookup[tag] = ret; return ret; } - Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.c_str()); + Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.data()); } factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { hecl::Frontend::IR ir = FE.compileSource(source, diagName); - Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.data(), tag.val64()); FE.getDiagnostics().reset(diagName); boo::ObjToken build; addData(m_factory->buildShaderFromIR(tag, ir, FE.getDiagnostics(), ctx, build)); @@ -426,7 +428,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source, std::shared_ptr ShaderCacheManager::buildShader(const ShaderTag& tag, const hecl::Frontend::IR& ir, - const std::string& diagName, + std::string_view diagName, boo::IGraphicsDataFactory& factory) { auto search = m_pipelineLookup.find(tag); @@ -439,7 +441,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const hecl::Frontend::IR& { factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.data(), tag.val64()); boo::ObjToken build = buildFromCache(foundData, ctx); if (build) { @@ -454,12 +456,12 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const hecl::Frontend::IR& m_pipelineLookup[tag] = ret; return ret; } - Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.c_str()); + Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.data()); } factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.data(), tag.val64()); FE.getDiagnostics().reset(diagName); boo::ObjToken build; addData(m_factory->buildShaderFromIR(tag, ir, FE.getDiagnostics(), ctx, build)); @@ -486,8 +488,8 @@ ShaderCacheManager::buildExtendedFromCache(const ShaderCachedData& foundData, } std::shared_ptr -ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& source, - const std::string& diagName, +ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, std::string_view source, + std::string_view diagName, boo::IGraphicsDataFactory& factory) { auto search = m_pipelineLookup.find(tag); @@ -500,7 +502,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& { factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.data(), tag.val64()); ret->m_pipelines = buildExtendedFromCache(foundData, ctx); return ret->m_pipelines.size() != 0; }); @@ -510,7 +512,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& m_pipelineLookup[tag] = ret; return ret; } - Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.c_str()); + Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.data()); } hecl::Frontend::IR ir = FE.compileSource(source, diagName); @@ -519,7 +521,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& { ret->m_pipelines.reserve(m_extensions.m_extensionSlots.size()); FE.getDiagnostics().reset(diagName); - Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.data(), tag.val64()); ShaderCachedData data = m_factory->buildExtendedShaderFromIR(tag, ir, FE.getDiagnostics(), m_extensions.m_extensionSlots, ctx, [&](const boo::ObjToken& shader){ret->m_pipelines.push_back(shader);}); @@ -535,7 +537,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& std::shared_ptr ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const hecl::Frontend::IR& ir, - const std::string& diagName, + std::string_view diagName, boo::IGraphicsDataFactory& factory) { auto search = m_pipelineLookup.find(tag); @@ -548,7 +550,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const hecl::Fronte { factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building cached shader '%s' %016llX", diagName.data(), tag.val64()); ret->m_pipelines = buildExtendedFromCache(foundData, ctx); return ret->m_pipelines.size() != 0; }); @@ -558,14 +560,14 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const hecl::Fronte m_pipelineLookup[tag] = ret; return ret; } - Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.c_str()); + Log.report(logvisor::Warning, "invalid cache read, rebuilding shader '%s'", diagName.data()); } factory.commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { ret->m_pipelines.reserve(m_extensions.m_extensionSlots.size()); FE.getDiagnostics().reset(diagName); - Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.c_str(), tag.val64()); + Log.report(logvisor::Info, "building shader '%s' %016llX", diagName.data(), tag.val64()); ShaderCachedData data = m_factory->buildExtendedShaderFromIR(tag, ir, FE.getDiagnostics(), m_extensions.m_extensionSlots, ctx, [&](const boo::ObjToken& shader){ret->m_pipelines.push_back(shader);}); diff --git a/hecl/lib/SteamFinder.cpp b/hecl/lib/SteamFinder.cpp index a21bdcd91..0c97ca869 100644 --- a/hecl/lib/SteamFinder.cpp +++ b/hecl/lib/SteamFinder.cpp @@ -94,8 +94,8 @@ hecl::SystemString FindCommonSteamApp(const hecl::SystemChar* name) while (std::regex_search(begin, end, dirMatch, regSteamPath)) { std::string match = dirMatch[1].str(); - hecl::SystemStringView otherInstallDir(match); - hecl::SystemString otherAppPath = otherInstallDir.sys_str() + PATH_SEP + + hecl::SystemStringConv otherInstallDir(match); + hecl::SystemString otherAppPath = hecl::SystemString(otherInstallDir.sys_str()) + PATH_SEP + _S("steamapps") + PATH_SEP + appPath; if (!hecl::Stat(otherAppPath.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) return otherAppPath; diff --git a/hecl/lib/WideStringConvert.cpp b/hecl/lib/WideStringConvert.cpp index 870ad0637..8576250a7 100644 --- a/hecl/lib/WideStringConvert.cpp +++ b/hecl/lib/WideStringConvert.cpp @@ -4,7 +4,7 @@ namespace hecl { -std::string WideToUTF8(const std::wstring& src) +std::string WideToUTF8(std::wstring_view src) { std::string retval; retval.reserve(src.length()); @@ -22,7 +22,7 @@ std::string WideToUTF8(const std::wstring& src) return retval; } -std::string Char16ToUTF8(const std::u16string& src) +std::string Char16ToUTF8(std::u16string_view src) { std::string retval; retval.reserve(src.length()); @@ -40,11 +40,11 @@ std::string Char16ToUTF8(const std::u16string& src) return retval; } -std::wstring UTF8ToWide(const std::string& src) +std::wstring UTF8ToWide(std::string_view src) { std::wstring retval; retval.reserve(src.length()); - const utf8proc_uint8_t* buf = reinterpret_cast(src.c_str()); + const utf8proc_uint8_t* buf = reinterpret_cast(src.data()); while (*buf) { utf8proc_int32_t wc; @@ -60,11 +60,11 @@ std::wstring UTF8ToWide(const std::string& src) return retval; } -std::u16string UTF8ToChar16(const std::string& src) +std::u16string UTF8ToChar16(std::string_view src) { std::u16string retval; retval.reserve(src.length()); - const utf8proc_uint8_t* buf = reinterpret_cast(src.c_str()); + const utf8proc_uint8_t* buf = reinterpret_cast(src.data()); while (*buf) { utf8proc_int32_t wc; diff --git a/hecl/lib/hecl.cpp b/hecl/lib/hecl.cpp index dacd3315f..6a2e63724 100644 --- a/hecl/lib/hecl.cpp +++ b/hecl/lib/hecl.cpp @@ -180,7 +180,7 @@ void ResourceLock::ClearThreadRes() bool IsPathPNG(const hecl::ProjectPath& path) { - FILE* fp = hecl::Fopen(path.getAbsolutePath().c_str(), _S("rb")); + FILE* fp = hecl::Fopen(path.getAbsolutePath().data(), _S("rb")); if (!fp) return false; uint32_t buf = 0; @@ -198,10 +198,10 @@ bool IsPathPNG(const hecl::ProjectPath& path) bool IsPathBlend(const hecl::ProjectPath& path) { - const SystemChar* lastCompExt = path.getLastComponentExt(); - if (!lastCompExt || hecl::StrCmp(lastCompExt, _S("blend"))) + auto lastCompExt = path.getLastComponentExt(); + if (lastCompExt.empty() || hecl::StrCmp(lastCompExt.data(), _S("blend"))) return false; - FILE* fp = hecl::Fopen(path.getAbsolutePath().c_str(), _S("rb")); + FILE* fp = hecl::Fopen(path.getAbsolutePath().data(), _S("rb")); if (!fp) return false; uint32_t buf = 0; @@ -219,22 +219,22 @@ bool IsPathBlend(const hecl::ProjectPath& path) bool IsPathYAML(const hecl::ProjectPath& path) { - if (!hecl::StrCmp(path.getLastComponent(), _S("!catalog.yaml"))) + if (!hecl::StrCmp(path.getLastComponent().data(), _S("!catalog.yaml"))) return false; /* !catalog.yaml is exempt from general use */ - const SystemChar* lastCompExt = path.getLastComponentExt(); - if (!lastCompExt) + auto lastCompExt = path.getLastComponentExt(); + if (lastCompExt.empty()) return false; - if (!hecl::StrCmp(lastCompExt, _S("yaml")) || - !hecl::StrCmp(lastCompExt, _S("yml"))) + if (!hecl::StrCmp(lastCompExt.data(), _S("yaml")) || + !hecl::StrCmp(lastCompExt.data(), _S("yml"))) return true; return false; } -hecl::DirectoryEnumerator::DirectoryEnumerator(const hecl::SystemChar* path, Mode mode, +hecl::DirectoryEnumerator::DirectoryEnumerator(SystemStringView path, Mode mode, bool sizeSort, bool reverse, bool noHidden) { hecl::Sstat theStat; - if (hecl::Stat(path, &theStat) || !S_ISDIR(theStat.st_mode)) + if (hecl::Stat(path.data(), &theStat) || !S_ISDIR(theStat.st_mode)) return; #if _WIN32 @@ -366,7 +366,7 @@ hecl::DirectoryEnumerator::DirectoryEnumerator(const hecl::SystemChar* path, Mod #else - DIR* dir = opendir(path); + DIR* dir = opendir(path.data()); if (!dir) return; const dirent* d; @@ -495,16 +495,16 @@ hecl::DirectoryEnumerator::DirectoryEnumerator(const hecl::SystemChar* path, Mod #define FILE_MAXDIR 768 static std::pair -NameFromPath(const hecl::SystemString& path) +NameFromPath(hecl::SystemStringView path) { - hecl::SystemUTF8View utf8(path); + hecl::SystemUTF8Conv utf8(path); if (utf8.str().size() == 1 && utf8.str()[0] == '/') - return {path, "/"}; + return {hecl::SystemString(path), "/"}; size_t lastSlash = utf8.str().rfind('/'); if (lastSlash != std::string::npos) - return {path, std::string(utf8.str().cbegin() + lastSlash + 1, utf8.str().cend())}; + return {hecl::SystemString(path), std::string(utf8.str().cbegin() + lastSlash + 1, utf8.str().cend())}; else - return {path, utf8.str()}; + return {hecl::SystemString(path), std::string(utf8.str())}; } std::vector> GetSystemLocations() @@ -647,7 +647,7 @@ std::vector> GetSystemLocations() return ret; } -std::wstring Char16ToWide(const std::u16string& src) +std::wstring Char16ToWide(std::u16string_view src) { return std::wstring(src.begin(), src.end()); }