1
0
mirror of https://github.com/anope/anope.git synced 2026-07-07 02:03:15 +02:00

Move serialization data type logic from sql.h to the core.

This commit is contained in:
Sadie Powell
2025-03-11 13:05:43 +00:00
parent fb0ee27df0
commit 2276c62ff0
3 changed files with 19 additions and 17 deletions
-14
View File
@@ -19,7 +19,6 @@ namespace SQL
public:
typedef std::map<Anope::string, std::stringstream *> Map;
Map data;
std::map<Anope::string, Serialize::DataType> types;
~Data()
{
@@ -59,19 +58,6 @@ namespace SQL
delete value;
this->data.clear();
}
void SetType(const Anope::string &key, Serialize::DataType dt) override
{
this->types[key] = dt;
}
Serialize::DataType GetType(const Anope::string &key) const override
{
auto it = this->types.find(key);
if (it != this->types.end())
return it->second;
return Serialize::DataType::TEXT;
}
};
/** A SQL exception, can be thrown at various points
+6 -3
View File
@@ -28,8 +28,11 @@ namespace Serialize
UINT,
};
class Data
class CoreExport Data
{
protected:
std::map<Anope::string, Serialize::DataType> types;
public:
virtual ~Data() = default;
@@ -54,8 +57,8 @@ namespace Serialize
virtual size_t Hash() const { throw CoreException("Not supported"); }
virtual void SetType(const Anope::string &key, DataType dt) { }
virtual DataType GetType(const Anope::string &key) const { return DataType::TEXT; }
Serialize::DataType GetType(const Anope::string &key) const;
void SetType(const Anope::string &key, Serialize::DataType dt);
};
extern void RegisterTypes();
+13
View File
@@ -111,6 +111,19 @@ const std::list<Serializable *> &Serializable::GetItems()
return *SerializableItems;
}
Serialize::DataType Serialize::Data::GetType(const Anope::string &key) const
{
auto it = this->types.find(key);
if (it != this->types.end())
return it->second;
return Serialize::DataType::TEXT;
}
void Serialize::Data::SetType(const Anope::string &key, Serialize::DataType dt)
{
this->types[key] = dt;
}
Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), unserialize(f), owner(o)
{
TypeOrder.push_back(this->name);