35 #ifndef AGS_ENGINE_AC_DYNOBJ_SCRIPTDICT_H 36 #define AGS_ENGINE_AC_DYNOBJ_SCRIPTDICT_H 38 #include "common/std/map.h" 39 #include "common/std/map.h" 40 #include "ags/engine/ac/dynobj/cc_ags_dynamic_object.h" 41 #include "ags/shared/util/stream.h" 42 #include "ags/shared/util/string.h" 43 #include "ags/shared/util/string_types.h" 47 using namespace AGS::Shared;
51 int Dispose(
void *address,
bool force)
override;
52 const char *GetType()
override;
55 virtual bool IsCaseSensitive()
const = 0;
56 virtual bool IsSorted()
const = 0;
58 virtual void Clear() = 0;
59 virtual bool Contains(
const char *key) = 0;
60 virtual const char *Get(
const char *key) = 0;
61 virtual bool Remove(
const char *key) = 0;
62 virtual bool Set(
const char *key,
const char *value) = 0;
63 virtual int GetItemCount() = 0;
68 size_t CalcSerializeSize(
const void *address)
override;
73 virtual size_t CalcContainerSize() = 0;
78 template <
typename TDict,
bool is_sorted,
bool is_casesensitive>
81 typedef typename TDict::const_iterator ConstIterator;
85 bool IsCaseSensitive()
const override {
86 return is_casesensitive;
88 bool IsSorted()
const override {
92 void Clear()
override {
93 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
97 bool Contains(
const char *key)
override {
98 #ifdef AGS_PLATFORM_SCUMMVM 99 return _dic.find(String::Wrapper(key)) != _dic.end();
101 return _dic.count(String::Wrapper(key)) != 0;
104 const char *Get(
const char *key)
override {
105 auto it = _dic.find(String::Wrapper(key));
106 if (it == _dic.end())
return nullptr;
107 return it->_value.GetCStr();
109 bool Remove(
const char *key)
override {
110 auto it = _dic.find(String::Wrapper(key));
111 if (it == _dic.end())
return false;
116 bool Set(
const char *key,
const char *value)
override {
127 int GetItemCount()
override {
131 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
135 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
140 bool TryAddItem(
const String &key,
const String &value) {
144 void DeleteItem(ConstIterator ) { }
146 size_t CalcContainerSize()
override {
148 size_t total_sz =
sizeof(int32_t) * 3;
150 for (
auto it = _dic.begin(); it != _dic.end(); ++it) {
151 total_sz +=
sizeof(int32_t) + it->_key.GetLength();
152 total_sz +=
sizeof(int32_t) + it->_value.GetLength();
159 out->WriteInt32((
int)_dic.size());
160 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
162 out->WriteInt32((
int)it->_key.GetLength());
163 out->Write(it->_key.GetCStr(), it->_key.GetLength());
164 out->WriteInt32((
int)it->_value.GetLength());
165 out->Write(it->_value.GetCStr(), it->_value.GetLength());
170 size_t item_count = in->ReadInt32();
171 for (
size_t i = 0; i < item_count; ++i) {
172 size_t key_len = in->ReadInt32();
173 String key = String::FromStreamCount(in, key_len);
174 size_t value_len = in->ReadInt32();
175 if (value_len != (
size_t)-1)
177 String value = String::FromStreamCount(in, value_len);
178 TryAddItem(key, value);
void push_back(const T &element)
Definition: array.h:180
Definition: script_dict.h:49
Definition: cc_ags_dynamic_object.h:88
Definition: script_dict.h:79