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

summaryrefslogtreecommitdiff
path: root/source/core/StarDirectives.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-24 01:30:55 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-24 01:30:55 +1000
commit2798d4bf668d74028b5c1f88ae5b7b25cd08de2d (patch)
tree4a4df7c000c2e7d8be953dcf0724aa8f4b0d2b24 /source/core/StarDirectives.hpp
parent6832c10ed5482530b4a423a78700b279fc73212a (diff)
what the fuck it's 1:30 AM. god
Diffstat (limited to 'source/core/StarDirectives.hpp')
-rw-r--r--source/core/StarDirectives.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/source/core/StarDirectives.hpp b/source/core/StarDirectives.hpp
new file mode 100644
index 0000000..bc5b78d
--- /dev/null
+++ b/source/core/StarDirectives.hpp
@@ -0,0 +1,78 @@
+#ifndef STAR_DIRECTIVES_HPP
+#define STAR_DIRECTIVES_HPP
+
+#include "StarImageProcessing.hpp"
+
+namespace Star {
+
+STAR_CLASS(NestedDirectives);
+STAR_EXCEPTION(DirectivesException, StarException);
+
+// Kae: My attempt at reducing memory allocation and per-frame string parsing for extremely long directives
+class NestedDirectives {
+public:
+ struct Leaf {
+ List<ImageOperation> operations;
+ List<String> strings;
+
+ size_t length() const;
+ };
+
+ typedef function<void(Leaf const&)> LeafCallback;
+ typedef function<void(ImageOperation const&, String const&)> LeafPairCallback;
+ typedef function<bool(Leaf const&)> AbortableLeafCallback;
+ typedef function<bool(ImageOperation const&, String const&)> AbortableLeafPairCallback;
+
+ struct Cell;
+ typedef std::shared_ptr<Cell> Branch;
+ typedef std::shared_ptr<Cell const> ConstBranch;
+ typedef List<ConstBranch> Branches;
+
+
+ struct Cell {
+ Variant<Leaf, Branches> value;
+
+ Cell();
+ Cell(Leaf&& leaf);
+ Cell(Branches&& branches);
+ Cell(const Leaf& leaf);
+ Cell(const Branches& branches);
+
+ void buildString(String& string) const;
+ void forEach(LeafCallback& callback) const;
+ bool forEachAbortable(AbortableLeafCallback& callback) const;
+ };
+
+
+ NestedDirectives();
+ NestedDirectives(String const& directives);
+ NestedDirectives(String&& directives);
+
+ void parseDirectivesIntoLeaf(String const& directives);
+
+ bool empty() const;
+ void append(const NestedDirectives& other);
+
+ const ConstBranch& branch() const;
+
+ String toString() const;
+ void addToString(String& string) const;
+
+ void forEach(LeafCallback callback) const;
+ void forEachPair(LeafPairCallback callback) const;
+ bool forEachAbortable(AbortableLeafCallback callback) const;
+ bool forEachPairAbortable(AbortableLeafPairCallback callback) const;
+
+ Image apply(Image& image) const;
+private:
+ void buildString(String& string, const Cell& cell) const;
+ Branches& convertToBranches();
+
+ Branch m_root;
+};
+
+typedef NestedDirectives ImageDirectives;
+
+}
+
+#endif