Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarDirectives.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-26 01:42:18 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-26 01:42:18 +1000
commit09d26d43b5262f480fd55eab9980eff06a71edbb (patch)
tree1e53765861cd966d204782aeefd15b1a67b3266f /source/core/StarDirectives.hpp
parent13a74602bd4c46149da9949d448387a40b8ebd1c (diff)
Add string view variant of Star::String and use it
it's 1:30 AM AGAIN !! !!!!! This might have broken the inventory icons of custom hats a little, need to look into that
Diffstat (limited to 'source/core/StarDirectives.hpp')
-rw-r--r--source/core/StarDirectives.hpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/source/core/StarDirectives.hpp b/source/core/StarDirectives.hpp
index 822d619..1455dd0 100644
--- a/source/core/StarDirectives.hpp
+++ b/source/core/StarDirectives.hpp
@@ -4,6 +4,7 @@
#include "StarImageProcessing.hpp"
#include "StarHash.hpp"
#include "StarDataStream.hpp"
+#include "StarStringView.hpp"
namespace Star {
@@ -14,33 +15,46 @@ STAR_EXCEPTION(DirectivesException, StarException);
// Kae: My attempt at reducing memory allocation and per-frame string parsing for extremely long directives
class Directives {
public:
+ struct Shared;
struct Entry {
ImageOperation operation;
- String string; // One day, we can make this a string_view pointing to Entry::string.
+ size_t begin;
+ size_t length;
- Entry(ImageOperation&& newOperation, String&& newString);
- Entry(ImageOperation const& newOperation, String const& newString);
+ inline StringView string(Shared const& parent) const;
+ Entry(ImageOperation&& newOperation, size_t begin, size_t end);
+ Entry(ImageOperation const& newOperation, size_t begin, size_t end);
Entry(Entry const& other);
};
+ struct Shared {
+ List<Entry> entries;
+ String string;
+ size_t hash = 0;
+
+ bool empty() const;
+ Shared(List<Entry>&& givenEntries, String&& givenString);
+ };
+
Directives();
Directives(String const& directives);
Directives(String&& directives);
Directives(const char* directives);
- Directives(List<Entry>&& entries);
- void parse(String const& directives);
- String& buildString(String& out) const;
- String toString() const;
+ void parse(String&& directives);
+ String string() const;
+ String const* stringPtr() const;
+ String buildString() const;
+ String& addToString(String& out) const;
+ size_t hash() const;
+ size_t size() const;
bool empty() const;
operator bool() const;
friend DataStream& operator>>(DataStream& ds, Directives& directives);
friend DataStream& operator<<(DataStream& ds, Directives const& directives);
- std::shared_ptr<List<Entry> const> entries;
- size_t hash = 0;
- String string;
+ std::shared_ptr<Shared const> shared;
};
class DirectivesGroup {
@@ -49,13 +63,10 @@ public:
DirectivesGroup(String const& directives);
DirectivesGroup(String&& directives);
- void parseDirectivesIntoLeaf(String const& directives);
-
bool empty() const;
operator bool() const;
bool compare(DirectivesGroup const& other) const;
void append(Directives const& other);
- void append(List<Directives::Entry>&& entries);
void clear();
DirectivesGroup& operator+=(Directives const& other);
@@ -63,8 +74,8 @@ public:
String toString() const;
void addToString(String& string) const;
- typedef function<void(Directives::Entry const&)> DirectivesCallback;
- typedef function<bool(Directives::Entry const&)> AbortableDirectivesCallback;
+ typedef function<void(Directives::Entry const&, Directives const&)> DirectivesCallback;
+ typedef function<bool(Directives::Entry const&, Directives const&)> AbortableDirectivesCallback;
void forEach(DirectivesCallback callback) const;
bool forEachAbortable(AbortableDirectivesCallback callback) const;