34 #ifndef AGS_ENGINE_AC_DYNOBJ_SCRIPTSET_H 35 #define AGS_ENGINE_AC_DYNOBJ_SCRIPTSET_H 37 #include "common/std/set.h" 38 #include "common/std/unordered_set.h" 39 #include "ags/engine/ac/dynobj/cc_ags_dynamic_object.h" 40 #include "ags/shared/util/stream.h" 41 #include "ags/shared/util/string.h" 42 #include "ags/shared/util/string_types.h" 46 using namespace AGS::Shared;
50 int Dispose(
const char *address,
bool force)
override;
51 const char *GetType()
override;
54 virtual bool IsCaseSensitive()
const = 0;
55 virtual bool IsSorted()
const = 0;
57 virtual bool Add(
const char *item) = 0;
58 virtual void Clear() = 0;
59 virtual bool Contains(
const char *item)
const = 0;
60 virtual bool Remove(
const char *item) = 0;
61 virtual int GetItemCount()
const = 0;
73 template <
typename TSet,
bool is_sorted,
bool is_casesensitive>
76 typedef typename TSet::const_iterator ConstIterator;
80 bool IsCaseSensitive()
const override {
81 return is_casesensitive;
83 bool IsSorted()
const override {
87 bool Add(
const char *item)
override {
88 if (!item)
return false;
89 return TryAddItem(
String(item));
91 void Clear()
override {
92 for (
auto it = _set.begin(); it != _set.end(); ++it)
96 bool Contains(
const char *item)
const override {
97 return _set.count(String::Wrapper(item)) != 0;
99 bool Remove(
const char *item)
override {
100 auto it = _set.find(String::Wrapper(item));
101 if (it == _set.end())
return false;
106 int GetItemCount()
const override {
110 for (
auto it = _set.begin(); it != _set.end(); ++it)
115 bool TryAddItem(
const String &s) {
116 return _set.insert(s)._value;
118 void DeleteItem(ConstIterator ) { }
120 size_t CalcSerializeSize()
override {
122 size_t total_sz =
sizeof(int32_t) * 3;
124 for (
auto it = _set.begin(); it != _set.end(); ++it)
125 total_sz +=
sizeof(int32_t) + it->GetLength();
130 out->WriteInt32((
int)_set.size());
131 for (
auto it = _set.begin(); it != _set.end(); ++it) {
132 out->WriteInt32((
int)it->GetLength());
133 out->Write(it->GetCStr(), it->GetLength());
138 size_t item_count = in->ReadInt32();
139 for (
size_t i = 0; i < item_count; ++i) {
140 size_t len = in->ReadInt32();
141 String item = String::FromStreamCount(in, len);
void push_back(const T &element)
Definition: array.h:180
Definition: script_set.h:74
Definition: cc_ags_dynamic_object.h:31
Definition: script_set.h:48