2023-06-23 15:30:55 +00:00
|
|
|
#ifndef STAR_DIRECTIVES_HPP
|
|
|
|
#define STAR_DIRECTIVES_HPP
|
|
|
|
|
|
|
|
#include "StarImageProcessing.hpp"
|
2023-06-24 09:41:52 +00:00
|
|
|
#include "StarHash.hpp"
|
2023-06-24 12:49:47 +00:00
|
|
|
#include "StarDataStream.hpp"
|
2023-06-25 15:42:18 +00:00
|
|
|
#include "StarStringView.hpp"
|
2023-06-23 15:30:55 +00:00
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
2023-06-24 12:49:47 +00:00
|
|
|
STAR_CLASS(Directives);
|
2023-06-24 09:41:52 +00:00
|
|
|
STAR_CLASS(DirectivesGroup);
|
2023-06-23 15:30:55 +00:00
|
|
|
STAR_EXCEPTION(DirectivesException, StarException);
|
|
|
|
|
|
|
|
// Kae: My attempt at reducing memory allocation and per-frame string parsing for extremely long directives
|
2023-06-24 12:49:47 +00:00
|
|
|
class Directives {
|
|
|
|
public:
|
2023-06-25 15:42:18 +00:00
|
|
|
struct Shared;
|
2023-06-24 09:41:52 +00:00
|
|
|
struct Entry {
|
|
|
|
ImageOperation operation;
|
2023-06-25 15:42:18 +00:00
|
|
|
size_t begin;
|
|
|
|
size_t length;
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
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);
|
2023-06-24 12:49:47 +00:00
|
|
|
Entry(Entry const& other);
|
2023-06-24 09:41:52 +00:00
|
|
|
};
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
struct Shared {
|
|
|
|
List<Entry> entries;
|
|
|
|
String string;
|
|
|
|
size_t hash = 0;
|
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
Shared(List<Entry>&& givenEntries, String&& givenString);
|
|
|
|
};
|
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
Directives();
|
|
|
|
Directives(String const& directives);
|
|
|
|
Directives(String&& directives);
|
2023-06-24 12:49:47 +00:00
|
|
|
Directives(const char* directives);
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
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;
|
2023-06-25 08:27:36 +00:00
|
|
|
bool empty() const;
|
|
|
|
operator bool() const;
|
2023-06-24 12:49:47 +00:00
|
|
|
|
|
|
|
friend DataStream& operator>>(DataStream& ds, Directives& directives);
|
|
|
|
friend DataStream& operator<<(DataStream& ds, Directives const& directives);
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
std::shared_ptr<Shared const> shared;
|
2023-06-24 09:41:52 +00:00
|
|
|
};
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
class DirectivesGroup {
|
|
|
|
public:
|
|
|
|
DirectivesGroup();
|
|
|
|
DirectivesGroup(String const& directives);
|
|
|
|
DirectivesGroup(String&& directives);
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-25 08:27:36 +00:00
|
|
|
bool empty() const;
|
|
|
|
operator bool() const;
|
2023-06-24 09:41:52 +00:00
|
|
|
bool compare(DirectivesGroup const& other) const;
|
|
|
|
void append(Directives const& other);
|
2023-06-24 12:49:47 +00:00
|
|
|
void clear();
|
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
DirectivesGroup& operator+=(Directives const& other);
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-25 08:27:36 +00:00
|
|
|
String toString() const;
|
2023-06-23 15:30:55 +00:00
|
|
|
void addToString(String& string) const;
|
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
typedef function<void(Directives::Entry const&, Directives const&)> DirectivesCallback;
|
|
|
|
typedef function<bool(Directives::Entry const&, Directives const&)> AbortableDirectivesCallback;
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
void forEach(DirectivesCallback callback) const;
|
|
|
|
bool forEachAbortable(AbortableDirectivesCallback callback) const;
|
|
|
|
|
2023-06-25 08:27:36 +00:00
|
|
|
Image applyNewImage(const Image& image) const;
|
2023-06-24 09:41:52 +00:00
|
|
|
void applyExistingImage(Image& image) const;
|
|
|
|
|
2023-06-25 08:27:36 +00:00
|
|
|
size_t hash() const;
|
2023-06-25 08:12:54 +00:00
|
|
|
const List<Directives>& list() const;
|
2023-06-24 10:10:53 +00:00
|
|
|
|
|
|
|
friend bool operator==(DirectivesGroup const& a, DirectivesGroup const& b);
|
|
|
|
friend bool operator!=(DirectivesGroup const& a, DirectivesGroup const& b);
|
2023-06-25 08:12:54 +00:00
|
|
|
|
|
|
|
friend DataStream& operator>>(DataStream& ds, DirectivesGroup& directives);
|
|
|
|
friend DataStream& operator<<(DataStream& ds, DirectivesGroup const& directives);
|
2023-06-23 15:30:55 +00:00
|
|
|
private:
|
2023-06-24 09:41:52 +00:00
|
|
|
void buildString(String& string, const DirectivesGroup& directives) const;
|
|
|
|
|
|
|
|
List<Directives> m_directives;
|
|
|
|
size_t m_count;
|
|
|
|
};
|
2023-06-23 15:30:55 +00:00
|
|
|
|
2023-06-24 10:10:53 +00:00
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
template <>
|
|
|
|
struct hash<DirectivesGroup> {
|
|
|
|
size_t operator()(DirectivesGroup const& s) const;
|
2023-06-23 15:30:55 +00:00
|
|
|
};
|
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
typedef DirectivesGroup ImageDirectives;
|
2023-06-23 15:30:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|