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(
void *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;
66 virtual size_t CalcSerializeSize(
const void *address)
override;
71 virtual size_t CalcContainerSize() = 0;
76 template <
typename TSet,
bool is_sorted,
bool is_casesensitive>
79 typedef typename TSet::const_iterator ConstIterator;
83 bool IsCaseSensitive()
const override {
84 return is_casesensitive;
86 bool IsSorted()
const override {
90 bool Add(
const char *item)
override {
91 if (!item)
return false;
92 return TryAddItem(
String(item));
94 void Clear()
override {
95 for (
auto it = _set.begin(); it != _set.end(); ++it)
99 bool Contains(
const char *item)
const override {
100 return _set.count(String::Wrapper(item)) != 0;
102 bool Remove(
const char *item)
override {
103 auto it = _set.find(String::Wrapper(item));
104 if (it == _set.end())
return false;
109 int GetItemCount()
const override {
113 for (
auto it = _set.begin(); it != _set.end(); ++it)
118 bool TryAddItem(
const String &s) {
119 return _set.insert(s)._value;
121 void DeleteItem(ConstIterator ) { }
123 size_t CalcContainerSize()
override {
125 size_t total_sz =
sizeof(int32_t) * 3;
127 for (
auto it = _set.begin(); it != _set.end(); ++it)
128 total_sz +=
sizeof(int32_t) + it->GetLength();
133 out->WriteInt32((
int)_set.size());
134 for (
auto it = _set.begin(); it != _set.end(); ++it) {
135 out->WriteInt32((
int)it->GetLength());
136 out->Write(it->GetCStr(), it->GetLength());
141 size_t item_count = in->ReadInt32();
142 for (
size_t i = 0; i < item_count; ++i) {
143 size_t len = in->ReadInt32();
144 String item = String::FromStreamCount(in, len);
void push_back(const T &element)
Definition: array.h:180
Definition: script_set.h:77
Definition: cc_ags_dynamic_object.h:88
Definition: script_set.h:48