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

summaryrefslogtreecommitdiff
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/StarAssetPath.cpp6
-rw-r--r--source/core/StarAssetPath.hpp6
-rw-r--r--source/core/StarDirectives.cpp60
-rw-r--r--source/core/StarDirectives.hpp19
4 files changed, 87 insertions, 4 deletions
diff --git a/source/core/StarAssetPath.cpp b/source/core/StarAssetPath.cpp
index eb1cd4d..b49f24d 100644
--- a/source/core/StarAssetPath.cpp
+++ b/source/core/StarAssetPath.cpp
@@ -66,7 +66,7 @@ AssetPath AssetPath::split(String const& path) {
++i;
}
- if (!directives.empty());
+ if (!directives.empty())
components.directives.append(move(directives));
}
@@ -178,4 +178,8 @@ std::ostream& operator<<(std::ostream& os, AssetPath const& rhs) {
return os;
}
+size_t hash<AssetPath>::operator()(AssetPath const& s) const {
+ return hashOf(s.basePath, s.subPath, s.directives);
+}
+
}
diff --git a/source/core/StarAssetPath.hpp b/source/core/StarAssetPath.hpp
index 3ca3f60..fd77005 100644
--- a/source/core/StarAssetPath.hpp
+++ b/source/core/StarAssetPath.hpp
@@ -2,6 +2,7 @@
#define STAR_ASSET_PATH_HPP
#include "StarDirectives.hpp"
+#include "StarHash.hpp"
namespace Star {
@@ -64,6 +65,11 @@ struct AssetPath {
std::ostream& operator<<(std::ostream& os, AssetPath const& rhs);
+template <>
+struct hash<AssetPath> {
+ size_t operator()(AssetPath const& s) const;
+};
+
}
#endif \ No newline at end of file
diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp
index e486ea9..8dcf8da 100644
--- a/source/core/StarDirectives.cpp
+++ b/source/core/StarDirectives.cpp
@@ -10,6 +10,16 @@ Directives::Entry::Entry(ImageOperation&& newOperation, String&& newString) {
string = move(newString);
}
+Directives::Entry::Entry(ImageOperation const& newOperation, String const& newString) {
+ operation = newOperation;
+ string = newString;
+}
+
+Directives::Entry::Entry(Entry const& other) {
+ operation = other.operation;
+ string = other.string;
+}
+
Directives::Directives() {}
Directives::Directives(String const& directives) {
parse(directives);
@@ -20,6 +30,17 @@ Directives::Directives(String&& directives) {
parse(mine);
}
+Directives::Directives(const char* directives) {
+ String string(directives);
+ parse(string);
+}
+
+Directives::Directives(List<Entry>&& newEntries) {
+ entries = std::make_shared<List<Entry> const>(move(newEntries));
+ String directives = toString(); // This needs to be better
+ hash = XXH3_64bits(directives.utf8Ptr(), directives.utf8Size());
+}
+
void Directives::parse(String const& directives) {
List<Entry> newList;
StringList split = directives.split('?');
@@ -41,6 +62,32 @@ void Directives::buildString(String& out) const {
}
}
+String Directives::toString() const {
+ String result;
+ buildString(result);
+ return result;
+}
+
+inline bool Directives::empty() const {
+ return entries->empty();
+}
+
+
+DataStream& operator>>(DataStream& ds, Directives& directives) {
+ String string;
+ ds.read(string);
+
+ directives.parse(string);
+
+ return ds;
+}
+
+DataStream& operator<<(DataStream& ds, Directives const& directives) {
+ ds.write(directives.toString());
+
+ return ds;
+}
+
DirectivesGroup::DirectivesGroup() : m_count(0) {}
DirectivesGroup::DirectivesGroup(String const& directives) {
m_directives.emplace_back(directives);
@@ -66,10 +113,21 @@ inline bool DirectivesGroup::compare(DirectivesGroup const& other) const {
}
void DirectivesGroup::append(Directives const& directives) {
- m_directives.push_back(directives);
+ m_directives.emplace_back(directives);
m_count += m_directives.back().entries->size();
}
+void DirectivesGroup::append(List<Directives::Entry>&& entries) {
+ size_t size = entries.size();
+ m_directives.emplace_back(move(entries));
+ m_count += size;
+}
+
+void DirectivesGroup::clear() {
+ m_directives.clear();
+ m_count = 0;
+}
+
DirectivesGroup& DirectivesGroup::operator+=(Directives const& other) {
append(other);
return *this;
diff --git a/source/core/StarDirectives.hpp b/source/core/StarDirectives.hpp
index e954387..ca4364c 100644
--- a/source/core/StarDirectives.hpp
+++ b/source/core/StarDirectives.hpp
@@ -3,28 +3,40 @@
#include "StarImageProcessing.hpp"
#include "StarHash.hpp"
+#include "StarDataStream.hpp"
namespace Star {
+STAR_CLASS(Directives);
STAR_CLASS(DirectivesGroup);
STAR_EXCEPTION(DirectivesException, StarException);
// Kae: My attempt at reducing memory allocation and per-frame string parsing for extremely long directives
-struct Directives {
+// entries must never be a null ptr!
+class Directives {
+public:
struct Entry {
ImageOperation operation;
String string;
Entry(ImageOperation&& newOperation, String&& newString);
+ Entry(ImageOperation const& newOperation, String const& newString);
+ Entry(Entry const& other);
};
Directives();
Directives(String const& directives);
Directives(String&& directives);
+ Directives(const char* directives);
+ Directives(List<Entry>&& entries);
void parse(String const& directives);
-
void buildString(String& out) const;
+ String toString() const;
+ inline bool empty() 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;
@@ -41,6 +53,9 @@ public:
inline bool empty() 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);
inline String toString() const;