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(
const char *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;
75 template <
typename TDict,
bool is_sorted,
bool is_casesensitive>
78 typedef typename TDict::const_iterator ConstIterator;
82 bool IsCaseSensitive()
const override {
83 return is_casesensitive;
85 bool IsSorted()
const override {
89 void Clear()
override {
90 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
94 bool Contains(
const char *key)
override {
95 #ifdef AGS_PLATFORM_SCUMMVM 96 return _dic.find(String::Wrapper(key)) != _dic.end();
98 return _dic.count(String::Wrapper(key)) != 0;
101 const char *Get(
const char *key)
override {
102 auto it = _dic.find(String::Wrapper(key));
103 if (it == _dic.end())
return nullptr;
104 return it->_value.GetCStr();
106 bool Remove(
const char *key)
override {
107 auto it = _dic.find(String::Wrapper(key));
108 if (it == _dic.end())
return false;
113 bool Set(
const char *key,
const char *value)
override {
124 int GetItemCount()
override {
128 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
132 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
137 bool TryAddItem(
const String &key,
const String &value) {
141 void DeleteItem(ConstIterator ) { }
143 size_t CalcSerializeSize()
override {
145 size_t total_sz =
sizeof(int32_t) * 3;
147 for (
auto it = _dic.begin(); it != _dic.end(); ++it) {
148 total_sz +=
sizeof(int32_t) + it->_key.GetLength();
149 total_sz +=
sizeof(int32_t) + it->_value.GetLength();
156 out->WriteInt32((
int)_dic.size());
157 for (
auto it = _dic.begin(); it != _dic.end(); ++it)
159 out->WriteInt32((
int)it->_key.GetLength());
160 out->Write(it->_key.GetCStr(), it->_key.GetLength());
161 out->WriteInt32((
int)it->_value.GetLength());
162 out->Write(it->_value.GetCStr(), it->_value.GetLength());
167 size_t item_count = in->ReadInt32();
168 for (
size_t i = 0; i < item_count; ++i) {
169 size_t key_len = in->ReadInt32();
170 String key = String::FromStreamCount(in, key_len);
171 size_t value_len = in->ReadInt32();
172 if (value_len != (
size_t)-1)
174 String value = String::FromStreamCount(in, value_len);
175 TryAddItem(key, value);
void push_back(const T &element)
Definition: array.h:180
Definition: script_dict.h:49
Definition: cc_ags_dynamic_object.h:31
Definition: script_dict.h:76