From 893a07e924e42268c546f0b08aac94fe7d50322a Mon Sep 17 00:00:00 2001 From: IlyaShurupov Date: Fri, 22 Mar 2024 14:44:26 +0300 Subject: [PATCH] RIP tp::Strings --- CMakeLists.txt | 1 - LibraryViewer/CMakeLists.txt | 2 +- LibraryViewer/private/Library.cpp | 20 +- LibraryViewer/private/Streamer.cpp | 4 +- LibraryViewer/public/GUI.hpp | 21 +- LibraryViewer/public/Library.hpp | 33 +-- Modules/.vs/slnx.sqlite | Bin 90112 -> 0 bytes Modules/private/Common.cpp | 1 + Modules/public/Archiver.hpp | 33 +-- Modules/public/Common.hpp | 2 + Objects/CMakeLists.txt | 2 +- Objects/applications/Compiler.cpp | 48 --- Objects/applications/GUI.cpp | 72 ++--- Objects/applications/GUI.h | 10 +- Objects/applications/Interpreter.cpp | 58 ---- Objects/applications/TestEntry.cpp | 89 ------ Objects/applications/test.cpp | 68 ----- Objects/private/compiler/constants.cpp | 4 +- Objects/private/compiler/expression.cpp | 12 +- Objects/private/compiler/function.cpp | 8 +- Objects/private/compiler/statement.cpp | 6 +- Objects/private/core/module.cpp | 2 - Objects/private/core/object.cpp | 33 ++- Objects/private/core/objectsave.cpp | 35 +-- Objects/private/core/scriptsection.cpp | 10 +- Objects/private/core/typegroups.cpp | 4 +- Objects/private/core/typemethods.cpp | 10 +- Objects/private/interpreter/interpreter.cpp | 6 +- Objects/private/interpreter/scopestack.cpp | 10 +- Objects/private/parser/Bindings.cpp | 2 +- Objects/private/parser/Private.hpp | 4 +- Objects/private/parser/parser.cpp | 6 +- Objects/private/primitives/boolobject.cpp | 10 +- Objects/private/primitives/classobject.cpp | 6 +- Objects/private/primitives/colorobject.cpp | 16 +- Objects/private/primitives/dictobject.cpp | 24 +- Objects/private/primitives/enumobject.cpp | 13 +- Objects/private/primitives/floatobject.cpp | 6 +- Objects/private/primitives/intobject.cpp | 6 +- Objects/private/primitives/methodobject.cpp | 2 +- Objects/private/primitives/nullobject.cpp | 2 +- Objects/private/primitives/stringobject.cpp | 26 +- Objects/private/primitives/typeobject.cpp | 14 +- Objects/public/compiler/constants.h | 10 +- Objects/public/compiler/expression.h | 24 +- Objects/public/compiler/function.h | 12 +- Objects/public/compiler/instruction.h | 6 +- Objects/public/compiler/statement.h | 14 +- Objects/public/core/object.h | 56 ++-- Objects/public/core/typegroups.h | 6 +- Objects/public/core/typemethods.h | 18 +- Objects/public/interpreter/bytecode.h | 2 +- Objects/public/interpreter/callstack.h | 6 +- Objects/public/interpreter/interpreter.h | 10 +- Objects/public/interpreter/scopestack.h | 8 +- Objects/public/parser/parser.h | 4 +- Objects/public/primitives/boolobject.h | 4 +- Objects/public/primitives/classobject.h | 10 +- Objects/public/primitives/colorobject.h | 2 +- Objects/public/primitives/dictobject.h | 14 +- Objects/public/primitives/enumobject.h | 4 +- Objects/public/primitives/floatobject.h | 4 +- Objects/public/primitives/interpreterobject.h | 2 +- Objects/public/primitives/intobject.h | 4 +- Objects/public/primitives/listobject.h | 2 +- Objects/public/primitives/methodobject.h | 2 +- Objects/public/primitives/stringobject.h | 8 +- Objects/tests/TestCore.cpp | 4 +- Objects/tests/TestParser.cpp | 8 +- Objects/tests/main.cpp | 1 - Sketch3D/CMakeLists.txt | 2 +- Sketch3D/applications/Entry.cpp | 10 - Sketch3D/private/Shader.cpp | 17 +- Sketch3D/private/Texture.cpp | 6 +- Sketch3D/public/Sketch3D.hpp | 9 +- Strings/CMakeLists.txt | 15 - Strings/private/Logging.cpp | 52 ---- Strings/private/Strings.cpp | 16 - Strings/public/Logging.hpp | 58 ---- Strings/public/StringLogic.hpp | 138 --------- Strings/public/Strings.hpp | 273 ------------------ Strings/tests/Test.cpp | 244 ---------------- Widgets/CMakeLists.txt | 2 +- Widgets/examples/ExampleGUI.hpp | 12 +- Widgets/public/ButtonWidget.hpp | 2 +- Widgets/public/LabelWidget.hpp | 4 +- Widgets/public/ScrollableWidget.hpp | 1 + Widgets/public/TextInputWidget.hpp | 8 +- Widgets/public/WidgetBase.hpp | 14 +- Widgets/public/WidgetConfig.hpp | 25 +- 90 files changed, 419 insertions(+), 1475 deletions(-) delete mode 100644 Modules/.vs/slnx.sqlite delete mode 100644 Objects/applications/Compiler.cpp delete mode 100644 Objects/applications/Interpreter.cpp delete mode 100644 Objects/applications/TestEntry.cpp delete mode 100644 Objects/applications/test.cpp delete mode 100644 Strings/CMakeLists.txt delete mode 100644 Strings/private/Logging.cpp delete mode 100644 Strings/private/Strings.cpp delete mode 100644 Strings/public/Logging.hpp delete mode 100644 Strings/public/StringLogic.hpp delete mode 100644 Strings/public/Strings.hpp delete mode 100644 Strings/tests/Test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f25dcac..61301a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ include(CMakeOptions.txt) add_subdirectory(Modules) add_subdirectory(Containers) add_subdirectory(Math) -add_subdirectory(Strings) # add_subdirectory(Language) add_subdirectory(Externals) add_subdirectory(Connection) diff --git a/LibraryViewer/CMakeLists.txt b/LibraryViewer/CMakeLists.txt index 10494b8..becb208 100644 --- a/LibraryViewer/CMakeLists.txt +++ b/LibraryViewer/CMakeLists.txt @@ -11,7 +11,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE} ./ext/) -target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets Strings) +target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets) target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS}) file(COPY "library" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}") diff --git a/LibraryViewer/private/Library.cpp b/LibraryViewer/private/Library.cpp index 4a66272..d94ea1b 100644 --- a/LibraryViewer/private/Library.cpp +++ b/LibraryViewer/private/Library.cpp @@ -13,11 +13,11 @@ using namespace tp; #define AS_BOOL trackProperty.second.evaluate_as_boolean() #define PROP(name) trackProperty.first == #name -tp::String getHome() { +std::string getHome() { const char* envVarName = "LIB_VIEW_HOME"; char* envVarValue = std::getenv(envVarName); if (envVarValue != nullptr) { - tp::String out; + std::string out; out = (int1*) (std::string(envVarValue) + "/").c_str(); return out; } else { @@ -25,11 +25,11 @@ tp::String getHome() { } } -tp::String getSongLocalPath(SongId id) { return getHome() + "tracks/" + tp::String((tp::alni) id); } +std::string getSongLocalPath(SongId id) { return getHome() + "tracks/" + std::to_string((tp::alni) id); } -SONG_FORMAT getSongFormat(const String& localPath) { - std::filesystem::path wavFormat((localPath + ".wav").read()); - std::filesystem::path flacFormat((localPath + ".flac").read()); +SONG_FORMAT getSongFormat(const std::string& localPath) { + std::filesystem::path wavFormat((localPath + ".wav").c_str()); + std::filesystem::path flacFormat((localPath + ".flac").c_str()); if (std::filesystem::exists(flacFormat)) return SONG_FORMAT::FLAC; if (std::filesystem::exists(wavFormat)) return SONG_FORMAT::WAV; return SONG_FORMAT::NONE; @@ -42,11 +42,11 @@ void Library::checkExisting() { } } -bool Library::loadJson(const String& path) { +bool Library::loadJson(const std::string& path) { LocalConnection libraryFile; Buffer libraryFileMem; - if (!libraryFile.connect(LocalConnection::Location(path.read()), LocalConnection::Type(true))) return false; + if (!libraryFile.connect(LocalConnection::Location(path.c_str()), LocalConnection::Type(true))) return false; libraryFileMem.reserve(libraryFile.size()); libraryFile.readBytes(libraryFileMem.getBuff(), libraryFile.size()); @@ -56,8 +56,8 @@ bool Library::loadJson(const String& path) { std::string err = picojson::parse(jsonNode, json); if (!err.empty()) { - printf("Given path - %s\n", path.read()); - printf("Home for library is - '%s'. Set it in the env as LIB_VIEW_HOME \n", getHome().read()); + printf("Given path - %s\n", path.c_str()); + printf("Home for library is - '%s'. Set it in the env as LIB_VIEW_HOME \n", getHome().c_str()); printf("Error parsing json library file - check your paths and files\n %s \n", err.c_str()); return false; } diff --git a/LibraryViewer/private/Streamer.cpp b/LibraryViewer/private/Streamer.cpp index f1ddcbe..2dc0a66 100644 --- a/LibraryViewer/private/Streamer.cpp +++ b/LibraryViewer/private/Streamer.cpp @@ -15,10 +15,10 @@ class Context { public: Context() = default; - bool preloadInfo(const tp::String& path, MusicStream* owner) { + bool preloadInfo(const std::string& path, MusicStream* owner) { mOwner = owner; - pFlac = drflac_open_file((path + ".flac").read(), NULL); + pFlac = drflac_open_file((path + ".flac").c_str(), NULL); if (pFlac == NULL) { return false; diff --git a/LibraryViewer/public/GUI.hpp b/LibraryViewer/public/GUI.hpp index 9455730..ae899ca 100644 --- a/LibraryViewer/public/GUI.hpp +++ b/LibraryViewer/public/GUI.hpp @@ -56,8 +56,8 @@ namespace tp { const RectF textAreaName = { textArea.x, textArea.y, textArea.z, textArea.w * 0.5f }; const RectF textAreaAuthor = { textArea.x, textArea.y + textArea.w * 0.5f, textArea.z, textArea.w * 0.5f }; - canvas.text(mTrack->mName.read(), textAreaName, 15.f, Canvas::LC, 4.f, { 0.9f, 0.9f, 0.9f, 1.f }); - canvas.text(mTrack->mArtist.read(), textAreaAuthor, 12.f, Canvas::LC, 4.f, { 0.8f, 0.8f, 0.8f, 1.f }); + canvas.text(mTrack->mName.c_str(), textAreaName, 15.f, Canvas::LC, 4.f, { 0.9f, 0.9f, 0.9f, 1.f }); + canvas.text(mTrack->mArtist.c_str(), textAreaAuthor, 12.f, Canvas::LC, 4.f, { 0.8f, 0.8f, 0.8f, 1.f }); } public: @@ -70,7 +70,7 @@ namespace tp { template class TrackInfoWidget : public Widget { struct SortType { - String text; + std::string text; bool dec = false; bool inc = false; }; @@ -140,15 +140,15 @@ namespace tp { ImGui::Text("Song Info:"); if (mTrack) { - ImGui::Text("Name : %s", mTrack->mName.read()); - ImGui::Text("Author : %s", mTrack->mArtist.read()); + ImGui::Text("Name : %s", mTrack->mName.c_str()); + ImGui::Text("Author : %s", mTrack->mArtist.c_str()); ImGui::Text("Love : %s", mTrack->mLoved ? "true" : "false"); ImGui::Text("Id : %lli", mTrack->mId); ImGui::Text("Total Time : %lli", mTrack->mTotalTime); ImGui::Text("Play Count : %lli", mTrack->mPlayCount); ImGui::Text("Skip Count : %lli", mTrack->mSkipCount); - ImGui::Text("Date Added : %s", mTrack->mDateAdded.read()); - ImGui::Text("Album : %s", mTrack->mAlbum.read()); + ImGui::Text("Date Added : %s", mTrack->mDateAdded.c_str()); + ImGui::Text("Album : %s", mTrack->mAlbum.c_str()); } else { ImGui::Text("Not Selected"); } @@ -168,7 +168,7 @@ namespace tp { sortFilter.Draw("Sorting Type"); for (int i = 0; i < items.size(); ++i) { - if (!sortFilter.PassFilter(items[i].text.read())) continue; + if (!sortFilter.PassFilter(items[i].text.c_str())) continue; ImGui::PushID(i); @@ -182,7 +182,7 @@ namespace tp { ImGui::AlignTextToFramePadding(); ImGui::SameLine(); - ImGui::Text("%s", items[i].text.read()); + ImGui::Text("%s", items[i].text.c_str()); ImGui::PopID(); } @@ -258,7 +258,8 @@ namespace tp { mSongList.mContents.clear(); for (auto track : mTracks) { - if (!mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mName.read()) && !mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mArtist.read())) { + if (!mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mName.c_str()) && + !mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mArtist.c_str())) { continue; } diff --git a/LibraryViewer/public/Library.hpp b/LibraryViewer/public/Library.hpp index 0af0abf..7b34d42 100644 --- a/LibraryViewer/public/Library.hpp +++ b/LibraryViewer/public/Library.hpp @@ -1,14 +1,13 @@ #pragma once #include "Window.hpp" -#include "Strings.hpp" typedef tp::ualni SongId; enum class SONG_FORMAT { WAV, FLAC, NONE }; -tp::String getHome(); -tp::String getSongLocalPath(SongId id); -SONG_FORMAT getSongFormat(const tp::String& path); +std::string getHome(); +std::string getSongLocalPath(SongId id); +SONG_FORMAT getSongFormat(const std::string& path); class Track { public: @@ -16,23 +15,23 @@ public: public: SongId mId = 0; - tp::String mName = "undef"; - tp::String mArtist = "undef"; - tp::String mAlbumArtist = "undef"; - tp::String mComposer = "undef"; - tp::String mAlbum = "undef"; - tp::String mGenre = "undef"; + std::string mName = "undef"; + std::string mArtist = "undef"; + std::string mAlbumArtist = "undef"; + std::string mComposer = "undef"; + std::string mAlbum = "undef"; + std::string mGenre = "undef"; tp::ualni mSize = 0; tp::ualni mTotalTime = 0; tp::ualni mYear = 0; - tp::String mDateModified = "undef"; - tp::String mDateAdded = "undef"; + std::string mDateModified = "undef"; + std::string mDateAdded = "undef"; tp::ualni mPlayCount = 0; - tp::String mPlayDate = "undef"; - tp::String mPlayDateUTC = "undef"; + std::string mPlayDate = "undef"; + std::string mPlayDateUTC = "undef"; tp::ualni mSkipCount = 0; - tp::String mSkipDate = "undef"; - tp::String mReleaseDate = "undef"; + std::string mSkipDate = "undef"; + std::string mReleaseDate = "undef"; tp::ualni mAlbumRating = 0; bool mAlbumRatingComputed = false; bool mLoved = false; @@ -46,7 +45,7 @@ public: Library() = default; public: - bool loadJson(const tp::String& path); + bool loadJson(const std::string& path); void checkExisting(); public: diff --git a/Modules/.vs/slnx.sqlite b/Modules/.vs/slnx.sqlite deleted file mode 100644 index 7b621f2557188917c5604ecb8b552dbc0710bfff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 90112 zcmeI4Piz}kdcbEi6e&?6pAto84HfYONMNz{$l`x;gA}Eyk_>TF|Zpn#rD=)+so#%heZ$V0=p=BD0)~FMYo3n4T>JRD1rh-fgaihn?v85 znaBA{Q!BSBtb7DC1rz98656Q8lPeo7?x#zi{}}JnZ|!t z@E?6G;tv6OgWp-(=W!pWnbo}%sfb0tBr>m~U(SCqzc6<%{Q2x>Ghc?d;12iwsjsJM zQ}2(f0@7a@0y9L@)3>9c*aLw*-Rbrf^-29?zdh)!tDSDYt91wcmhrLwXrtRx%Sx;4 zCxl8hvDgs#a&=w&fZsb)9nDCX$FHrbSH8)w>^Yll#!r_bp;!s4dBT3J*X z17P)ju~xcUtgR$7nfORy7gt(jvc2Q7CGTZzSs_L$}tWmz2# zyX|g|ba8~$E#|U8kDS$IJ3!(n^^>8d?vD_?ELfzWl zDQfQyZK&YLcxi&i|NWi3adLp8B#l(G3F>)`?!G$Ir2T^?Pl89Iyon^&rm?+R8a~pDNTRK$xT8o5jcixQe__?L*HQ0vIEk-5`eoyC{_;IGI;4VOH z`Sf-$6#EcIz7s3**}Twf+FQ~V|7_wRvp?n($X#qgZ4>(Tf=(<=+owgIW(gI4g@Y3m zwn|P=&JTS2+1-Ess%Fi$p89N46tkdHdnNN|| zIi>_J7val8!ludJE_sf00h2$1g>xa z<`ycG^EteqM-DhjgQLEdc$S=+X5M{XAbS9Mu5l(+H+K1lDOHu%vPoG;q_Zg@oy)HY zQc6|?HJeGOYlTcMtK#H#Dk*34IU$)($U<7qDuR@h5<*JJ=hE$tlvL7+kZY&fN=8Wu z`BXM3q?0*C$QPuvkV_{!Ni~_wWaXq#Xm|33c0m@@f`V&W%cXElsjQGvbM0g<-^nE8 zoFHeD`D{*>g=|jB3+aNK6{Lc)CM4TxCzUNI`E~~jwL9s2CY=-3+G-Z-q$F{}xF2#N zsdQ2qMO6z0K`A5?NjakkgLi4GF4@5da-B>@QVUs3Mpg2Obh?le zQfrxvkj}~pq0mv+1l*V`7c!}}RANo&f00e*l5C8%|00;m9 zAOHk_z^h7Nj^&nF^D71%?!?@z@fDXhrZ|Chf7@jtj3qeqQwIGM{T=%ESGCWeHxK{< zKmZ5;0U!VbfB+Bx0zd!=0D((PV2QiMdcL2*EpzX(W4@a)wZL7Ub$khceE)wTy2qe@ zLw|$*4E-_sF4E9L^qc5S#6`b~{&n<+(ch0AVF7pn0U!VbfB+Bx0zd!=00AHX1b_e# z@F(zV3qj@@I~#1^A7~k_$_EF*nJ<6$`n~r*nOjCd<{grQe}$#o?+jKS9~=Z|=GADB zc?)N54wR#w>d1OC5@c@REU|ywJskA+@o#}R@~_StMN5PI{XyTEHD_cMhxkVeT&2Q} z2Cj%G%DJ-uHjvPpP`?i zA4R`G^REaeP!k9M0U!VbfB+Bx0zd!=00AHX1b~2t018}Vtz-V+!s~%|@V)(i63{~6 zE!K9_ABZjmZm{md{y;<*vyS@%^Lm1H;2)T?SA-Anxv-}qk~(Xzh$PI|DG0Of z00e*l5C8%|00;m9AOHj|5dm`k59|L+G@#HGAOHk_01yBIKmZ5;0U!VbfB+Bx0zL%b z{ND!(Bmn^+00e*l5C8%|00;m9AOHk_01&uj1mOJtk_{+y2M7QGAOHk_01yBIKmZ5; z0U!VbfPfDHIRE#70!css2mk>f00e*l5C8%|00;m9AOHj|838!|zhnan-2nnX00;m9 zAOHk_01yBIKmZ5;0U+Q*0M`FLP#_5i00AHX1b_e#00KY&2mk>f00e-*B_jae|G#7d z3f%z$KmZ5;0U!VbfB+Bx0zd!=00AK2Lx8OR!y%4A+2}8#!}%}f7v}DTKcD?<=F1Ql z+~K}I_4QP3>V2PrkOTzA5D5Gz_CR1yce;H=eNsQ!Zx4FwYNy-pYTZG7)U@oTH&VuHYaPtc@xPjz?QeIGHEX%uf)M4z5V z!Yc+B55%(4#C#j#9kIr5*UFp4+C%=H_>eE|Hnz%DTIO_FIc8;W8x6@S>zY3h=LCf94R$}p@J*K%u zSyqR`ZoAtfT^wO`i@9vjBWHEl4v;uX{bZ=A`y+(zB!ZH+N}q>iWgtt$KWl@J$9I4V zl?J_|{k~T&5{{qVnhV8R*sof;U+J34QopYrmL&PH+VZMyc$r&p-sxrT?6LLOe9m14 z+n%@eX8hT1SogT+P2J<%rQG*(PLFeEkzkL5T#PH%Uz!MvQk zP`9>sirTwF8!9+5UYg+Xe}5-$oE+dNNh1|)f_h$~yRQy4Y5$BzC%@g^bGBcrAJkCCQSGPl2nNhv-Zq{jo&P5>(sZM58aPCFgMoo#awch>n_#n9QZ@-xgt#*Tp%>-0EA z=2PT#jw!**MfmcNuxawQ%id{VMH*^b?V);jtm0{r6?x6sBEK$f6n85PUOqb1JyxS( z8aw%b3&j%4?CCY#P3o$qb^DKWpEl>)MoPeGPhL6QjP&WgQDB_Y#3in4i@xouv7v2ah3Bt^0 z501O)$7HU)EoqPSCtz0{y6;WS_sik~-krxw!$|l+xp5c!O=-7QFW(ovGR3+%RU`gY z$4iV-gZIV*zF6mPOGC#TysX^h$2l;OFBx`kh!{_BQiOyFN4EBu->7YEdRnzS7tcqw zs@AQcrFBm<-(K}m&ndD|U;Wk9^;Ds&|H&u(_20hEqCML#g0QxBuq!QzWN(CU3w2kh7k$B zNZGR}iB%n^n|F+`f!@W-WPfAf%XNJsd%Ch1itWYO(}%8E#k!y9C1;FuX4*ofGvj;_)2d^ns`ZF9 zA6S-go#Qe4k}GdIS+@6%E^{1DeJW^l<3&3uFIq`ikAcba_;XBa%!f@w{J^3 zNW#A=Uw0Xm!J{?$Y$$*i49SH_O0TO2YG0B1+61K+CoAn+)kLLTrJC{Q%P15}rP$AG zyCqK2K1>(Jx%-HTug{Niy^ec^RV>{

E^nU;chiOH6jOUwO;Y&GUaZ5?S3j&lcba zw`ri3ZvVdv5rXR$ zfWwb-?R3246pWs0eESYR;Q#+Ge3Jtj1Oh++2mk>f00e*l5C8%|00;m9AaLOXVEupL z$e}?X00e*l5C8%|00;m9AOHk_01yBI7ft|v|L?+)LxVs72mk>f00e*l5C8%|00;m9 pAOHj|oB*8vUpR7T5C{MPAOHk_01yBIKmZ5;0U!VbfWU void operator<<(const Type& val) { + static_assert(!std::is_same::value); + static_assert(!tRead); static_assert(HasFunc::template AssertCombinations::assert()); if constexpr (HasFunc::template Write::value) { @@ -63,6 +65,8 @@ namespace tp { // check if type has explicit read method. if not read as bytes template void operator>>(Type& val) { + static_assert(!std::is_same::value); + static_assert(tRead); static_assert(HasFunc::template AssertCombinations::assert()); if constexpr (HasFunc::template Read::value) { @@ -75,6 +79,8 @@ namespace tp { // check if type has explicit archive method. if not read/write as bytes template void operator%(Type& val) { + static_assert(!std::is_same::value); + static_assert(HasFunc::template AssertCombinations::assert()); if constexpr (HasFunc::template Archive::value) { val.archive(*this); @@ -89,6 +95,8 @@ namespace tp { template void operator%(const Type& val) { + static_assert(!std::is_same::value); + static_assert(HasFunc::template AssertCombinations::assert()); if constexpr (HasFunc::template Archive::value) { ((Type&) val).archive(*this); @@ -132,29 +140,4 @@ namespace tp { ualni mAddress = 0; ualni mFirstNotWritten = 0; }; - - struct StringArchiver { - std::string* val; - - StringArchiver(std::string& val) { this->val = &val; } - - template - void archiveRead(tArchiver& ar) { - ualni len; - ar >> len; - val->resize(len); - for (ualni i = 0; i < len; i++) { - ar >> (*val)[i]; - } - } - - template - void archiveWrite(tArchiver& ar) const { - ualni len = val->size(); - ar << len; - for (ualni i = 0; i < len; i++) { - ar << (*val)[i]; - } - } - }; } \ No newline at end of file diff --git a/Modules/public/Common.hpp b/Modules/public/Common.hpp index d98b82e..abf9e3b 100644 --- a/Modules/public/Common.hpp +++ b/Modules/public/Common.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace tp { template @@ -49,6 +50,7 @@ namespace tp { ualni hash(uhalni bytes); ualni hash(ualni bytes); ualni hash(alnf bytes); + ualni hash(const std::string& in); template T clamp(T v, T l, T u) { diff --git a/Objects/CMakeLists.txt b/Objects/CMakeLists.txt index 0af6b78..0d4dde0 100644 --- a/Objects/CMakeLists.txt +++ b/Objects/CMakeLists.txt @@ -7,7 +7,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE}) -target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Connection LALR Strings) +target_link_libraries(${PROJECT_NAME} PUBLIC Math Connection LALR) target_compile_definitions(${PROJECT_NAME} PUBLIC USERDATA_DESTROY_FAILED_TREE_ROOTS) ### -------------------------- Applications -------------------------- ### diff --git a/Objects/applications/Compiler.cpp b/Objects/applications/Compiler.cpp deleted file mode 100644 index 1700479..0000000 --- a/Objects/applications/Compiler.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -#include "Compiler/Compiler.h" - -#include "MethodObject/MethodObject.h" -#include "log.h" -#include "primitives/primitives.h" - -using namespace osc; -using namespace tp; -using namespace obj; - -int main(int argc, char* argv[]) { - - tp::alloc_init(); - string::Initialize(); - Logger::init(); - - objects_init(); - primitives_define_types(); - MethodObject::Initialize(); - - { - Compiler compiler; - - tp::string script; - - RelAssert(argc == 2 && "Invalid Arguments"); - - script.loadFile(argv[1]); - - compiler.compile(script); - - GLog->write("oscc : compilation finished", 1); - } - - try { - MethodObject::UnInitialize(); - objects_finalize(); - primitives_uninitialize(); - - Logger::deinit(); - string::UnInitialize(); - tp::alloc_uninit(); - - } catch (...) { - tp::terminate(); - } -} \ No newline at end of file diff --git a/Objects/applications/GUI.cpp b/Objects/applications/GUI.cpp index ac85365..f46a58a 100644 --- a/Objects/applications/GUI.cpp +++ b/Objects/applications/GUI.cpp @@ -121,14 +121,14 @@ obj::Object* imgui_object_create_menu(obj::TypeGroups* type_group = NULL) { for (auto childo : *type_group->getChilds()) { if (childo->val->isGroup()) { - if (ImGui::BeginMenu((childo->key).read())) { + if (ImGui::BeginMenu((childo->key).c_str())) { newo = imgui_object_create_menu(childo->val); ImGui::EndMenu(); } continue; } - if (ImGui::Button((childo->key).read(), { 100, 0 })) { + if (ImGui::Button((childo->key).c_str(), { 100, 0 })) { if (childo->key == "null") { newo = NDO_NULL; } else { @@ -142,7 +142,7 @@ obj::Object* imgui_object_create_menu(obj::TypeGroups* type_group = NULL) { obj::ObjectsGUI::ObjectsGUI() { assert(obj::NDO && "Objects library is not initialized"); } -void obj::ObjectsGUI::cd(obj::Object* child, tp::String name) { +void obj::ObjectsGUI::cd(obj::Object* child, const std::string& name) { mActive = child; mViewStack.pushBack({ mActive, name }); obj::NDO->refinc(child); @@ -198,8 +198,8 @@ void obj::ObjectsGUI::preview(obj::Object* obj) { NDO_CASTV(obj::StringObject, obj, stringo); static char val[2048] = { " " }; if (stringo->val != val) { - assert(tp::String::Logic::calcLength(stringo->val.read()) < 2048); - tp::memCopy(val, stringo->val.read(), stringo->val.size() + 1); + assert(stringo->val.size() < 2048); + tp::memCopy(val, stringo->val.c_str(), stringo->val.size() + 1); } ImGui::InputText("", val, 2048); if (stringo->val != val) { @@ -301,7 +301,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter } // INFO - auto hd = HoverPopupBegin(tp::String((tp::alni) ip).read(), { 400, 250 }); + auto hd = HoverPopupBegin(std::to_string((tp::alni) ip).c_str(), { 400, 250 }); if (hd) { Text(info.desc); if (info.operands.len) { @@ -365,20 +365,20 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter Begin("ScopeStack"); { for (auto i = 0; i < interp.mScopeStack.mIdx; i++) { - if (TreeNode(tp::String((tp::alni) i).read())) { + if (TreeNode(std::to_string((tp::alni) i).c_str())) { auto& scope = interp.mScopeStack.mBuff[i]; if (TreeNode("Locals")) { for (auto local : scope.mLocals) { - if (Selectable(local->key.read(), false, 0, ImVec2(100, 0))) { + if (Selectable(local->key.c_str(), false, 0, ImVec2(100, 0))) { TreePop(); TreePop(); End(); return { local->val, local->key }; } - PushID(local->key.read()); + PushID(local->key.c_str()); SameLine(); preview(local->val); PopID(); @@ -389,7 +389,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter if (TreeNode("Temps")) { tp::alni idx = 0; for (auto tmp : scope.mTemps) { - if (Selectable(tp::String(idx).read(), false, 0, ImVec2(100, 0))) { + if (Selectable(std::to_string(idx).c_str(), false, 0, ImVec2(100, 0))) { TreePop(); TreePop(); End(); @@ -429,7 +429,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter if (Button(const_obj.data()->type->name)) { End(); PopID(); - return { const_obj.data(), tp::String(idx) }; + return { const_obj.data(), std::to_string(idx) }; } SameLine(); preview(const_obj.data()); @@ -531,11 +531,11 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) { if (mClipboard) { if (ImGui::Selectable("Paste")) { tp::alni idx = 1; - tp::String name_base = tp::String("clipboard ") + tp::String(mClipboard->type->name) + tp::String(" "); - tp::String name_out = name_base; + auto name_base = std::string("clipboard ") + std::string(mClipboard->type->name) + " "; + auto name_out = name_base; while (dict->presents(name_out)) { - name_out = name_base + tp::String(idx); + name_out = name_base + std::to_string(idx); idx++; } @@ -549,11 +549,11 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) { if (newo) { tp::alni idx = 1; - tp::String name_base = tp::String("new ") + tp::String(newo->type->name) + tp::String(" "); - tp::String name_out = name_base; + auto name_base = std::string("new ") + std::string(newo->type->name) + " "; + auto name_out = name_base; while (dict->presents(name_out)) { - name_out = name_base + tp::String(idx); + name_out = name_base + std::to_string(idx); idx++; } @@ -567,8 +567,8 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) { } } -void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::Object* obj, bool& popup) { - if (ImGui::BeginPopupContextItem(key.read(), ImGuiPopupFlags_MouseButtonRight)) { +void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, const std::string& key, obj::Object* obj, bool& popup) { + if (ImGui::BeginPopupContextItem(key.c_str(), ImGuiPopupFlags_MouseButtonRight)) { popup = true; ImGui::Text("%s at %x", obj->type->name, obj); @@ -578,7 +578,7 @@ void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::O } else { if (mLastNameEditObject != obj) { - tp::memCopy(mNameEdit, key.read(), key.size() + 1); + tp::memCopy(mNameEdit, key.c_str(), key.size() + 1); mLastNameEditObject = obj; } @@ -589,7 +589,7 @@ void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::O } else { obj::NDO->refinc(obj); dict->remove(key); - auto id = tp::String(mNameEdit); + auto id = std::string(mNameEdit); dict->put(id, obj); obj::NDO->destroy(obj); } @@ -626,16 +626,16 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::dictView(obj::DictObject* obj) { ImGui::TableNextRow(0, 30); ImGui::TableSetColumnIndex(0); - if (ImGui::Selectable(childo->key.read())) { + if (ImGui::Selectable(childo->key.c_str())) { ImGui::EndTable(); ImGui::EndChild(); - return { childo->val, { tp::String(childo->val->type->name) + tp::String(" ") + childo->key } }; + return { childo->val, { std::string(childo->val->type->name) + " " + childo->key } }; } dictViewEdit(obj, childo->key, childo->val, popup); ImGui::TableSetColumnIndex(1); - ImGui::PushID((int) childo->key.read()[0]); + ImGui::PushID((int) childo->key.c_str()[0]); preview(childo->val); ImGui::PopID(); } @@ -670,13 +670,13 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::listView(obj::ListObject* obj) { ImGui::TableNextRow(0, 36); ImGui::TableSetColumnIndex(0); - if (ImGui::Selectable(tp::String(idx).read())) { - out = ViewStackNode(childo.data(), { tp::String(childo->type->name) + tp::String("at") + tp::String(idx) }); + if (ImGui::Selectable(std::to_string(idx).c_str())) { + out = ViewStackNode(childo.data(), { std::string(childo->type->name) + "at" + std::to_string(idx) }); break; } { - if (ImGui::BeginPopupContextItem(tp::String(idx).read(), ImGuiPopupFlags_MouseButtonRight)) { + if (ImGui::BeginPopupContextItem(std::to_string(idx).c_str(), ImGuiPopupFlags_MouseButtonRight)) { popup = true; ImGui::Text("%s at %x", childo->type->name, childo.data()); @@ -742,12 +742,12 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::listView(obj::ListObject* obj) { return out; } -void drawStrView(tp::String& in) { +void drawStrView(std::string& in) { static char val[2048] = { " " }; if (in != val) { - assert(tp::String::Logic::calcLength(in.read()) < 2048); - tp::memCopy(val, in.read(), in.size() + 1); + assert(in.size() < 2048); + tp::memCopy(val, in.c_str(), in.size() + 1); } ImGui::BeginChild("str_edit"); @@ -800,11 +800,11 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::classView(obj::ClassObject* self ImGui::TableNextRow(0, 30); ImGui::TableSetColumnIndex(0); - if (ImGui::Selectable(childo->key.read())) { + if (ImGui::Selectable(childo->key.c_str())) { ImGui::EndTable(); ImGui::TreePop(); ImGui::EndChild(); - return { childo->val, { tp::String(childo->val->type->name) + childo->key } }; + return { childo->val, { std::string(childo->val->type->name) + childo->key } }; } dictViewEdit(dict, childo->key, childo->val, popup); @@ -824,10 +824,10 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::classView(obj::ClassObject* self if (n_methods && ImGui::TreeNodeBehavior(window->GetID("Methods"), tree_flags, "Methods", 0)) { for (auto childo : dict->getItems()) { if (childo->val->type == &obj::MethodObject::TypeData) { - if (ImGui::Selectable(childo->key.read())) { + if (ImGui::Selectable(childo->key.c_str())) { ImGui::TreePop(); ImGui::EndChild(); - return { childo->val, { tp::String(childo->val->type->name) + childo->key } }; + return { childo->val, { std::string(childo->val->type->name) + childo->key } }; } dictViewEdit(dict, childo->key, childo->val, popup); } @@ -896,10 +896,10 @@ void obj::ObjectsGUI::explorer() { ImGui::PushID((int) idx); bool go_back = false; if (childo == rev_path.last()) { - go_back = ImGui::Button(childo->data->id.read()); + go_back = ImGui::Button(childo->data->id.c_str()); ImGui::SameLine(); } else { - go_back = ImGui::Button((childo->data->id).read()); + go_back = ImGui::Button((childo->data->id).c_str()); ImGui::SameLine(); } ImGui::PopID(); diff --git a/Objects/applications/GUI.h b/Objects/applications/GUI.h index a206a70..bf62efd 100644 --- a/Objects/applications/GUI.h +++ b/Objects/applications/GUI.h @@ -6,7 +6,7 @@ #include "compiler/function.h" -#include "Strings.hpp" +#include namespace obj { @@ -18,9 +18,9 @@ namespace obj { struct ViewStackNode { obj::Object* obj; - tp::String id; + std::string id; ViewStackNode() { obj = NULL; } - ViewStackNode(obj::Object* obj, tp::String id) : obj(obj), id(id) {} + ViewStackNode(obj::Object* obj, const std::string& id) : obj(obj), id(id) {} operator bool() { return obj; } }; @@ -42,7 +42,7 @@ namespace obj { ObjectsGUI(); ~ObjectsGUI(); - void cd(obj::Object* child, tp::String name); + void cd(obj::Object* child, const std::string& name); void cdup(); void clearEvents(); @@ -67,7 +67,7 @@ namespace obj { ViewStackNode methodView(obj::MethodObject* in); ViewStackNode colorView(obj::ColorObject* in); ViewStackNode interpreterView(obj::InterpreterObject* in); - void dictViewEdit(obj::DictObject* dict, tp::String item_id, obj::Object* obj, bool& popup); + void dictViewEdit(obj::DictObject* dict, const std::string& item_id, obj::Object* obj, bool& popup); void dictViewDrawCreate(obj::DictObject* dict); }; }; diff --git a/Objects/applications/Interpreter.cpp b/Objects/applications/Interpreter.cpp deleted file mode 100644 index eb38446..0000000 --- a/Objects/applications/Interpreter.cpp +++ /dev/null @@ -1,58 +0,0 @@ - - -#include "MethodObject/methodobject.h" -#include "primitives/primitives.h" - -#include "Interpreter/Interpreter.h" - -#include "log.h" - -using namespace osc; -using namespace tp; -using namespace obj; - -int main(int argc, char* argv[]) { - tp::alloc_init(); - string::Initialize(); - Logger::init(); - - objects_init(); - primitives_define_types(); - MethodObject::Initialize(); - - { - time_ms load_start = get_time(); - RelAssert(argc == 2 && "Invalid Arguments"); - auto obj = NDO->load(argv[1]); - RelAssert(obj && "Failed to Load the File"); - RelAssert(obj->type == &MethodObject::TypeData && "Innvalid file content"); - - Interpreter interp; - NDO_CASTV(MethodObject, obj, method); - - RelAssert(method->mScript && "Innvalid file content"); - time_ms load_end = get_time(); - - GLog->write("\noscvm - execution started\n"); - time_ms exec_start = get_time(); - interp.exec(&method->mScript->mBytecode); - time_ms exec_end = get_time(); - - auto exec_time = (exec_end - exec_start); - auto load_time = (load_end - load_start); - GLog->write(sfmt("\noscvm - execution finished (Load : %f Exec : %f)", load_time, exec_time)); - } - - try { - MethodObject::UnInitialize(); - objects_finalize(); - primitives_uninitialize(); - - Logger::deinit(); - string::UnInitialize(); - tp::alloc_uninit(); - - } catch (...) { - tp::terminate(); - } -} \ No newline at end of file diff --git a/Objects/applications/TestEntry.cpp b/Objects/applications/TestEntry.cpp deleted file mode 100644 index d285e64..0000000 --- a/Objects/applications/TestEntry.cpp +++ /dev/null @@ -1,89 +0,0 @@ - - -#include "primitives/methodobject.h" -#include "primitives/primitives.h" - -#include "interpreter/interpreter.h" - -#include "compiler/function.h" - -using namespace tp; -using namespace obj; - -void TestCompile(ByteCode& bytecode) { - using namespace BCgen; - - Genereate( - bytecode, - StmScope({ - - StmDefFunc( - "main", - {}, - { - StmDefLocal("i1", ExprConst(1)), - StmDefLocal("i2", ExprConst(2)), - - // StmDefFunc("add", {"first", "second"}, { - // StmReturn(ExprAdd(ExprLocal("first"), ExprLocal("second"))) - //}), - - StmPrint(ExprLocal("i1")), - StmPrint(ExprConst(" + ")), - StmPrint(ExprLocal("i2")), - StmPrint(ExprConst(" = ")), - - StmPrint(ExprFunc("add")->ExprCall({ ExprLocal("i1"), ExprLocal("i2") })), - - StmPrint(ExprConst("\n")), - } - ), - - StmPrint(ExprBoolNot(ExprConst(0))), - - StmWhile(ExprConst(false), StmScope({ StmIgnore(ExprFunc("main")->ExprCall({})) })), - - StmIf( - ExprConst(true), - StmScope({ - // StmIgnore(ExprFunc("main")->ExprCall({})), - // StmPrint(ExprConst("true")), - }), - StmScope({ - // StmPrint(ExprConst("false")), - }) - ) }) - ); -} - -int main(int argc, char* argv[]) { - - tp::alloc_init(); - string::Initialize(); - Logger::init(); - - objects_init(); - primitives_define_types(); - MethodObject::Initialize(); - - { - Interpreter interp; - - ByteCode bytecode; - TestCompile(bytecode); - - GLog->write(" >> Exec: start \n"); - auto start = get_time(); - interp.exec(&bytecode); - auto end = get_time(); - GLog->write(sfmt("\n >> Exec time %i ms", end - start)); - } - - MethodObject::UnInitialize(); - objects_finalize(); - primitives_uninitialize(); - - Logger::deinit(); - string::UnInitialize(); - tp::alloc_uninit(); -} \ No newline at end of file diff --git a/Objects/applications/test.cpp b/Objects/applications/test.cpp deleted file mode 100644 index 1da1486..0000000 --- a/Objects/applications/test.cpp +++ /dev/null @@ -1,68 +0,0 @@ - -#include "primitives/primitives.h" - -#include "compiler/function.h" -#include "interpreter/interpreter.h" - -#include "CmdArgParser.h" - -void compile(char argc, const char* argv[]) { - tp::CmdArgParser args = { { "script", tp::CmdArgParser::Arg::FILE_IN }, { "out", "out.mo" } }; - - if (!args.parse(argc, argv, true)) { - return; - } - - auto& script_file = args.getFile("script"); - auto outpath = args.getString("out"); - - tp::string script; - script.loadFile(&script_file); - - auto method = obj::MethodObject::create(script); - - obj::NDO->save(method, outpath); -} - -void execute(char argc, const char* argv[]) { - tp::CmdArgParser args = { { "object_path", tp::CmdArgParser::Arg::STR }, { "debug", false } }; - - if (!args.parse(argc, argv, true)) { - return; - } - - auto object_path = args.getString("object_path"); - auto debug = args.getBool("debug"); - - auto obj = obj::NDO->load(object_path); - if (!obj) { - printf("Invalid Object File\n"); - return; - } - - NDO_CASTV(obj::MethodObject, obj, method); - if (!method) { - printf("Object Is Not A Method\n"); - return; - } - - obj::Interpreter interpreter; - interpreter.execAll(method); -} - -int main(char argc, const char* argv[]) { - - tp::ModuleManifest* ModuleDependencies[] = { &obj::gModuleObjects, NULL }; - tp::ModuleManifest TestModule("Test", NULL, NULL, ModuleDependencies); - if (!TestModule.initialize()) { - return 1; - } - -#ifdef OBC - compile(argc, argv); -#elif OBVM - execute(argc, argv); -#endif // OBC - - TestModule.deinitialize(); -} \ No newline at end of file diff --git a/Objects/private/compiler/constants.cpp b/Objects/private/compiler/constants.cpp index 5c7100a..9854144 100644 --- a/Objects/private/compiler/constants.cpp +++ b/Objects/private/compiler/constants.cpp @@ -60,7 +60,7 @@ ConstObject* ConstObjectsPool::get(tp::alni val) { return const_obj; } -ConstObject* ConstObjectsPool::get(tp::String val) { +ConstObject* ConstObjectsPool::get(const std::string& val) { auto idx = mStrings.presents(val); ConstObject* const_obj = NULL; if (idx) { @@ -100,7 +100,7 @@ ConstObject* ConstObjectsPool::get(bool val) { } } -ConstObject* ConstObjectsPool::addMethod(tp::String method_id, obj::Object* method) { +ConstObject* ConstObjectsPool::addMethod(const std::string& method_id, obj::Object* method) { ASSERT(NDO_CAST(MethodObject, method) && "Object is not a method object"); ASSERT(!mMethods.presents(method_id) && "Method Redefinition"); auto out = registerObject(method); diff --git a/Objects/private/compiler/expression.cpp b/Objects/private/compiler/expression.cpp index 6267724..a7f65cf 100644 --- a/Objects/private/compiler/expression.cpp +++ b/Objects/private/compiler/expression.cpp @@ -6,7 +6,7 @@ using namespace BCgen; Expression::Expression(Type type) : mType(type) {} -ExpressionChild* Expression::ExprChild(const tp::String& id) { return new ExpressionChild(this, id); } +ExpressionChild* Expression::ExprChild(const std::string& id) { return new ExpressionChild(this, id); } ExpressionCall* Expression::ExprCall(ExpressionList* args) { return new ExpressionCall(this, args); } @@ -46,13 +46,13 @@ ExpressionList::~ExpressionList() { } } -ExpressionNew::ExpressionNew(const tp::String& type) : +ExpressionNew::ExpressionNew(const std::string& type) : Expression(Type::NEW), mNewType(type) {} ExpressionNew::~ExpressionNew() = default; -ExpressionLocal::ExpressionLocal(const tp::String& id) : +ExpressionLocal::ExpressionLocal(const std::string& id) : Expression(Type::LOCAL), mLocalId(id) {} @@ -61,7 +61,7 @@ ExpressionLocal::~ExpressionLocal() = default; ExpressionSelf::ExpressionSelf() : Expression(Type::SELF) {} -ExpressionChild::ExpressionChild(Expression* mParent, const tp::String& id) : +ExpressionChild::ExpressionChild(Expression* mParent, const std::string& id) : Expression(Type::CHILD), mParent(mParent), mLocalId(id) {} @@ -79,13 +79,13 @@ ExpressionArithmetics::~ExpressionArithmetics() { delete mRight; } -ExpressionFunc::ExpressionFunc(const tp::String& id) : +ExpressionFunc::ExpressionFunc(const std::string& id) : Expression(Type::FUNC), mFuncId(id) {} ExpressionFunc::~ExpressionFunc() = default; -ExpressionConst::ExpressionConst(const tp::String& val) : +ExpressionConst::ExpressionConst(const std::string& val) : Expression(Type::CONST_EXPR), mConstType(STR), str(val) {} diff --git a/Objects/private/compiler/function.cpp b/Objects/private/compiler/function.cpp index c5c338f..8a84524 100644 --- a/Objects/private/compiler/function.cpp +++ b/Objects/private/compiler/function.cpp @@ -4,8 +4,6 @@ #include "primitives/methodobject.h" #include "primitives/primitives.h" -#include "Logging.hpp" - #include "parser/parser.h" using namespace obj; @@ -27,7 +25,7 @@ void obj::BCgen::Genereate(ByteCode& out, StatementScope* body) { root.generateByteCode(out); } -ConstObject* FunctionDefinition::defineLocal(tp::String id) { +ConstObject* FunctionDefinition::defineLocal(const std::string& id) { auto idx = mLocals.presents(id); // RelAssert(!idx && "Local Redefinition"); auto const_str_id = mConstants.get(id); @@ -35,7 +33,7 @@ ConstObject* FunctionDefinition::defineLocal(tp::String id) { return const_str_id; } -FunctionDefinition::FunctionDefinition(tp::String function_id, tp::Buffer args, FunctionDefinition* prnt) { +FunctionDefinition::FunctionDefinition(const std::string& function_id, tp::Buffer args, FunctionDefinition* prnt) { mFunctionId = function_id; inst(Instruction(OpCode::SAVE_ARGS, args.size(), 1)); for (auto id : args) { @@ -190,7 +188,7 @@ void FunctionDefinition::EvalStatement(Statement* stm) { } else { - tp::String type; + std::string type; switch (stm_local_def->mConstExpr->mConstType) { case ExpressionConst::BOOL: { diff --git a/Objects/private/compiler/statement.cpp b/Objects/private/compiler/statement.cpp index 45d2717..d4cb988 100644 --- a/Objects/private/compiler/statement.cpp +++ b/Objects/private/compiler/statement.cpp @@ -3,14 +3,14 @@ using namespace obj; using namespace BCgen; -StatementFuncDef::StatementFuncDef(const tp::String& function_id) : +StatementFuncDef::StatementFuncDef(const std::string& function_id) : Statement(Type::DEF_FUNC) { mFunctionId = function_id; } StatementFuncDef::~StatementFuncDef() { delete mStatements; } -StatementLocalDef::StatementLocalDef(const tp::String& id, Expression* value) : +StatementLocalDef::StatementLocalDef(const std::string& id, Expression* value) : mLocalId(id), Statement(Type::DEF_LOCAL) { @@ -96,7 +96,7 @@ StatementIgnore::StatementIgnore(Expression* expr) : StatementIgnore::~StatementIgnore() { delete mExpr; } -StatementClassDef::StatementClassDef(const tp::String& class_id, StatementScope* scope) : +StatementClassDef::StatementClassDef(const std::string& class_id, StatementScope* scope) : Statement(Type::CLASS_DEF) { mClassId = class_id; mScope = scope; diff --git a/Objects/private/core/module.cpp b/Objects/private/core/module.cpp index faf2e44..42d0861 100644 --- a/Objects/private/core/module.cpp +++ b/Objects/private/core/module.cpp @@ -76,8 +76,6 @@ static void deinit(const tp::ModuleManifest*) { } static tp::ModuleManifest* sModuleDependencies[] = { - // &tp::gModuleCompressor, - &tp::gModuleStrings, nullptr }; diff --git a/Objects/private/core/object.cpp b/Objects/private/core/object.cpp index 892e2d7..b86b8ad 100644 --- a/Objects/private/core/object.cpp +++ b/Objects/private/core/object.cpp @@ -11,10 +11,29 @@ namespace obj { + void save_string(ArchiverOut& file, const std::string& string) { + file << string.size(); + file.writeBytes(string.c_str(), string.size()); + } + + tp::ualni save_string_size(const std::string& string) { + return string.size() + sizeof(string.size()); + } + + void load_string(ArchiverIn& file, std::string& out) { + typeof(out.size()) size; + file >> size; + auto buff = new char[size + 1]; + file.readBytes(buff, size); + buff[size] = 0; + out = buff; + delete[] buff; + } + Object* ObjectMemAllocate(const ObjectType* type); void ObjectMemDeallocate(Object* in); - objects_api* NDO = NULL; + objects_api* NDO = nullptr; void hierarchy_copy(Object* self, const Object* in, const ObjectType* type); void hierarchy_construct(Object* self, const ObjectType* type); @@ -36,7 +55,7 @@ namespace obj { type->type_methods.init(); } - Object* objects_api::create(const tp::String& name) { + Object* objects_api::create(const std::string& name) { MODULE_SANITY_CHECK(gModuleObjects); const ObjectType* type = types.get(name); @@ -44,7 +63,7 @@ namespace obj { Object* obj_instance = ObjectMemAllocate(type); if (!obj_instance) { - return NULL; + return nullptr; } hierarchy_construct(obj_instance, obj_instance->type); @@ -69,7 +88,7 @@ namespace obj { Object* objects_api::copy(Object* self, const Object* in) { if (self->type != in->type) { - return NULL; + return nullptr; } hierarchy_copy(self, in, self->type); @@ -110,7 +129,7 @@ namespace obj { } } - void objects_api::set(Object* self, tp::String val) { + void objects_api::set(Object* self, const std::string& val) { if (self->type->convesions && self->type->convesions->from_string) { self->type->convesions->from_string(self, val); return; @@ -134,7 +153,7 @@ namespace obj { return true; } - tp::String objects_api::toString(Object* self) { + std::string objects_api::toString(Object* self) { DEBUG_ASSERT(self->type->convesions && self->type->convesions->to_string); return self->type->convesions->to_string(self); } @@ -217,6 +236,6 @@ namespace obj { } typeiter = typeiter->base; } - return NULL; + return nullptr; } }; diff --git a/Objects/private/core/objectsave.cpp b/Objects/private/core/objectsave.cpp index d490cc8..ca0656f 100644 --- a/Objects/private/core/objectsave.cpp +++ b/Objects/private/core/objectsave.cpp @@ -17,8 +17,8 @@ namespace obj { ObjectsFileHeader(bool default_val = true) { if (default_val) { - tp::memCopy(&name, "objects", tp::String::Logic::calcLength("objects") + 1); - tp::memCopy(&version, "0", tp::String::Logic::calcLength("0") + 1); + tp::memCopy(&name, "objects", 8); + tp::memCopy(&version, "0", 2); } } }; @@ -26,10 +26,10 @@ namespace obj { Object* ObjectMemAllocate(const ObjectType* type) { ObjectMemHead* memh = (ObjectMemHead*) malloc(type->size + sizeof(ObjectMemHead)); if (!memh) { - return NULL; + return nullptr; } - memh->down = NULL; + memh->down = nullptr; memh->flags = 0; memh->refc = (tp::alni) 1; @@ -235,10 +235,11 @@ namespace obj { // save file object header ObjectFileHead ofh = { 0, getrefc(in) }; ndf << ofh; - ndf << tp::String(in->type->name); + + save_string(ndf, in->type->name); // allocate for object file header - ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + tp::SaveSizeCounter::calc(tp::String(in->type->name))); + ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + save_string_size(in->type->name)); // calc max size needed for saving all hierarchy of types tp::alni file_alloc_size = objsize_file_util(in, in->type); @@ -281,14 +282,14 @@ namespace obj { ObjectFileHead ofh; ndf >> ofh; - tp::String type_name; - ndf >> type_name; + std::string type_name; + load_string(ndf, type_name); const ObjectType* object_type = NDO->types.get(type_name); Object* out = ObjectMemAllocate(object_type); if (!out) { - return NULL; + return nullptr; } setrefc(out, 0); @@ -312,8 +313,8 @@ namespace obj { return out; } - bool objects_api::save(Object* in, tp::String path, bool compressed) { - ArchiverOut ndf(path.read()); + bool objects_api::save(Object* in, const std::string& path, bool compressed) { + ArchiverOut ndf(path.c_str()); if (!ndf.isOpened()) { return false; @@ -365,22 +366,22 @@ namespace obj { return true; } - Object* objects_api::load(tp::String path) { + Object* objects_api::load(const std::string& path) { /* auto temp_file_name = path + ".unz"; bool unz_res = tp::decompressF2F(path.cstr(), temp_file_name.cstr()); if (!unz_res) { - return NULL; + return nullptr; } File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD); */ - ArchiverIn ndf(path.read()); + ArchiverIn ndf(path.c_str()); if (!ndf.isOpened()) { - return NULL; + return nullptr; } // check for compatibility @@ -390,7 +391,7 @@ namespace obj { ndf >> loaded_header; if (!tp::memEqual(¤t_header, &loaded_header, sizeof(ObjectsFileHeader))) { - return NULL; + return nullptr; } ndf.setAddress(0); @@ -423,7 +424,7 @@ namespace obj { /* ndf.close(); - if (unz_res == NULL) { + if (unz_res == nullptr) { File::remove(temp_file_name.cstr()); } */ diff --git a/Objects/private/core/scriptsection.cpp b/Objects/private/core/scriptsection.cpp index 31df1f5..c6ee37c 100644 --- a/Objects/private/core/scriptsection.cpp +++ b/Objects/private/core/scriptsection.cpp @@ -3,7 +3,7 @@ using namespace obj; -ScriptSection* gScriptSection = NULL; +ScriptSection* gScriptSection = nullptr; struct script_data_head { tp::alni refc = 0; @@ -19,7 +19,7 @@ Script* ScriptSection::createScript() { auto out = (Script*) (sdhead + 1); if (!sdhead) { - return NULL; + return nullptr; } sdhead->refc = 1; @@ -215,7 +215,7 @@ Script* ScriptSection::get_scritp_from_file_adress(tp::alni file_adress) { return iter.data(); } } - return NULL; + return nullptr; } ScriptSection::~ScriptSection() { @@ -229,8 +229,8 @@ obj::save_load_callbacks ScriptSection::slcb_script_section = { .pre_save = (obj::pre_save_callback*) ScriptSection::save_script_table_to_file, .size = (obj::slcb_size_callback*) ScriptSection::save_script_table_to_file_size, .pre_load = (obj::pre_load_callback*) ScriptSection::load_script_table_from_file, - .post_save = NULL, - .post_load = NULL, + .post_save = nullptr, + .post_load = nullptr, }; void ScriptSection::initialize() { diff --git a/Objects/private/core/typegroups.cpp b/Objects/private/core/typegroups.cpp index 2c89f24..99d2146 100644 --- a/Objects/private/core/typegroups.cpp +++ b/Objects/private/core/typegroups.cpp @@ -15,7 +15,7 @@ obj::TypeGroups::TypeGroups(bool is_group) : if (is_group) { new (&childs) Dict(); } else { - type = NULL; + type = nullptr; } } @@ -43,7 +43,7 @@ void obj::TypeGroups::addType(ObjectType* type, tp::InitialierList return; } - TypeGroups* group = NULL; + TypeGroups* group = nullptr; tp::alni index = 0; for (auto dir : path) { diff --git a/Objects/private/core/typemethods.cpp b/Objects/private/core/typemethods.cpp index 57d728b..d081e11 100644 --- a/Objects/private/core/typemethods.cpp +++ b/Objects/private/core/typemethods.cpp @@ -14,7 +14,7 @@ TypeMethod obj::gDefaultTypeMethods[] = { .nameid = "type", .descr = "retrieves typeobject", .exec = [](const TypeMethod* tm) { tm->ret.obj = TypeObject::create(tm->self->type); }, - .ret = { "typeobject", NULL }, + .ret = { "typeobject", nullptr }, }, { .nameid = "to_str", @@ -25,7 +25,7 @@ TypeMethod obj::gDefaultTypeMethods[] = { tm->ret.obj = StringObject::create(NDO->toString(tm->self)); } }, - .ret = { "string object", NULL }, + .ret = { "string object", nullptr }, }, { .nameid = "to_float", @@ -36,11 +36,11 @@ TypeMethod obj::gDefaultTypeMethods[] = { tm->ret.obj = FloatObject::create(NDO->toFloat(tm->self)); } }, - .ret = { "string object", NULL }, + .ret = { "string object", nullptr }, }, }; -tp::int2 TypeMethods::presents(tp::String id) const { +tp::int2 TypeMethods::presents(const std::string& id) const { for (tp::int2 idx = 0; idx < mNMethods; idx++) { if (id == methods[idx]->nameid) { return idx; @@ -58,7 +58,7 @@ tp::int2 TypeMethods::presents(tp::String id) const { return -1; } -TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, tp::String id) { +TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, const std::string& id) { tp::int2 depth = 0; tp::int2 idx = 0; diff --git a/Objects/private/interpreter/interpreter.cpp b/Objects/private/interpreter/interpreter.cpp index b59235e..ca9b2ab 100644 --- a/Objects/private/interpreter/interpreter.cpp +++ b/Objects/private/interpreter/interpreter.cpp @@ -3,8 +3,6 @@ #include "primitives/primitives.h" -#include "Logging.hpp" - #include "Timing.hpp" using namespace obj; @@ -224,9 +222,9 @@ void Interpreter::stepBytecodeIn() { auto obj = mOperandsStack.getOperand(); if (obj->type->convesions && obj->type->convesions->to_string) { auto str = NDO->toString(obj); - gLogger->write(str, true); + printf("%s\n", str.c_str()); } else { - gLogger->write(String(obj->type->name), true); + printf("Object with type '%s' has no string representation.\n", obj->type->name); } break; } diff --git a/Objects/private/interpreter/scopestack.cpp b/Objects/private/interpreter/scopestack.cpp index 6901f23..d6a12ad 100644 --- a/Objects/private/interpreter/scopestack.cpp +++ b/Objects/private/interpreter/scopestack.cpp @@ -12,9 +12,9 @@ Scope::~Scope() { } } -obj::Object* ScopeStack::getLocalUtil(Scope& scope, tp::String* id) { +obj::Object* ScopeStack::getLocalUtil(Scope& scope, const std::string& id) { - auto idx = scope.mLocals.presents(*id); + auto idx = scope.mLocals.presents(id); if (idx) { return scope.mLocals.getSlotVal(idx); @@ -62,7 +62,7 @@ void ScopeStack::addTempReturn(obj::Object* ret) { } } -void ScopeStack::addLocal(obj::Object* local, tp::String id) { +void ScopeStack::addLocal(obj::Object* local, const std::string& id) { DEBUG_ASSERT(mIdx != 0 && "No scope given"); Scope::ObjDict& locals = mBuff[mIdx - 1].mLocals; auto idx = locals.presents(id); @@ -73,9 +73,9 @@ void ScopeStack::addLocal(obj::Object* local, tp::String id) { locals.put(id, local); } -obj::Object* ScopeStack::getLocal(tp::String& str) { +obj::Object* ScopeStack::getLocal(const std::string& str) { mIterIdx = mIdx - 1; - return getLocalUtil(mBuff[mIdx - 1], &str); + return getLocalUtil(mBuff[mIdx - 1], str); } Scope* ScopeStack::getCurrentScope() { return &mBuff[mIdx - 1]; } diff --git a/Objects/private/parser/Bindings.cpp b/Objects/private/parser/Bindings.cpp index 02c6402..78da434 100644 --- a/Objects/private/parser/Bindings.cpp +++ b/Objects/private/parser/Bindings.cpp @@ -82,7 +82,7 @@ static UserData id_list_append(const UserData* start, const Node* nodes, size_t) } static UserData id_list_create(const UserData*, const Node* nodes, size_t) { - return new tp::Buffer({ (char*) nodes[0].lexeme().c_str() }); + return new tp::Buffer({ (char*) nodes[0].lexeme().c_str() }); } static UserData expr_function(const UserData* start, const Node*, size_t) { diff --git a/Objects/private/parser/Private.hpp b/Objects/private/parser/Private.hpp index d5c3f36..8299aae 100644 --- a/Objects/private/parser/Private.hpp +++ b/Objects/private/parser/Private.hpp @@ -12,7 +12,7 @@ struct UserNode { obj::BCgen::Expression* expression = nullptr; obj::BCgen::Statement* statement = nullptr; - tp::Buffer* arguments = nullptr; + tp::Buffer* arguments = nullptr; UserNode(obj::BCgen::Statement* stm) : statement(stm) {} @@ -20,7 +20,7 @@ struct UserNode { UserNode(obj::BCgen::Expression* expr) : expression(expr) {} - UserNode(tp::Buffer* argList) : + UserNode(tp::Buffer* argList) : arguments(argList) {} UserNode() = default; diff --git a/Objects/private/parser/parser.cpp b/Objects/private/parser/parser.cpp index 0d1619b..6e83bac 100644 --- a/Objects/private/parser/parser.cpp +++ b/Objects/private/parser/parser.cpp @@ -22,7 +22,7 @@ public: virtual void lalr_vprintf(const char* format, va_list args) override { printf(format, args); } }; -Parser::Result Parser::parse(const tp::String& stream) { +Parser::Result Parser::parse(const std::string& stream) { CustomErrorPolicy errorPolicy; @@ -30,8 +30,8 @@ Parser::Result Parser::parse(const tp::String& stream) { bind(parser); - std::string streamStd(stream.read()); - streamStd += "\n"; // for windows os to make happy + std::string streamStd(stream.c_str()); + streamStd += "\n"; // for windows os to be happy ASSERT(parser.valid()); diff --git a/Objects/private/primitives/boolobject.cpp b/Objects/private/primitives/boolobject.cpp index 4521502..3d04dbe 100644 --- a/Objects/private/primitives/boolobject.cpp +++ b/Objects/private/primitives/boolobject.cpp @@ -18,9 +18,11 @@ void BoolObject::from_int(BoolObject* self, alni in) { self->val = in; } void BoolObject::from_float(BoolObject* self, alnf in) { self->val = alni(bool(in)); } -void BoolObject::from_string(BoolObject* self, String in) { self->val = alni(bool(in)); } +void BoolObject::from_string(BoolObject* self, const std::string& in) { + self->val = in == "true" || in == "True"; +} -String BoolObject::to_string(BoolObject* self) { return String(bool(self->val)); } +std::string BoolObject::to_string(BoolObject* self) { return std::to_string(bool(self->val)); } alni BoolObject::to_int(BoolObject* self) { return self->val; } @@ -42,9 +44,9 @@ struct ObjectTypeConversions BoolObjectTypeConversions = { }; struct obj::ObjectType obj::BoolObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = (object_constructor) BoolObject::constructor, - .destructor = NULL, + .destructor = nullptr, .copy = (object_copy) BoolObject::copy, .size = sizeof(BoolObject), .name = "bool", diff --git a/Objects/private/primitives/classobject.cpp b/Objects/private/primitives/classobject.cpp index 87f8d77..425a4ba 100644 --- a/Objects/private/primitives/classobject.cpp +++ b/Objects/private/primitives/classobject.cpp @@ -17,9 +17,9 @@ void ClassObject::copy(ClassObject* self, const ClassObject* blueprint) { NDO->c void ClassObject::destructor(ClassObject* self) { NDO->destroy(self->members); } -void ClassObject::addMember(Object* obj, tp::String id) { members->put(id, obj); } +void ClassObject::addMember(Object* obj, const std::string& id) { members->put(id, obj); } -void ClassObject::createMember(tp::String type, tp::String id) { +void ClassObject::createMember(const std::string& type, const std::string& id) { auto newo = NDO->create(type); members->put(id, newo); } @@ -55,7 +55,7 @@ alni allocated_size_recursive(ClassObject* self) { return out; } -struct ObjectType ClassObject::TypeData = { .base = NULL, +struct ObjectType ClassObject::TypeData = { .base = nullptr, .constructor = (object_constructor) ClassObject::constructor, .destructor = (object_destructor) ClassObject::destructor, .copy = (object_copy) ClassObject::copy, diff --git a/Objects/private/primitives/colorobject.cpp b/Objects/private/primitives/colorobject.cpp index a9bab7f..c29a95c 100644 --- a/Objects/private/primitives/colorobject.cpp +++ b/Objects/private/primitives/colorobject.cpp @@ -17,7 +17,7 @@ void ColorObject::from_int(ColorObject* self, alni in) { self->mCol = tp::RGBA(( void ColorObject::from_float(ColorObject* self, alnf in) { NDO_CAST(ColorObject, self)->mCol = tp::RGBA(tp::clamp((tp::halnf) in, 0.f, 1.f)); } -String ColorObject::to_string(ColorObject* self) { +std::string ColorObject::to_string(ColorObject* self) { // auto &col = NDO_CAST(ColorObject, self)->mCol; // return tp::sfmt("%i:%i:%i:%i", (tp::alni) (col.r * 255), (tp::alni)(col.g * 255), (tp::alni)(col.b * 255), (tp::alni)(col.a * 255)); // TODO : implement @@ -33,10 +33,10 @@ static void load(ArchiverIn& file_self, ColorObject* self) { file_self >> self-> struct ObjectTypeConversions ColorObjectTypeConversions = { .from_int = (object_from_int) ColorObject::from_int, .from_float = (object_from_float) ColorObject::from_float, - .from_string = NULL, + .from_string = nullptr, .to_string = (object_to_string) ColorObject::to_string, - .to_int = NULL, - .to_float = NULL, + .to_int = nullptr, + .to_float = nullptr, }; void sub(ColorObject* self, ColorObject* in) { self->mCol = in->mCol - self->mCol; } @@ -46,14 +46,14 @@ void add(ColorObject* self, ColorObject* in) { self->mCol = in->mCol + self->mCo struct ObjectTypeAriphmetics ColorObject::TypeAriphm = { .add = (object_add) add, .sub = (object_sub) sub, - .mul = (object_mul) NULL, - .div = (object_div) NULL, + .mul = (object_mul) nullptr, + .div = (object_div) nullptr, }; struct obj::ObjectType obj::ColorObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = ColorObject::constructor, - .destructor = NULL, + .destructor = nullptr, .copy = (object_copy) ColorObject::copy, .size = sizeof(ColorObject), .name = "RGBA", diff --git a/Objects/private/primitives/dictobject.cpp b/Objects/private/primitives/dictobject.cpp index 6af7a9a..c3028e5 100644 --- a/Objects/private/primitives/dictobject.cpp +++ b/Objects/private/primitives/dictobject.cpp @@ -8,7 +8,7 @@ using namespace tp; void DictObject::constructor(Object* self) { NDO_CASTV(DictObject, self, dict); - new (&dict->items) Map(); + new (&dict->items) Map(); } void DictObject::copy(Object* in, const Object* target) { @@ -41,7 +41,7 @@ alni DictObject::save_size(DictObject* self) { for (auto item : self->items) { // string length - save_size += tp::SaveSizeCounter::calc(item->key); + save_size += save_string_size(item->key); // object file adress save_size += sizeof(alni); @@ -63,12 +63,12 @@ void DictObject::save(DictObject* self, ArchiverOut& file_self) { file_self << ndo_object_adress; // item key - file_self << item->key; + save_string(file_self, item->key); } } void DictObject::load(ArchiverIn& file_self, DictObject* self) { - new (&self->items) tp::Map(); + new (&self->items) tp::Map(); alni len; file_self >> len; @@ -81,8 +81,8 @@ void DictObject::load(ArchiverIn& file_self, DictObject* self) { Object* val = NDO->load(file_self, ndo_object_adress); // read key value - String key; - file_self >> key; + std::string key; + load_string(file_self, key); // add to dictinary self->put(key, val); @@ -118,13 +118,13 @@ alni DictObject::allocated_size_recursive(DictObject* self) { return out; } -void DictObject::put(tp::String str, Object* obj) { +void DictObject::put(const std::string& str, Object* obj) { DEBUG_ASSERT(obj); NDO->refinc(obj); items.put(str, obj); } -void DictObject::remove(tp::String str) { +void DictObject::remove(const std::string& str) { auto idx = items.presents(str); if (idx) { NDO->destroy(items.getSlotVal(idx)); @@ -132,13 +132,13 @@ void DictObject::remove(tp::String str) { } } -Object* DictObject::get(tp::String str) { return items.get(str); } +Object* DictObject::get(const std::string& str) { return items.get(str); } -tp::Map::Idx DictObject::presents(tp::String str) { return items.presents(str); } +tp::Map::Idx DictObject::presents(const std::string& str) { return items.presents(str); } -Object* DictObject::getSlotVal(tp::Map::Idx idx) { return items.getSlotVal(idx); } +Object* DictObject::getSlotVal(tp::Map::Idx idx) { return items.getSlotVal(idx); } -const tp::Map& DictObject::getItems() const { return items; } +const tp::Map& DictObject::getItems() const { return items; } static auto tm_get = TypeMethod{ .nameid = "get", .descr = "gets the object", diff --git a/Objects/private/primitives/enumobject.cpp b/Objects/private/primitives/enumobject.cpp index 4e0d3bc..9669bc1 100644 --- a/Objects/private/primitives/enumobject.cpp +++ b/Objects/private/primitives/enumobject.cpp @@ -2,6 +2,7 @@ #include "primitives/enumobject.h" #include +#include using namespace obj; using namespace tp; @@ -37,7 +38,7 @@ void obj::EnumObject::init(tp::InitialierList list) { alni* entry = entries; for (auto elem : list) { - alni len = tp::String::Logic::calcLength(elem); + alni len = std::strlen(elem); if (len > ENV_ALNI_SIZE_B - 1) len = ENV_ALNI_SIZE_B - 1; tp::memCopy(entry, elem, len); @@ -69,11 +70,11 @@ void EnumObject::from_float(EnumObject* self, alnf in) { } } -void EnumObject::from_string(EnumObject* self, String in) { +void EnumObject::from_string(EnumObject* self, const std::string& in) { if (self->entries) { alni* entry = self->entries; for (uhalni i = 0; i < self->nentries; i++) { - if (tp::String::Logic::isEqualLogic((const char*) entry, in.read())) { + if (in == ((const char*) entry)) { self->active = i; } entry += 1; @@ -81,12 +82,12 @@ void EnumObject::from_string(EnumObject* self, String in) { } } -String EnumObject::to_string(EnumObject* self) { +std::string EnumObject::to_string(EnumObject* self) { if (!self->entries) { - return tp::String(); + return {}; } auto val = (const char*) (&self->entries[self->active]); - return String(val); + return val; } alni EnumObject::to_int(EnumObject* self) { diff --git a/Objects/private/primitives/floatobject.cpp b/Objects/private/primitives/floatobject.cpp index e49a0b0..15e8f0a 100644 --- a/Objects/private/primitives/floatobject.cpp +++ b/Objects/private/primitives/floatobject.cpp @@ -16,9 +16,11 @@ void FloatObject::from_int(FloatObject* self, alni in) { self->val = alnf(in); } void FloatObject::from_float(FloatObject* self, alnf in) { self->val = in; } -void FloatObject::from_string(FloatObject* self, String in) { self->val = alnf(in); } +void FloatObject::from_string(FloatObject* self, const std::string& in) { + self->val = std::stof(in); +} -String FloatObject::to_string(FloatObject* self) { return String(self->val); } +std::string FloatObject::to_string(FloatObject* self) { return std::to_string(self->val); } alni FloatObject::to_int(FloatObject* self) { return alni(self->val); } diff --git a/Objects/private/primitives/intobject.cpp b/Objects/private/primitives/intobject.cpp index a01192b..c4e7c4b 100644 --- a/Objects/private/primitives/intobject.cpp +++ b/Objects/private/primitives/intobject.cpp @@ -17,9 +17,11 @@ void IntObject::from_int(Object* self, alni in) { NDO_CAST(IntObject, self)->val void IntObject::from_float(Object* self, alnf in) { NDO_CAST(IntObject, self)->val = (alni) in; } -void IntObject::from_string(Object* self, String in) { NDO_CAST(IntObject, self)->val = alni(in); } +void IntObject::from_string(Object* self, const std::string& in) { + NDO_CAST(IntObject, self)->val = std::stol(in); +} -String IntObject::to_string(Object* self) { return String(NDO_CAST(IntObject, self)->val); } +std::string IntObject::to_string(Object* self) { return std::to_string(NDO_CAST(IntObject, self)->val); } alni IntObject::to_int(Object* self) { return alni(NDO_CAST(IntObject, self)->val); } diff --git a/Objects/private/primitives/methodobject.cpp b/Objects/private/primitives/methodobject.cpp index b845995..975a4d7 100644 --- a/Objects/private/primitives/methodobject.cpp +++ b/Objects/private/primitives/methodobject.cpp @@ -54,7 +54,7 @@ void MethodObject::UnInitialize() { obj::ScriptSection::uninitialize(); } void MethodObject::compile() { BCgen::Compile(this); } -MethodObject* MethodObject::create(tp::String script) { +MethodObject* MethodObject::create(const std::string& script) { auto out = (MethodObject*) NDO->create(MethodObject::TypeData.name); out->mScript->mReadable->val = script; out->compile(); diff --git a/Objects/private/primitives/nullobject.cpp b/Objects/private/primitives/nullobject.cpp index 071a740..2cc4bde 100644 --- a/Objects/private/primitives/nullobject.cpp +++ b/Objects/private/primitives/nullobject.cpp @@ -16,7 +16,7 @@ void NullObject::uninit() { void NullObject::destructor(Object* self) { DEBUG_ASSERT(uninit_flag && "Only one the instance of NullObject exists and thus it can't be destroyed"); } -String to_string(NullObject* self) { return "NULL"; } +std::string to_string(NullObject* self) { return "NULL"; } alni to_int(NullObject* self) { return 0; } diff --git a/Objects/private/primitives/stringobject.cpp b/Objects/private/primitives/stringobject.cpp index 72e55f0..7922df0 100644 --- a/Objects/private/primitives/stringobject.cpp +++ b/Objects/private/primitives/stringobject.cpp @@ -5,13 +5,13 @@ using namespace obj; using namespace tp; -void StringObject::constructor(Object* self) { new (&NDO_CAST(StringObject, self)->val) String(); } +void StringObject::constructor(Object* self) { new (&NDO_CAST(StringObject, self)->val) std::string(); } -void StringObject::destructor(StringObject* self) { self->val.~String(); } +void StringObject::destructor(StringObject* self) { self->val.~basic_string(); } void StringObject::copy(Object* self, const Object* in) { NDO_CAST(StringObject, self)->val = NDO_CAST(StringObject, in)->val; } -StringObject* StringObject::create(String in) { +StringObject* StringObject::create(const std::string& in) { NDO_CASTV(StringObject, NDO->create("str"), out)->val = in; return out; } @@ -24,23 +24,27 @@ void StringObject::from_float(StringObject* self, alnf in) { // self->val = in; } -void StringObject::from_string(StringObject* self, String in) { +void StringObject::from_string(StringObject* self, const std::string& in) { // self->val = in; } -String StringObject::to_string(StringObject* self) { return self->val; } +std::string StringObject::to_string(StringObject* self) { return self->val; } -alni StringObject::to_int(StringObject* self) { return alni(self->val); } +alni StringObject::to_int(StringObject* self) { return std::stoi(self->val); } -alnf StringObject::to_float(StringObject* self) { return alnf(self->val); } +alnf StringObject::to_float(StringObject* self) { return std::stof(self->val); } -static alni save_size(StringObject* self) { return tp::SaveSizeCounter::calc(self->val); } +static alni save_size(StringObject* self) { + return save_string_size(self->val); +} -static void save(StringObject* self, ArchiverOut& file_self) { file_self << self->val; } +static void save(StringObject* self, ArchiverOut& file_self) { + save_string(file_self, self->val); +} static void load(ArchiverIn& file_self, StringObject* self) { - new (&self->val) tp::String(); - file_self >> self->val; + new (&self->val) std::string(); + load_string(file_self, self->val); } alni allocated_size(StringObject* self) { diff --git a/Objects/private/primitives/typeobject.cpp b/Objects/private/primitives/typeobject.cpp index c91a5c7..4ffda33 100644 --- a/Objects/private/primitives/typeobject.cpp +++ b/Objects/private/primitives/typeobject.cpp @@ -12,18 +12,16 @@ TypeObject* TypeObject::create(const ObjectType* type) { } static alni save_size(TypeObject* self) { - tp::String const nameid(self->mTypeRef->name); - return nameid.size() + sizeof(nameid.size()); + return save_string_size(self->mTypeRef->name); } static void save(TypeObject* self, ArchiverOut& file_self) { - tp::String const nameid(self->mTypeRef->name); - file_self << nameid; + save_string(file_self, self->mTypeRef->name); } static void load(ArchiverIn& file_self, TypeObject* self) { - tp::String nameid; - file_self >> nameid; + std::string nameid; + load_string(file_self, nameid); auto idx = NDO->types.presents(nameid); @@ -36,7 +34,7 @@ static void load(ArchiverIn& file_self, TypeObject* self) { static alni allocated_size(TypeObject* self) { return sizeof(alni); } -static void from_string(TypeObject* self, tp::String in) { +static void from_string(TypeObject* self, const std::string& in) { auto idx = NDO->types.presents(in); if (idx) { @@ -46,7 +44,7 @@ static void from_string(TypeObject* self, tp::String in) { } } -static String to_string(TypeObject* self) { return self->mTypeRef->name; } +static std::string to_string(TypeObject* self) { return self->mTypeRef->name; } bool comparator(TypeObject* left, TypeObject* right) { return left->mTypeRef == right->mTypeRef; } diff --git a/Objects/public/compiler/constants.h b/Objects/public/compiler/constants.h index 5c8d32b..f6509df 100644 --- a/Objects/public/compiler/constants.h +++ b/Objects/public/compiler/constants.h @@ -9,7 +9,7 @@ namespace obj { class ConstObject { public: - obj::Object* mObj = NULL; + obj::Object* mObj = nullptr; tp::alni mConstIdx = 0; ConstObject(); @@ -19,8 +19,8 @@ namespace obj { class ConstObjectsPool { public: - tp::Map mMethods; - tp::Map mStrings; + tp::Map mMethods; + tp::Map mStrings; tp::Map mIntegers; tp::Map mFloats; ConstObject mBoolTrue; @@ -30,11 +30,11 @@ namespace obj { tp::alni mTotalObjects = 0; ConstObject* get(tp::alni val); - ConstObject* get(tp::String val); + ConstObject* get(const std::string& val); ConstObject* get(tp::alnf val); ConstObject* get(bool val); - ConstObject* addMethod(tp::String method_id, obj::Object* method); + ConstObject* addMethod(const std::string& method_id, obj::Object* method); ConstObject* registerObject(obj::Object* obj); void save(tp::Buffer& out); diff --git a/Objects/public/compiler/expression.h b/Objects/public/compiler/expression.h index 146e2b1..5de8b9c 100644 --- a/Objects/public/compiler/expression.h +++ b/Objects/public/compiler/expression.h @@ -1,7 +1,7 @@ #pragma once -#include "Strings.hpp" +#include #include "Buffer.hpp" #include "interpreter/opcodes.h" @@ -28,7 +28,7 @@ namespace obj::BCgen { explicit Expression(Type type); virtual ~Expression() = default; - struct ExpressionChild* ExprChild(const tp::String& id); + struct ExpressionChild* ExprChild(const std::string& id); struct ExpressionCall* ExprCall(class ExpressionList* args); }; @@ -39,28 +39,28 @@ namespace obj::BCgen { }; struct ExpressionNew : public Expression { - tp::String mNewType; - explicit ExpressionNew(const tp::String& type); + std::string mNewType; + explicit ExpressionNew(const std::string& type); ~ExpressionNew() override; }; struct ExpressionLocal : public Expression { - tp::String mLocalId; - explicit ExpressionLocal(const tp::String& id); + std::string mLocalId; + explicit ExpressionLocal(const std::string& id); ~ExpressionLocal() override; }; struct ExpressionFunc : public Expression { - tp::String mFuncId; - explicit ExpressionFunc(const tp::String& id); + std::string mFuncId; + explicit ExpressionFunc(const std::string& id); ~ExpressionFunc() override; }; struct ExpressionChild : public Expression { Expression* mParent = nullptr; - tp::String mLocalId; + std::string mLocalId; bool mMethod = false; - ExpressionChild(Expression* mParent, const tp::String& id); + ExpressionChild(Expression* mParent, const std::string& id); ~ExpressionChild() override; }; @@ -102,12 +102,12 @@ namespace obj::BCgen { struct ExpressionConst : public Expression { enum ConstType { STR, INT, BOOL, FLT } mConstType; - tp::String str; + std::string str; tp::alni integer = 0; tp::alnf floating = 0; bool boolean = false; - explicit ExpressionConst(const tp::String& val); + explicit ExpressionConst(const std::string& val); explicit ExpressionConst(const char* val); explicit ExpressionConst(tp::alni val); explicit ExpressionConst(tp::int4 val); diff --git a/Objects/public/compiler/function.h b/Objects/public/compiler/function.h index a54df26..e40b3ec 100644 --- a/Objects/public/compiler/function.h +++ b/Objects/public/compiler/function.h @@ -1,7 +1,7 @@ #pragma once -#include "Strings.hpp" +#include #include "List.hpp" #include "Map.hpp" @@ -16,17 +16,17 @@ namespace obj { struct FunctionDefinition { - FunctionDefinition* mPrnt = NULL; + FunctionDefinition* mPrnt = nullptr; // signature - tp::String mFunctionId; + std::string mFunctionId; tp::List mArgsOrder; ConstObjectsPool mConstants; - tp::Map mLocals; + tp::Map mLocals; tp::List mInstructions; - FunctionDefinition(tp::String function_id, tp::Buffer args, FunctionDefinition* prnt); + FunctionDefinition(const std::string& function_id, tp::Buffer args, FunctionDefinition* prnt); FunctionDefinition() {} void generateByteCode(ByteCode& out); @@ -36,7 +36,7 @@ namespace obj { void EvalExpr(Expression* expr); void EvalStatement(Statement* expr); - ConstObject* defineLocal(tp::String id); + ConstObject* defineLocal(const std::string& id); }; void init(); diff --git a/Objects/public/compiler/instruction.h b/Objects/public/compiler/instruction.h index 8d2b370..4419d10 100644 --- a/Objects/public/compiler/instruction.h +++ b/Objects/public/compiler/instruction.h @@ -35,11 +35,11 @@ namespace obj { tp::alni mParam = 0; tp::alni mParamBytes = 1; - ConstObject* mConstData = NULL; - ConstObject* mConstData2 = NULL; + ConstObject* mConstData = nullptr; + ConstObject* mConstData2 = nullptr; tp::alni mInstIdx = 0; - Instruction* mInstTarget = NULL; + Instruction* mInstTarget = nullptr; Instruction(); Instruction(ConstObject* constData); diff --git a/Objects/public/compiler/statement.h b/Objects/public/compiler/statement.h index 0d87a40..3e98c37 100644 --- a/Objects/public/compiler/statement.h +++ b/Objects/public/compiler/statement.h @@ -36,21 +36,21 @@ namespace obj::BCgen { }; struct StatementFuncDef : public Statement { - tp::Buffer mArgs; - tp::String mFunctionId; + tp::Buffer mArgs; + std::string mFunctionId; StatementScope* mStatements = nullptr; - explicit StatementFuncDef(const tp::String& function_id); + explicit StatementFuncDef(const std::string& function_id); ~StatementFuncDef() override; }; struct StatementLocalDef : public Statement { - tp::String mLocalId; + std::string mLocalId; Expression* mNewExpr = nullptr; ExpressionConst* mConstExpr = nullptr; bool mIsConstExpr = false; - StatementLocalDef(const tp::String& id, Expression* value); + StatementLocalDef(const std::string& id, Expression* value); ~StatementLocalDef() override; }; @@ -102,10 +102,10 @@ namespace obj::BCgen { }; struct StatementClassDef : public Statement { - tp::String mClassId; + std::string mClassId; StatementScope* mScope = nullptr; - StatementClassDef(const tp::String& class_id, StatementScope* scope); + StatementClassDef(const std::string& class_id, StatementScope* scope); ~StatementClassDef() override; }; } \ No newline at end of file diff --git a/Objects/public/core/object.h b/Objects/public/core/object.h index 8cc6ea0..2cc0799 100644 --- a/Objects/public/core/object.h +++ b/Objects/public/core/object.h @@ -5,7 +5,6 @@ #include "Map.hpp" #include "List.hpp" #include "Buffer.hpp" -#include "Strings.hpp" #include "LocalConnection.hpp" #include "core/typegroups.h" @@ -14,6 +13,8 @@ #include "Archiver.hpp" #include "SizeCounter.hpp" +#include + //#include "interpreter/interpreter.h" /* Steps to create custom Object: @@ -38,6 +39,7 @@ implement construct, destruct and copy methods */ namespace obj { + template class Archiver : public tp::ArchiverTemplate { tp::LocalConnection mConnection; @@ -84,6 +86,10 @@ namespace obj { using ArchiverIn = Archiver; using ArchiverOut = Archiver; + void save_string(ArchiverOut& file, const std::string& string); + tp::ualni save_string_size(const std::string& string); + void load_string(ArchiverIn& file, std::string& out); + extern tp::ModuleManifest gModuleObjects; extern struct objects_api* NDO; @@ -101,8 +107,8 @@ namespace obj { typedef void (*object_from_int)(Object* self, tp::alni in); typedef void (*object_from_float)(Object* self, tp::alnf in); - typedef void (*object_from_string)(Object* self, tp::String in); - typedef tp::String(*object_to_string)(Object* self); + typedef void (*object_from_string)(Object* self, const std::string& in); + typedef std::string(*object_to_string)(Object* self); typedef tp::alni(*object_to_int)(Object* self); typedef tp::alnf(*object_to_float)(Object* self); @@ -142,23 +148,23 @@ namespace obj { typedef tp::alni (*object_allocated_size_recursive)(Object*); // default value = object_allocated_size struct ObjectType { - const ObjectType* base = NULL; - object_constructor constructor = NULL; - object_destructor destructor = NULL; - object_copy copy = NULL; + const ObjectType* base = nullptr; + object_constructor constructor = nullptr; + object_destructor destructor = nullptr; + object_copy copy = nullptr; tp::alni size = 0; const char* name; - const ObjectTypeConversions* convesions = NULL; - const ObjectTypeAriphmetics* ariphmetics = NULL; - object_save_size save_size = NULL; - object_save save = NULL; - object_load load = NULL; - object_compare comparison = NULL; - void* vtable = NULL; - const char* description = NULL; - object_debug_all_childs_retrival childs_retrival = NULL; - object_allocated_size allocated_size = NULL; - object_allocated_size_recursive allocated_size_recursive = NULL; + const ObjectTypeConversions* convesions = nullptr; + const ObjectTypeAriphmetics* ariphmetics = nullptr; + object_save_size save_size = nullptr; + object_save save = nullptr; + object_load load = nullptr; + object_compare comparison = nullptr; + void* vtable = nullptr; + const char* description = nullptr; + object_debug_all_childs_retrival childs_retrival = nullptr; + object_allocated_size allocated_size = nullptr; + object_allocated_size_recursive allocated_size_recursive = nullptr; TypeMethods type_methods; }; @@ -182,26 +188,26 @@ namespace obj { struct objects_api { - tp::Map types; + tp::Map types; obj::TypeGroups type_groups; - Interpreter* interp = NULL; + Interpreter* interp = nullptr; objects_api(); ~objects_api(); void define(ObjectType* type); - Object* create(const tp::String& name); + Object* create(const std::string& name); Object* copy(Object* self, const Object* in); bool compare(Object* first, Object* second); Object* instatiate(Object*); void set(Object* self, tp::alni val); void set(Object* self, tp::alnf val); - void set(Object* self, tp::String val); + void set(Object* self, const std::string& val); tp::alni toInt(Object* self); tp::alnf toFloat(Object* self); bool toBool(Object* self); - tp::String toString(Object* self); + std::string toString(Object* self); void clear_object_flags(); @@ -225,8 +231,8 @@ namespace obj { tp::alni objsize_ram_recursive_util(Object* self, const ObjectType* type, bool different_object = true); tp::alni objsize_ram_recursive(Object* self); - bool save(Object*, tp::String path, bool compressed = true); - Object* load(tp::String path); + bool save(Object*, const std::string& path, bool compressed = true); + Object* load(const std::string& path); tp::alni save(ArchiverOut&, Object*); Object* load(ArchiverIn&, tp::alni file_adress); }; diff --git a/Objects/public/core/typegroups.h b/Objects/public/core/typegroups.h index ac546a8..b230925 100644 --- a/Objects/public/core/typegroups.h +++ b/Objects/public/core/typegroups.h @@ -2,7 +2,7 @@ #pragma once #include "Map.hpp" -#include "Strings.hpp" +#include namespace obj { @@ -13,13 +13,13 @@ namespace obj { public: - typedef tp::Map Dict; + typedef tp::Map Dict; TypeGroups(); friend struct obj::objects_api; - TypeGroups(bool is_group); + explicit TypeGroups(bool is_group); void addType(ObjectType* type, tp::InitialierList path, tp::alni cur_arg = 0); void setType(ObjectType* type); diff --git a/Objects/public/core/typemethods.h b/Objects/public/core/typemethods.h index 06a95d5..59c659f 100644 --- a/Objects/public/core/typemethods.h +++ b/Objects/public/core/typemethods.h @@ -2,7 +2,7 @@ #pragma once #include "Buffer.hpp" -#include "Strings.hpp" +#include namespace obj { @@ -13,19 +13,19 @@ namespace obj { struct TypeMethod { enum { MAX_ARGS = 8 }; struct Arg { - const char* descr = NULL; - mutable Object* obj = NULL; + const char* descr = nullptr; + mutable Object* obj = nullptr; }; - const char* nameid = NULL; - const char* descr = NULL; + const char* nameid = nullptr; + const char* descr = nullptr; - mutable Object* self = NULL; + mutable Object* self = nullptr; Arg args[MAX_ARGS]; tp::int1 mNargs = 0; - void (*exec)(const TypeMethod* tm) = NULL; + void (*exec)(const TypeMethod* tm) = nullptr; mutable Arg ret; @@ -48,7 +48,7 @@ namespace obj { operator bool() { return key != -1; } }; - static LookupKey presents(const ObjectType*, tp::String); + static LookupKey presents(const ObjectType*, const std::string&); static const TypeMethod* getMethod(const ObjectType*, LookupKey); void init(); @@ -56,7 +56,7 @@ namespace obj { tp::halni nMethods() const; private: - tp::int2 presents(tp::String) const; + tp::int2 presents(const std::string&) const; const TypeMethod* getMethod(tp::int2) const; }; diff --git a/Objects/public/interpreter/bytecode.h b/Objects/public/interpreter/bytecode.h index 6453959..db08b95 100644 --- a/Objects/public/interpreter/bytecode.h +++ b/Objects/public/interpreter/bytecode.h @@ -7,7 +7,7 @@ #include "primitives/stringobject.h" #include "Buffer.hpp" -#include "Strings.hpp" +#include namespace obj { diff --git a/Objects/public/interpreter/callstack.h b/Objects/public/interpreter/callstack.h index afb97df..4324c88 100644 --- a/Objects/public/interpreter/callstack.h +++ b/Objects/public/interpreter/callstack.h @@ -17,15 +17,15 @@ namespace obj { struct CallFrame { enum { CALL_DEPTH = 1024 }; - obj::Object* mSelf = NULL; - obj::MethodObject* mMethod = NULL; + obj::Object* mSelf = nullptr; + obj::MethodObject* mMethod = nullptr; tp::ualni mIp = 0; }; void enter(const CallFrame& frame); void leave(); ByteCode* getBytecode(); - tp::halni len() const; + [[nodiscard]] tp::halni len() const; tp::ConstSizeBuffer mStack; }; diff --git a/Objects/public/interpreter/interpreter.h b/Objects/public/interpreter/interpreter.h index c6f67b2..38a3e11 100644 --- a/Objects/public/interpreter/interpreter.h +++ b/Objects/public/interpreter/interpreter.h @@ -10,13 +10,13 @@ namespace obj { ScopeStack mScopeStack; CallStack mCallStack; - obj::Object* mLastParent = NULL; + obj::Object* mLastParent = nullptr; bool mIsTypeMethod = false; - const TypeMethod* mTypeMethod = NULL; + const TypeMethod* mTypeMethod = nullptr; - typedef struct { obj::Object* obj; tp::String id; } GlobalDef; + typedef struct { obj::Object* obj; std::string id; } GlobalDef; - void exec(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList globals2 = {}); + void exec(obj::MethodObject* method, obj::ClassObject* self = nullptr, obj::DictObject* globals = nullptr, tp::InitialierList globals2 = {}); void stepBytecode(); void stepBytecodeIn(); @@ -24,6 +24,6 @@ namespace obj { bool finished(); - void execAll(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList globals2 = {}); + void execAll(obj::MethodObject* method, obj::ClassObject* self = nullptr, obj::DictObject* globals = nullptr, tp::InitialierList globals2 = {}); }; }; \ No newline at end of file diff --git a/Objects/public/interpreter/scopestack.h b/Objects/public/interpreter/scopestack.h index 9e1aae9..0b4edc7 100644 --- a/Objects/public/interpreter/scopestack.h +++ b/Objects/public/interpreter/scopestack.h @@ -6,7 +6,7 @@ namespace obj { struct Scope { - typedef tp::Map ObjDict; + typedef tp::Map ObjDict; typedef tp::List ObjList; ObjDict mLocals; @@ -31,16 +31,16 @@ namespace obj { ScopeStack(); void enterScope(bool aChildReachable); void leaveScope(); - void addLocal(obj::Object* local, tp::String id); + void addLocal(obj::Object* local, const std::string& id); void addTemp(obj::Object* tmp); void popTemp(); void addTempReturn(obj::Object* ret); - obj::Object* getLocal(tp::String& str); + obj::Object* getLocal(const std::string& str); Scope* getCurrentScope(); ~ScopeStack(); private: - obj::Object* getLocalUtil(Scope& scope, tp::String* id); + obj::Object* getLocalUtil(Scope& scope, const std::string& id); }; }; \ No newline at end of file diff --git a/Objects/public/parser/parser.h b/Objects/public/parser/parser.h index ebb40c3..cccd86a 100644 --- a/Objects/public/parser/parser.h +++ b/Objects/public/parser/parser.h @@ -12,11 +12,11 @@ namespace obj { struct Result { obj::BCgen::StatementScope* scope = nullptr; bool isError = false; - tp::String description; + std::string description; tp::halni line = 0; tp::halni column = 0; }; - Result parse(const tp::String& stream); + Result parse(const std::string& stream); }; }; diff --git a/Objects/public/primitives/boolobject.h b/Objects/public/primitives/boolobject.h index f669d6d..9377a67 100644 --- a/Objects/public/primitives/boolobject.h +++ b/Objects/public/primitives/boolobject.h @@ -16,8 +16,8 @@ namespace obj { static void from_int(BoolObject* self, tp::alni in); static void from_float(BoolObject* self, tp::alnf in); - static void from_string(BoolObject* self, tp::String in); - static tp::String to_string(BoolObject* self); + static void from_string(BoolObject* self, const std::string& in); + static std::string to_string(BoolObject* self); static tp::alni to_int(BoolObject* self); static tp::alnf to_float(BoolObject* self); }; diff --git a/Objects/public/primitives/classobject.h b/Objects/public/primitives/classobject.h index e6c2499..0d8d345 100644 --- a/Objects/public/primitives/classobject.h +++ b/Objects/public/primitives/classobject.h @@ -16,11 +16,11 @@ namespace obj { DictObject* members; - void addMember(Object* obj, tp::String id); - void createMember(tp::String type, tp::String id); + void addMember(Object* obj, const std::string& id); + void createMember(const std::string& type, const std::string& id); template - Type* createMember(tp::String id) { + Type* createMember(const std::string& id) { auto out = NDO->create(Type::TypeData.name); addMember(out, id); NDO->destroy(out); @@ -28,7 +28,7 @@ namespace obj { } template - Type* getMember(const tp::String& id) { + Type* getMember(const std::string& id) { auto idx = members->presents(id); if (bool(idx)) { return ((Type*)obj::ndo_cast(members->getSlotVal(idx), &Type::TypeData)); @@ -37,7 +37,7 @@ namespace obj { } template - Type* getMemberAssert(const tp::String& id) { + Type* getMemberAssert(const std::string& id) { auto out = getMember(id); assert(out && "invalid member access"); return out; diff --git a/Objects/public/primitives/colorobject.h b/Objects/public/primitives/colorobject.h index 831c761..eb4346e 100644 --- a/Objects/public/primitives/colorobject.h +++ b/Objects/public/primitives/colorobject.h @@ -17,7 +17,7 @@ namespace obj { static void from_int(ColorObject* self, tp::alni in); static void from_float(ColorObject* self, tp::alnf in); - static tp::String to_string(ColorObject* self); + static std::string to_string(ColorObject* self); static ColorObject* create(tp::RGBA in); }; diff --git a/Objects/public/primitives/dictobject.h b/Objects/public/primitives/dictobject.h index 6806436..f2e0081 100644 --- a/Objects/public/primitives/dictobject.h +++ b/Objects/public/primitives/dictobject.h @@ -17,15 +17,15 @@ namespace obj { static tp::alni allocated_size(DictObject* self); static tp::alni allocated_size_recursive(DictObject* self); - void put(tp::String, Object*); - void remove(tp::String); - Object* get(tp::String); - tp::Map::Idx presents(tp::String); - Object* getSlotVal(tp::Map::Idx); + void put(const std::string&, Object*); + void remove(const std::string&); + Object* get(const std::string&); + tp::Map::Idx presents(const std::string&); + Object* getSlotVal(tp::Map::Idx); - const tp::Map& getItems() const; + [[nodiscard]] const tp::Map& getItems() const; private: - tp::Map items; + tp::Map items; }; }; \ No newline at end of file diff --git a/Objects/public/primitives/enumobject.h b/Objects/public/primitives/enumobject.h index 6e12823..6f0ba99 100644 --- a/Objects/public/primitives/enumobject.h +++ b/Objects/public/primitives/enumobject.h @@ -23,8 +23,8 @@ namespace obj { static void from_int(EnumObject* self, tp::alni in); static void from_float(EnumObject* self, tp::alnf in); - static void from_string(EnumObject* self, tp::String in); - static tp::String to_string(EnumObject* self); + static void from_string(EnumObject* self, const std::string& in); + static std::string to_string(EnumObject* self); static tp::alni to_int(EnumObject* self); static tp::alnf to_float(EnumObject* self); diff --git a/Objects/public/primitives/floatobject.h b/Objects/public/primitives/floatobject.h index 5013383..60af359 100644 --- a/Objects/public/primitives/floatobject.h +++ b/Objects/public/primitives/floatobject.h @@ -18,8 +18,8 @@ namespace obj { static void from_int(FloatObject* self, tp::alni in); static void from_float(FloatObject* self, tp::alnf in); - static void from_string(FloatObject* self, tp::String in); - static tp::String to_string(FloatObject* self); + static void from_string(FloatObject* self, const std::string& in); + static std::string to_string(FloatObject* self); static tp::alni to_int(FloatObject* self); static tp::alnf to_float(FloatObject* self); }; diff --git a/Objects/public/primitives/interpreterobject.h b/Objects/public/primitives/interpreterobject.h index 9f5f235..df538f0 100644 --- a/Objects/public/primitives/interpreterobject.h +++ b/Objects/public/primitives/interpreterobject.h @@ -12,7 +12,7 @@ namespace obj { static void constructor(InterpreterObject* self); static void load(ArchiverIn& file_self, InterpreterObject* self); - void exec(obj::ClassObject* self = NULL, tp::InitialierList globals = {}); + void exec(obj::ClassObject* self = nullptr, tp::InitialierList globals = {}); void debug(); bool running(); }; diff --git a/Objects/public/primitives/intobject.h b/Objects/public/primitives/intobject.h index 0f26799..f889f67 100644 --- a/Objects/public/primitives/intobject.h +++ b/Objects/public/primitives/intobject.h @@ -17,8 +17,8 @@ namespace obj { static void from_int(Object* self, tp::alni in); static void from_float(Object* self, tp::alnf in); - static void from_string(Object* self, tp::String in); - static tp::String to_string(Object* self); + static void from_string(Object* self, const std::string& in); + static std::string to_string(Object* self); static tp::alni to_int(Object* self); static tp::alnf to_float(Object* self); }; diff --git a/Objects/public/primitives/listobject.h b/Objects/public/primitives/listobject.h index 3546f70..5e750dd 100644 --- a/Objects/public/primitives/listobject.h +++ b/Objects/public/primitives/listobject.h @@ -23,7 +23,7 @@ namespace obj { static void save(ListObject* self, ArchiverOut& file_self); static tp::alni save_size(ListObject* self); - const tp::List& getItems() const; + [[nodiscard]] const tp::List& getItems() const; void pushBack(Object* obj); void pushFront(Object* obj); diff --git a/Objects/public/primitives/methodobject.h b/Objects/public/primitives/methodobject.h index 907225a..95dbc69 100644 --- a/Objects/public/primitives/methodobject.h +++ b/Objects/public/primitives/methodobject.h @@ -23,6 +23,6 @@ namespace obj { void compile(); - static MethodObject* create(tp::String script); + static MethodObject* create(const std::string& script); }; }; \ No newline at end of file diff --git a/Objects/public/primitives/stringobject.h b/Objects/public/primitives/stringobject.h index 6f0b841..c3d5be1 100644 --- a/Objects/public/primitives/stringobject.h +++ b/Objects/public/primitives/stringobject.h @@ -6,18 +6,18 @@ namespace obj { struct StringObject : Object { - tp::String val; + std::string val; static ObjectType TypeData; static void constructor(Object* self); static void destructor(StringObject* self); static void copy(Object* self, const Object* in); - static StringObject* create(tp::String in); + static StringObject* create(const std::string& in); static void from_int(StringObject* self, tp::alni in); static void from_float(StringObject* self, tp::alnf in); - static void from_string(StringObject* self, tp::String in); - static tp::String to_string(StringObject* self); + static void from_string(StringObject* self, const std::string& in); + static std::string to_string(StringObject* self); static tp::alni to_int(StringObject* self); static tp::alnf to_float(StringObject* self); }; diff --git a/Objects/tests/TestCore.cpp b/Objects/tests/TestCore.cpp index 97825c2..f18a529 100644 --- a/Objects/tests/TestCore.cpp +++ b/Objects/tests/TestCore.cpp @@ -17,12 +17,12 @@ SUITE(Core) { integer->val = 10; - printf("%s\n", NDO->toString(integer).read()); + printf("%s\n", NDO->toString(integer).c_str()); NDO->save(integer, "tmp.o"); auto savedInt = NDO->load("tmp.o"); - printf("%s\n", NDO->toString(savedInt).read()); + printf("%s\n", NDO->toString(savedInt).c_str()); CHECK(NDO->compare(integer, savedInt)); CHECK(NDO_CAST(IntObject, savedInt)); diff --git a/Objects/tests/TestParser.cpp b/Objects/tests/TestParser.cpp index bfbfafd..d7ac7b7 100644 --- a/Objects/tests/TestParser.cpp +++ b/Objects/tests/TestParser.cpp @@ -13,7 +13,7 @@ SUITE(Parser) { { Parser parser; - String stream = ""; + std::string stream = ""; auto res = parser.parse(stream); CHECK(!res.isError); @@ -24,7 +24,7 @@ SUITE(Parser) { { Parser parser; - String stream = "var i = true;"; + std::string stream = "var i = true;"; auto res = parser.parse(stream); CHECK(!res.isError); @@ -35,7 +35,7 @@ SUITE(Parser) { { Parser parser; - String stream = "var i = true; print (i + 1) * 10;"; + std::string stream = "var i = true; print (i + 1) * 10;"; auto res = parser.parse(stream); CHECK(!res.isError); @@ -51,7 +51,7 @@ SUITE(Parser) { { Parser parser; - String stream = "var i = true; print (i + 1) * 10; invalidCharacter "; + std::string stream = "var i = true; print (i + 1) * 10; invalidCharacter "; auto res = parser.parse(stream); CHECK(res.isError); diff --git a/Objects/tests/main.cpp b/Objects/tests/main.cpp index 1fc580d..c837e5d 100644 --- a/Objects/tests/main.cpp +++ b/Objects/tests/main.cpp @@ -7,6 +7,5 @@ tp::ModuleManifest* objDeps[] = { &obj::gModuleObjects, nullptr }; tp::ModuleManifest objTestModule("ObjectsTests", nullptr, nullptr, objDeps); #include -#include int main(int /*argc*/, char** /*argv*/) { return UnitTest::RunAllTests(); } \ No newline at end of file diff --git a/Sketch3D/CMakeLists.txt b/Sketch3D/CMakeLists.txt index 22a5710..21fef33 100644 --- a/Sketch3D/CMakeLists.txt +++ b/Sketch3D/CMakeLists.txt @@ -11,7 +11,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE} ./ext/) -target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets Math Strings) +target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets Math) target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS}) ### -------------------------- Applications -------------------------- ### diff --git a/Sketch3D/applications/Entry.cpp b/Sketch3D/applications/Entry.cpp index 6213afa..9cb6be0 100644 --- a/Sketch3D/applications/Entry.cpp +++ b/Sketch3D/applications/Entry.cpp @@ -33,15 +33,5 @@ void runApp() { } int main() { - - tp::ModuleManifest* deps[] = { &tp::gModuleStrings, nullptr }; - tp::ModuleManifest binModule("LibViewEntry", nullptr, nullptr, deps); - - if (!binModule.initialize()) { - return 1; - } - runApp(); - - binModule.deinitialize(); } \ No newline at end of file diff --git a/Sketch3D/private/Shader.cpp b/Sketch3D/private/Shader.cpp index ef06812..0bb8af3 100644 --- a/Sketch3D/private/Shader.cpp +++ b/Sketch3D/private/Shader.cpp @@ -1,6 +1,5 @@ -#include "Strings.hpp" #include "Buffer.hpp" #include "LocalConnection.hpp" #include "Shader.hpp" @@ -96,7 +95,7 @@ void RenderShader::load(const char* pvert, const char* pgeom, const char* pfrag, if (paths) { - String content; + std::string content; auto loadFile = [&](const char* path) { LocalConnection file; @@ -105,26 +104,30 @@ void RenderShader::load(const char* pvert, const char* pgeom, const char* pfrag, return false; } - content.resize(file.size()); - file.readBytes(content.write(), content.size()); + const auto size = file.size(); + auto tmp = new char[size + 1]; + tmp[size] = 0; + file.readBytes(tmp, size); + content = tmp; + delete[] tmp; return true; }; printf("Compiling shader : %s\n", pvert); if (loadFile(pvert)) { - compile_shader(content.read(), VertexShaderID); + compile_shader(content.c_str(), VertexShaderID); } if (GeometryShaderID) { printf("Compiling shader : %s\n", pgeom); if (loadFile(pgeom)) { - compile_shader(content.read(), GeometryShaderID); + compile_shader(content.c_str(), GeometryShaderID); } } printf("Compiling shader : %s\n", pfrag); if (loadFile(pfrag)) { - compile_shader(content.read(), FragmentShaderID); + compile_shader(content.c_str(), FragmentShaderID); } } else { diff --git a/Sketch3D/private/Texture.cpp b/Sketch3D/private/Texture.cpp index 66ec2bc..55fcbd7 100644 --- a/Sketch3D/private/Texture.cpp +++ b/Sketch3D/private/Texture.cpp @@ -3,8 +3,6 @@ #include "Map.hpp" -#include "Strings.hpp" - #include "Shader.hpp" #include "GraphicsApi.hpp" @@ -71,7 +69,7 @@ void RenderTexture::draw(const GLuint& out) { struct texture_drawer_data { - Map textures; + Map textures; GLuint quad_VertexArrayID; GLuint quad_vertexbuffer; @@ -147,7 +145,7 @@ void RenderTexture::draw_texture(uint4 out, uint4 in) { texdd->shader.unbind(); } -GLuint load_texture(const String& name) { +GLuint load_texture(const std::string& name) { GLuint tex_2d = 0; ASSERT(0 && "incomplete compilation - no SOIL support added"); diff --git a/Sketch3D/public/Sketch3D.hpp b/Sketch3D/public/Sketch3D.hpp index f1d5cbd..a7d64ff 100644 --- a/Sketch3D/public/Sketch3D.hpp +++ b/Sketch3D/public/Sketch3D.hpp @@ -5,7 +5,6 @@ #include "Map.hpp" #include "Topology.hpp" #include "Color.hpp" -#include "Strings.hpp" #include "GraphicsApi.hpp" #include "FrameBuffer.hpp" @@ -88,7 +87,7 @@ namespace tp { Layer() = default; ~Layer(); - String name = "new layer"; + std::string name = "new layer"; List strokes; // TODO use vector bool enabled = true; }; @@ -108,13 +107,13 @@ namespace tp { Camera mCamera; RGBA mBackgroundColor = { 0.22f, 0.22f, 0.25f, 1.f }; - Map mBrushes; - String mActiveBrush; + Map mBrushes; + std::string mActiveBrush; }; class Brush { public: - String mType = "equal"; + std::string mType = "equal"; Brush() = default; virtual void sample(Project* proj, Vec2F crs, halnf pressure) {} virtual void draw(Renderer* render, const Camera* camera) {} diff --git a/Strings/CMakeLists.txt b/Strings/CMakeLists.txt deleted file mode 100644 index c62330b..0000000 --- a/Strings/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -project(Strings) - -### ---------------------- Static Library --------------------- ### -file(GLOB SOURCES "./private/*.cpp") -file(GLOB HEADERS "./public/*.hpp") -add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) -target_include_directories(${PROJECT_NAME} PUBLIC ./public/) -target_link_libraries(${PROJECT_NAME} PUBLIC Containers) - -### -------------------------- Tests -------------------------- ### -enable_testing() -file(GLOB TEST_SOURCES "./tests/*.cpp") -add_executable(Test${PROJECT_NAME} ${TEST_SOURCES}) -target_link_libraries(Test${PROJECT_NAME} ${PROJECT_NAME} UnitTest++) -add_test(NAME Test${PROJECT_NAME} COMMAND Test${PROJECT_NAME}) \ No newline at end of file diff --git a/Strings/private/Logging.cpp b/Strings/private/Logging.cpp deleted file mode 100644 index 55ef8db..0000000 --- a/Strings/private/Logging.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "Logging.hpp" - -#include - -namespace tp { - - Logger* gLogger = nullptr; - - ualni Logger::Report::getLineCount() const { return (ualni) (mLineOffsets.size() - 1); } - - String Logger::Report::getString() const { return mData; } - - void Logger::Report::calcLineCount() { mData.calcLineOffsets(mLineOffsets); } - - Logger::Report::Report() { mData = " - "; } - - Logger::Report::Report(const String& text) : - mData(text) { - calcLineCount(); - } - - Logger::Report::Report(const String& text, Type type) : - mType(type), - mData(text) { - calcLineCount(); - } - - void Logger::write(const String& in, bool post, Report::Type type) { - mBuff.pushBack(Report(in, type)); - mLineCount += mBuff.last()->data.getLineCount(); - if (!mCursor) mCursor = mBuff.last(); - if (post) printf("%s", in.read()); - } - - String Logger::read() { - if (!mCursor) return {}; - const Report& out = mCursor->data; - mCursor = mCursor->next; - return out.getString(); - } - - void Logger::initializeGlobal() { - DEBUG_ASSERT(!gLogger) - gLogger = new Logger(); - } - - void Logger::deinitializeGlobal() { - DEBUG_ASSERT(gLogger) - delete gLogger; - gLogger = nullptr; - } -} diff --git a/Strings/private/Strings.cpp b/Strings/private/Strings.cpp deleted file mode 100644 index 7441a2e..0000000 --- a/Strings/private/Strings.cpp +++ /dev/null @@ -1,16 +0,0 @@ - -#include "Strings.hpp" -#include "Logging.hpp" - -using namespace tp; - -bool initialize(const ModuleManifest*) { - Logger::initializeGlobal(); - return true; -} - -void deinitialize(const ModuleManifest*) { Logger::deinitializeGlobal(); } - -static tp::ModuleManifest* sModuleDependencies[] = { nullptr }; - -ModuleManifest tp::gModuleStrings = ModuleManifest("Strings", initialize, deinitialize, sModuleDependencies); \ No newline at end of file diff --git a/Strings/public/Logging.hpp b/Strings/public/Logging.hpp deleted file mode 100644 index 8d943ac..0000000 --- a/Strings/public/Logging.hpp +++ /dev/null @@ -1,58 +0,0 @@ - -#pragma once - -#include "Buffer.hpp" -#include "List.hpp" -#include "Strings.hpp" - -namespace tp { - - class Logger { - public: - class Report { - String mData; - Buffer mLineOffsets; - - public: - enum Type { INFO, ERR, WARN, SUC } mType = INFO; - - public: - Report(); - explicit Report(const String& text); - Report(const String& text, Type type); - - public: - [[nodiscard]] ualni getLineCount() const; - [[nodiscard]] String getString() const; - - private: - void calcLineCount(); - }; - - private: - List::Node* mCursor = nullptr; - List mBuff; - ualni mLineCount = 0; - - public: - void write(const String& in, bool post = true, Report::Type type = Report::Type::INFO); - - [[nodiscard]] String read(); - [[nodiscard]] const List& getBuff() const { return mBuff; } - [[nodiscard]] ualni getLineCount() const { return mLineCount; } - - public: - static void initializeGlobal(); - static void deinitializeGlobal(); - }; - - extern Logger* gLogger; -} - -#define LOG(val) tp::str::gLogger->write((val), 1) - -#ifdef ENV_BUILD_DEBUG -#define DEBUG_LOG(val) tp::str::gLogger->write((val), 1) -#else -#define DEBUG_LOG(val) (0) -#endif \ No newline at end of file diff --git a/Strings/public/StringLogic.hpp b/Strings/public/StringLogic.hpp deleted file mode 100644 index a6baa10..0000000 --- a/Strings/public/StringLogic.hpp +++ /dev/null @@ -1,138 +0,0 @@ -#pragma once - -#include "Buffer.hpp" -#include "Utils.hpp" -#include -#include -#include - -namespace tp { - - template - class StringLogic { - public: - typedef halni Index; - typedef Index LineId; - typedef Index ColumnId; - - static inline bool isNewLineChar(tChar in) { return (in == '\n') || (in == '\r'); } - static inline bool isEndChar(tChar in) { return in == '\0'; } - static constexpr tChar getEndChar() { return '\0'; } - - static Index calcLength(const tChar* in) { - const tChar* iter = in; - while (*iter != '\0') - iter++; - return iter - in; - } - - static void insertLogic(tChar* result, Index resultLen, const tChar* cur, const tChar* tar, Index at, Index len) { - auto curLen = calcLength(cur); - auto allLen = curLen + len; - ASSERT(allLen <= resultLen); - - DEBUG_ASSERT(curLen >= 0) - DEBUG_ASSERT(len >= 0) - DEBUG_ASSERT(at < curLen + 1 && at >= 0) - - for (Index idx = 0; idx < at; idx++) { - result[idx] = cur[idx]; - } - for (Index idx = 0; idx < len; idx++) { - result[idx + at] = tar[idx]; - } - for (Index idx = at + len; idx < allLen; idx++) { - result[idx] = cur[idx - len]; - } - result[allLen] = '\0'; - } - - // including end not including start - static void removeLogic(tChar* result, Index resultLen, const tChar* cur, Index start, Index end) { - auto curLen = calcLength(cur); - auto rangeLen = end - start; - auto newLen = curLen - rangeLen; - - ASSERT(newLen <= resultLen); - - result[newLen] = '\0'; - for (Index idx = 0; idx < start; idx++) { - result[idx] = cur[idx]; - } - for (Index idx = end; idx < curLen; idx++) { - result[idx - rangeLen] = cur[idx]; - } - } - - static bool isEqualLogic(const tChar* left, const tChar* right) { - Index idx = 0; - LOOP: - if (left[idx] == '\0' || right[idx] == '\0') { - if (left[idx] == '\0' && right[idx] == '\0') { - return true; - } - return false; - } - if (left[idx] != right[idx]) { - return false; - } - idx++; - goto LOOP; - } - - // returns 0 : nl1 + 1 : nl2 + 1 : nl3 + 1 : ... : size - static void calcLineOffsets(const tChar* aBuff, Index aLength, Buffer& aOut) { - Index lines = 0; - for (auto idx : Range(aLength)) { - if (isNewLineChar(aBuff[idx])) { - lines++; - } - } - aOut.reserve(lines + 2); // plus start and end offsets - lines = 0; - for (auto idx : Range(aLength)) { - if (isNewLineChar(aBuff[idx])) { - aOut[lines + 1] = Index(idx + 1); - lines++; - } - } - aOut[0] = 0; - aOut[lines + 1] = aLength; - } - - static bool convertStringToValue(const tChar* input, alni& output) { - char* endPtr; - output = std::strtoll(input, &endPtr, 10); - return (endPtr == input + calcLength(input)); - } - - static bool convertStringToValue(const tChar* input, alnf& output) { - char* endPtr; - output = std::strtod(input, &endPtr); - return (endPtr == input + calcLength(input)); - } - - static bool convertStringToValue(const tChar* input, bool& output) { - output = !(isEqualLogic(input, "False") || isEqualLogic(input, "false") || isEqualLogic(input, "0")); - return true; - } - - static bool convertValueToString(alni input, tChar* output, Index bufferSize) { - int result = std::snprintf(output, bufferSize, "%lld", input); - return result >= 0; - } - - static bool convertValueToString(alnf input, tChar* output, Index bufferSize) { - int result = std::snprintf(output, bufferSize, "%f", input); - return result >= 0; - } - - static bool convertValueToString(bool input, tChar* output, Index bufferSize) { - const char* str = (input ? "true" : "false"); - Index length = calcLength(str); - if (length >= bufferSize) return false; - memCopy(output, str, length + 1); - return true; - } - }; -} \ No newline at end of file diff --git a/Strings/public/Strings.hpp b/Strings/public/Strings.hpp deleted file mode 100644 index 6593f87..0000000 --- a/Strings/public/Strings.hpp +++ /dev/null @@ -1,273 +0,0 @@ -#pragma once - -#include "StringLogic.hpp" - -namespace tp { - - // Static data - extern ModuleManifest gModuleStrings; - - template - class StringTemplate; - - // Hidden slave class - template - class StringData { - friend StringTemplate; - typedef StringLogic Logic; - typedef typename StringLogic::Index Index; - - private: - uint2 mIsConst; // source is non-modifiable - uint2 mEditedIdx; // editor id - uint4 mReferenceCount; // number of users of this - tChar* mBuff; // actual string data - - StringData() { - mBuff = (tChar*) "*"; - mReferenceCount = 1; - mIsConst = true; - mEditedIdx = 0; - } - - StringData(const tChar* aBuff, bool aIsConst) { - MODULE_SANITY_CHECK(gModuleStrings) - DEBUG_ASSERT(aBuff) - mBuff = (tChar*) aBuff; - mReferenceCount = 0; - mIsConst = aIsConst; - mEditedIdx = 0; - } - - explicit StringData(tChar* aBuff) { - MODULE_SANITY_CHECK(gModuleStrings) - DEBUG_ASSERT(aBuff) - auto const len = Logic::calcLength(aBuff); - mReferenceCount = 0; - mIsConst = false; - mEditedIdx = 0; - mBuff = new tChar[len + 1]; - mBuff[len] = Logic::getEndChar(); - memCopy(mBuff, aBuff, len); - } - - [[nodiscard]] tChar* getBuffer() { return mBuff; } - - ~StringData() { - if (!mIsConst) delete[] mBuff; - } - - void resize(Index size) { - DEBUG_ASSERT(mReferenceCount == 1 && !mIsConst) - delete[] mBuff; - mBuff = new tChar[size + 1]; - // set non-zero value so that size() function wont return size that may be less that actual - memSetVal(mBuff, size, 1); - mBuff[size] = Logic::getEndChar(); - } - }; - - template - class StringTemplate { - public: - typedef StringLogic Logic; - typedef StringData Data; - typedef typename Logic::Index Index; - - enum { - STRINGS_POOL_SIZE = 1024, - MAX_INT_STRING_LENGTH = 10, - MAX_BOOL_STRING_LENGTH = 10, - MAX_FLOAT_STRING_LENGTH = 10, - }; - - static Data sNullString; - - private: - Data* mData; - - public: // Main Interface - // Creates null string reference - StringTemplate() { - mData = &sNullString; - incReference(mData); - } - - // References existing string data - StringTemplate(const StringTemplate& in) { - mData = in.mData; - incReference(mData); - } - - void* alloc() { return malloc(sizeof(StringData)); } - - // Creates new string data from raw data pointer. - // Does not own string buffer - string buffer will not be freed. Initializes as const memory. - StringTemplate(const tChar* raw) { - mData = new (alloc()) StringData(raw, true); - incReference(mData); - } - - // Copies raw data and claims ownership over it - StringTemplate(tChar* raw) { - mData = new (alloc()) StringData(raw); - incReference(mData); - } - - ~StringTemplate() { decReference(mData); } - - private: - static void incReference(Data* dp) { dp->mReferenceCount++; } - - void decReference(Data* dp) { - DEBUG_ASSERT(dp->mReferenceCount > 0) - dp->mReferenceCount--; - if (!dp->mReferenceCount) { - mData->~StringData(); - free(mData); - } - } - - public: // Access - // used to read data - [[nodiscard]] const tChar* read() const { return mData->mBuff; } - - // used to write data - // output will be null if in TextEditing mode - [[nodiscard]] tChar* write() { - makeModifiable(); - return mData->getBuffer(); - } - - // output will be null if in TextEditing mode - tChar* resize(Index size) { - makeModifiable(); - mData->resize(size); - return write(); - } - - public: - void makeModifiable() { - // We have no rights to modify if someone references that memory too - // So we need to create new copy of StringData - if (mData->mReferenceCount > 1) { - mData = new (alloc()) StringData(mData->mBuff); - incReference(mData); - return; - } - - // Also if initial raw data was marked as const - create copy of raw data - // Note - raw data will be lost at this point if no other record of such is stored - if (mData->mIsConst) { - mData = new (alloc()) StringData(mData->mBuff); - incReference(mData); - } - } - - template - void archiveWrite(tArchiver& ar) const { - auto size = this->size(); - ar << size; - ar.writeBytes(read(), size); - } - - template - void archiveRead(tArchiver& ar) { - Index size; - ar >> size; - resize(size); - ar.readBytes(write(), size); - } - - public: // Syntax sugars - explicit StringTemplate(alni val) { - tChar raw[MAX_INT_STRING_LENGTH]; - Logic::convertValueToString(val, raw, MAX_INT_STRING_LENGTH); - mData = new (alloc()) StringData(raw); - incReference(mData); - } - - explicit StringTemplate(alnf val) { - tChar raw[MAX_INT_STRING_LENGTH]; - Logic::convertValueToString(val, raw, MAX_FLOAT_STRING_LENGTH); - mData = new (alloc()) StringData(raw); - incReference(mData); - } - - explicit StringTemplate(bool val) { - tChar raw[MAX_INT_STRING_LENGTH]; - Logic::convertValueToString(val, raw, MAX_BOOL_STRING_LENGTH); - mData = new (alloc()) StringData(raw); - incReference(mData); - } - - explicit operator alni() { - alni out; - Logic::convertStringToValue(read(), out); - return out; - } - - explicit operator alnf() { - alnf out; - Logic::convertStringToValue(read(), out); - return out; - } - - explicit operator bool() { - bool out; - Logic::convertStringToValue(read(), out); - return out; - } - - Index size() const { return Logic::calcLength(read()); } - - void calcLineOffsets(Buffer& aOut) const { Logic::calcLineOffsets(read(), size(), aOut); } - - StringTemplate& operator=(tChar* in) { - this->~StringTemplate(); - new (this) StringTemplate(in); - return *this; - } - - StringTemplate& operator=(const tChar* in) { - this->~StringTemplate(); - new (this) StringTemplate(in); - return *this; - } - - StringTemplate& operator=(const StringTemplate& in) { - if (&in == this) return *this; - this->~StringTemplate(); - new (this) StringTemplate(in); - return *this; - } - - bool operator==(const StringTemplate& in) const { - if (&in == this) return true; - if (in.mData == mData) return true; - return Logic::isEqualLogic(in.read(), read()); - } - - StringTemplate operator+(const StringTemplate& in) const { - StringTemplate out; - auto const newSize = in.size() + size(); - out.resize(newSize); - Logic::insertLogic(out.write(), newSize, read(), in.read(), size(), in.size()); - return out; - } - - public: // Debugging - [[nodiscard]] ualni getReferenceCount() const { return mData->mReferenceCount; } - [[nodiscard]] bool getIsConstFlag() const { return mData->mIsConst; } - }; - - template - StringData StringTemplate::sNullString; - - using String = StringTemplate; - - template - ualni hash(StringTemplate in) { - return hash(in.read()); - } -} \ No newline at end of file diff --git a/Strings/tests/Test.cpp b/Strings/tests/Test.cpp deleted file mode 100644 index a70ee65..0000000 --- a/Strings/tests/Test.cpp +++ /dev/null @@ -1,244 +0,0 @@ - -#include "UnitTest++/UnitTest++.h" - -#include "Strings.hpp" -#include "StringLogic.hpp" - -SUITE(Strings) { - using namespace tp; - - typedef StringLogic Logic; - - struct TestStruct { - String str = "test data"; - }; - - TEST(CoreLogic) { - String str; - CHECK(str.getIsConstFlag()); - CHECK(str.getReferenceCount() == 2); - - String str2; - CHECK(str.getIsConstFlag()); - CHECK(str.getReferenceCount() == 3); - - auto tmp = new TestStruct(); - CHECK(tmp->str.getIsConstFlag()); - CHECK(tmp->str.getReferenceCount() == 1); - - str = tmp->str; - - CHECK(str.getIsConstFlag()); - CHECK(str.getReferenceCount() == 2); - - delete tmp; - - CHECK(str.getIsConstFlag()); - CHECK(str.getReferenceCount() == 1); - } - - TEST(Addition) { - String str1 = "abc"; - String str2 = "def"; - { str1 + str2; } - { - CHECK(str1 + str2 == "abcdef"); - CHECK(str1 + "aaaccc" == "abcaaaccc"); - } - } - - TEST(isNewLineChar) { - CHECK(Logic::isNewLineChar('\n')); - CHECK(Logic::isNewLineChar('\r')); - CHECK(!Logic::isNewLineChar('a')); - } - - TEST(isEndChar) { - CHECK(Logic::isEndChar('\0')); - CHECK(!Logic::isEndChar('a')); - } - - TEST(calcLength) { - const char* str1 = "Hello"; - const char* str2 = "Wor\nld2"; - CHECK(Logic::calcLength(str1) == 5); - CHECK(Logic::calcLength(str2) == 7); - } - - TEST(insertLogic_emptyTarget) { - char inserted[40] = { "" }; - const char* cur = "Hello"; - const char* tar = ""; - const char* result = "Hello"; - Logic::insertLogic(inserted, 40, cur, tar, 5, 0); - CHECK(Logic::isEqualLogic(inserted, result)); - } - - TEST(insertLogic_emptyCurrent) { - char inserted[40] = { "" }; - const char* cur = ""; - const char* tar = "World"; - const char* result = "World"; - Logic::insertLogic(inserted, 40, cur, tar, 0, 5); - CHECK(Logic::isEqualLogic(inserted, result)); - } - - TEST(insertLogic_curLengthLessThanPos) { - char inserted[40] = { "" }; - const char* cur = "Hello"; - const char* tar = "World"; - const char* result = "HelloWorld"; - Logic::insertLogic(inserted, 40, cur, tar, 5, 5); - CHECK(Logic::isEqualLogic(inserted, result)); - } - - TEST(removeLogic_emptyCurrent) { - char removed[40] = { "" }; - const char* cur = ""; - const char* result = ""; - Logic::removeLogic(removed, 40, cur, 0, 0); - CHECK(Logic::isEqualLogic(removed, result)); - } - - TEST(removeLogic_removeUntilEnd) { - char removed[40] = { "" }; - const char* cur = "HelloWorld"; - const char* result = "World"; - Logic::removeLogic(removed, 40, cur, 0, 5); - CHECK(Logic::isEqualLogic(removed, result)); - } - - TEST(removeLogic_removeMiddleCharacters) { - char removed[40] = { "" }; - const char* cur = "HelloWorld"; - const char* result = "Helrld"; - Logic::removeLogic(removed, 40, cur, 3, 7); - CHECK(Logic::isEqualLogic(removed, result)); - } - - TEST(insertLogicGood) { - char inserted[40] = { "" }; - const char* cur = "Hello"; - const char* tar = "World"; - const char* result = "HelloWorld"; - Logic::insertLogic(inserted, 40, cur, tar, 5, 5); - CHECK(Logic::isEqualLogic(inserted, result)); - } - - TEST(removeLogicGood) { - char removed[40] = { "" }; - const char* cur = "HelloWorld"; - const char* result = "Helld"; - Logic::removeLogic(removed, 40, cur, 3, 8); - CHECK(Logic::isEqualLogic(removed, result)); - } - - TEST(convertStringToValue_alni) { - const char* str1 = "123"; - const char* str2 = "456xyz"; - const char* str3 = "789"; - alni output; - CHECK(Logic::convertStringToValue(str1, output) && output == 123); - CHECK(!Logic::convertStringToValue(str2, output)); - CHECK(Logic::convertStringToValue(str3, output) && output == 789); - } - - TEST(convertStringToValue_alnf) { - const char* str1 = "12.34"; - const char* str2 = "56.78xyz"; - const char* str3 = "90.12"; - alnf output; - CHECK(Logic::convertStringToValue(str1, output) && output == 12.34); - CHECK(!Logic::convertStringToValue(str2, output)); - CHECK(Logic::convertStringToValue(str3, output) && output == 90.12); - } - - TEST(convertStringToValue_bool) { - const char* str1 = "true"; - const char* str2 = "false"; - const char* str3 = "1"; - const char* str4 = "0"; - bool output; - CHECK(Logic::convertStringToValue(str1, output) && output == true); - CHECK(Logic::convertStringToValue(str2, output) && output == false); - CHECK(Logic::convertStringToValue(str3, output) && output == true); - CHECK(Logic::convertStringToValue(str4, output) && output == false); - } - - TEST(convertValueToString_alni) { - alni input1 = 123; - alni input2 = -456; - char output[10]; - CHECK(Logic::convertValueToString(input1, output, 10)); - CHECK(Logic::isEqualLogic(output, "123")); - - CHECK(Logic::convertValueToString(input2, output, 10)); - CHECK(Logic::isEqualLogic(output, "-456")); - } - - TEST(convertValueToString_alnf) { - alnf input1 = 12.34; - alnf input2 = -56.78; - char output[10]; - - CHECK(Logic::convertValueToString(input1, output, 10)); - CHECK(Logic::isEqualLogic(output, "12.340000")); - - CHECK(Logic::convertValueToString(input2, output, 10)); - CHECK(Logic::isEqualLogic(output, "-56.78000")); - } - - TEST(convertValueToString_bool) { - bool input1 = true; - bool input2 = false; - char output[10]; - - CHECK(Logic::convertValueToString(input1, output, 10)); - CHECK(Logic::isEqualLogic(output, "true")); - - CHECK(Logic::convertValueToString(input2, output, 10)); - CHECK(Logic::isEqualLogic(output, "false")); - } - - TEST(isEqualLogic) { - const char* str1 = "Hello"; - const char* str2 = "Hello"; - const char* str3 = "World"; - const char* str4 = "Hello2"; - CHECK(Logic::isEqualLogic(str1, str2)); - CHECK(!Logic::isEqualLogic(str1, str4)); - CHECK(!Logic::isEqualLogic(str1, str3)); - } - - TEST(calcLineOffsets) { - const char* str = "\n\nHello\nWorld\n\n "; - Buffer offsets; - Logic::calcLineOffsets(str, Logic::calcLength(str), offsets); - - CHECK(offsets.size() == 7); - - CHECK(offsets[0] == 0); - CHECK(offsets[1] == 1); - CHECK(offsets[2] == 2); - CHECK(offsets[3] == 8); - CHECK(offsets[4] == 14); - CHECK(offsets[5] == 15); - CHECK(offsets[6] == 16); - } -} - -int main() { - - tp::ModuleManifest* deps[] = { &tp::gModuleStrings, nullptr }; - tp::ModuleManifest testModule("StringsTest", nullptr, nullptr, deps); - - if (!testModule.initialize()) { - return 1; - } - - auto res = UnitTest::RunAllTests(); - - testModule.deinitialize(); - - return res; -} \ No newline at end of file diff --git a/Widgets/CMakeLists.txt b/Widgets/CMakeLists.txt index a045b9a..8d8bbd1 100644 --- a/Widgets/CMakeLists.txt +++ b/Widgets/CMakeLists.txt @@ -6,7 +6,7 @@ file(GLOB HEADERS "./public/*.hpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/) -target_link_libraries(${PROJECT_NAME} PUBLIC Math Graphics Imgui Strings) +target_link_libraries(${PROJECT_NAME} PUBLIC Math Graphics Imgui) ### -------------------------- Tests -------------------------- ### enable_testing() diff --git a/Widgets/examples/ExampleGUI.hpp b/Widgets/examples/ExampleGUI.hpp index 49f5e82..474151e 100644 --- a/Widgets/examples/ExampleGUI.hpp +++ b/Widgets/examples/ExampleGUI.hpp @@ -35,11 +35,11 @@ namespace tp { const auto size = this->getValue("Size"); const auto colUser = this->getColor("ColUser"); - canvas.text(mUser.read(), this->mArea, size, Canvas::CC, padding, colUser); + canvas.text(mUser.c_str(), this->mArea, size, Canvas::CC, padding, colUser); } public: - String mUser = "UserName"; + std::string mUser = "UserName"; bool mIsHover = false; }; @@ -83,13 +83,13 @@ namespace tp { content.y = userName.y + userName.w; content.w = this->mArea.w - userName.w; - canvas.text(mContent.read(), content, size, Canvas::LC, padding, col); - canvas.text(mUser.read(), userName, sizeUser, Canvas::LC, padding, colUser); + canvas.text(mContent.c_str(), content, size, Canvas::LC, padding, col); + canvas.text(mUser.c_str(), userName, sizeUser, Canvas::LC, padding, colUser); } public: - String mContent = "Message Content"; - String mUser = "UserName"; + std::string mContent = "Message Content"; + std::string mUser = "UserName"; bool mIsHover = false; }; diff --git a/Widgets/public/ButtonWidget.hpp b/Widgets/public/ButtonWidget.hpp index a29db2c..8df41bc 100644 --- a/Widgets/public/ButtonWidget.hpp +++ b/Widgets/public/ButtonWidget.hpp @@ -16,7 +16,7 @@ namespace tp { this->addValue("Rounding", "Rounding"); } - ButtonWidget(const String& label, const tp::RectF& aArea) { + ButtonWidget(const std::string& label, const tp::RectF& aArea) { this->mArea = aArea; this->mLabel.mLabel = label; diff --git a/Widgets/public/LabelWidget.hpp b/Widgets/public/LabelWidget.hpp index 20da9df..945436e 100644 --- a/Widgets/public/LabelWidget.hpp +++ b/Widgets/public/LabelWidget.hpp @@ -23,7 +23,7 @@ namespace tp { if (!this->mVisible) return; canvas.text( - mLabel.read(), + mLabel.c_str(), this->mArea, this->getValue("Size"), Canvas::CC, @@ -33,6 +33,6 @@ namespace tp { } public: - String mLabel = "Label"; + std::string mLabel = "Label"; }; } \ No newline at end of file diff --git a/Widgets/public/ScrollableWidget.hpp b/Widgets/public/ScrollableWidget.hpp index c2702ac..d955825 100644 --- a/Widgets/public/ScrollableWidget.hpp +++ b/Widgets/public/ScrollableWidget.hpp @@ -1,6 +1,7 @@ #pragma once #include "WidgetBase.hpp" +#include "Buffer.hpp" namespace tp { diff --git a/Widgets/public/TextInputWidget.hpp b/Widgets/public/TextInputWidget.hpp index 3960c5c..11089cb 100644 --- a/Widgets/public/TextInputWidget.hpp +++ b/Widgets/public/TextInputWidget.hpp @@ -43,7 +43,7 @@ namespace tp { // ImGui::PushID((int) alni(this)); ImGui::Begin( - mId.read(), + mId.c_str(), 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize @@ -55,7 +55,7 @@ namespace tp { nChanged = true; } } else { - if (ImGui::InputTextEx("input", mId.read(), mBuff, mMaxBufferSize, { this->mArea.z, this->mArea.w }, 0)) { + if (ImGui::InputTextEx("input", mId.c_str(), mBuff, mMaxBufferSize, { this->mArea.z, this->mArea.w }, 0)) { mValue = mBuff; nChanged = true; } @@ -68,8 +68,8 @@ namespace tp { enum { mMaxBufferSize = 512 }; char mBuff[mMaxBufferSize] = ""; bool nChanged = false; - String mValue; - String mId = "id"; + std::string mValue; + std::string mId = "id"; bool mMultiline = false; }; } \ No newline at end of file diff --git a/Widgets/public/WidgetBase.hpp b/Widgets/public/WidgetBase.hpp index d1fc60f..3fcd190 100644 --- a/Widgets/public/WidgetBase.hpp +++ b/Widgets/public/WidgetBase.hpp @@ -11,7 +11,7 @@ namespace tp { this->mArea = { 0, 0, 100, 100 }; } - [[nodiscard]] const RGBA& getColor(const String& name) const { + [[nodiscard]] const RGBA& getColor(const std::string& name) const { const auto& node = cfg->values.get(name); if (node.type == WidgetConfig::Node::REF) { return globalCfg->configs.get(node.refGroup).values.get(node.refName).color; @@ -19,7 +19,7 @@ namespace tp { return cfg->values.get(name).color; } - [[nodiscard]] halnf getValue(const String& name) const { + [[nodiscard]] halnf getValue(const std::string& name) const { const auto& node = cfg->values.get(name); if (node.type == WidgetConfig::Node::REF) { return globalCfg->configs.get(node.refGroup).values.get(node.refName).value; @@ -27,17 +27,17 @@ namespace tp { return cfg->values.get(name).value; } - void addColor(const String& name, const RGBA& val) { cfg->values.put(name, WidgetConfig::Node(val)); } - void addValue(const String& name, halnf val) { cfg->values.put(name, WidgetConfig::Node(val)); } + void addColor(const std::string& name, const RGBA& val) { cfg->values.put(name, WidgetConfig::Node(val)); } + void addValue(const std::string& name, halnf val) { cfg->values.put(name, WidgetConfig::Node(val)); } - void addColor(const String& name, const String& presetName) { + void addColor(const std::string& name, const std::string& presetName) { cfg->values.put(name, WidgetConfig::Node(presetName)); } - void addValue(const String& name, const String& presetName) { + void addValue(const std::string& name, const std::string& presetName) { cfg->values.put(name, WidgetConfig::Node(presetName)); } - void createConfig(const String& name) { + void createConfig(const std::string& name) { globalCfg->configs.put(name, {}); cfg = &globalCfg->configs.get(name); } diff --git a/Widgets/public/WidgetConfig.hpp b/Widgets/public/WidgetConfig.hpp index f531f6b..3455c48 100644 --- a/Widgets/public/WidgetConfig.hpp +++ b/Widgets/public/WidgetConfig.hpp @@ -3,7 +3,6 @@ #include "Animations.hpp" #include "Map.hpp" #include "Rect.hpp" -#include "Strings.hpp" #include "InputCodes.hpp" @@ -18,8 +17,8 @@ namespace tp { Type type = NONE; - String refGroup; - String refName; + std::string refGroup; + std::string refName; Node() = default; @@ -33,14 +32,14 @@ namespace tp { color = val; } - explicit Node(const String& val) { + explicit Node(const std::string& val) { refGroup = "Presets"; refName = val; type = REF; } }; - Map values; + Map values; }; struct GlobalGUIConfig { @@ -54,16 +53,16 @@ namespace tp { presets.values.put("Padding", WidgetConfig::Node(5.f)); presets.values.put("HandleSize", WidgetConfig::Node(5.f)); - presets.values.put("Background", WidgetConfig::Node({ 0.03f, 0.03f, 0.03f, 1.f })); - presets.values.put("Base", WidgetConfig::Node({ 0.07f, 0.07f, 0.07f, 1.f })); - presets.values.put("Accent", WidgetConfig::Node({ 0.13f, 0.13f, 0.13f, 1.f })); - presets.values.put("Interaction", WidgetConfig::Node({ 0.33f, 0.33f, 0.3f, 1.f })); - presets.values.put("Action", WidgetConfig::Node({ 0.44f, 0.44f, 0.4f, 1.f })); - presets.values.put("Front", WidgetConfig::Node({ 1.f, 1.f, 1.f, 1.f })); - presets.values.put("FrontDim", WidgetConfig::Node({ 0.7f, 0.7f, 0.7f, 1.f })); + presets.values.put("Background", WidgetConfig::Node(RGBA{ 0.03f, 0.03f, 0.03f, 1.f })); + presets.values.put("Base", WidgetConfig::Node(RGBA{ 0.07f, 0.07f, 0.07f, 1.f })); + presets.values.put("Accent", WidgetConfig::Node(RGBA{ 0.13f, 0.13f, 0.13f, 1.f })); + presets.values.put("Interaction", WidgetConfig::Node(RGBA{ 0.33f, 0.33f, 0.3f, 1.f })); + presets.values.put("Action", WidgetConfig::Node(RGBA{ 0.44f, 0.44f, 0.4f, 1.f })); + presets.values.put("Front", WidgetConfig::Node(RGBA{ 1.f, 1.f, 1.f, 1.f })); + presets.values.put("FrontDim", WidgetConfig::Node(RGBA{ 0.7f, 0.7f, 0.7f, 1.f })); } - Map configs; + Map configs; ~GlobalGUIConfig() { configs.removeAll();