2021-12-05 17:54:36 +00:00
|
|
|
#include "CDComponentsRegistryTable.h"
|
|
|
|
|
|
|
|
#define CDCLIENT_CACHE_ALL
|
|
|
|
|
|
|
|
//! Constructor
|
|
|
|
CDComponentsRegistryTable::CDComponentsRegistryTable(void) {
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
#ifdef CDCLIENT_CACHE_ALL
|
2022-07-28 13:39:57 +00:00
|
|
|
// First, get the size of the table
|
|
|
|
unsigned int size = 0;
|
|
|
|
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ComponentsRegistry");
|
|
|
|
while (!tableSize.eof()) {
|
|
|
|
size = tableSize.getIntField(0, 0);
|
|
|
|
|
|
|
|
tableSize.nextRow();
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
tableSize.finalize();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
// Reserve the size
|
|
|
|
//this->entries.reserve(size);
|
|
|
|
|
|
|
|
// Now get the data
|
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ComponentsRegistry");
|
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDComponentsRegistry entry;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.id = tableData.getIntField("id", -1);
|
|
|
|
entry.component_type = tableData.getIntField("component_type", -1);
|
|
|
|
entry.component_id = tableData.getIntField("component_id", -1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id);
|
|
|
|
|
|
|
|
//this->entries.push_back(entry);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
//Darwin's stuff:
|
|
|
|
const auto& it = this->mappedEntries.find(entry.id);
|
|
|
|
if (it != mappedEntries.end()) {
|
|
|
|
const auto& iter = it->second.find(entry.component_type);
|
|
|
|
if (iter == it->second.end()) {
|
|
|
|
it->second.insert(std::make_pair(entry.component_type, entry.component_id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::map<unsigned int, unsigned int> map;
|
|
|
|
map.insert(std::make_pair(entry.component_type, entry.component_id));
|
|
|
|
this->mappedEntries.insert(std::make_pair(entry.id, map));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
tableData.finalize();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Destructor
|
2022-07-28 13:39:57 +00:00
|
|
|
CDComponentsRegistryTable::~CDComponentsRegistryTable(void) {}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//! Returns the table's name
|
|
|
|
std::string CDComponentsRegistryTable::GetName(void) const {
|
2022-07-28 13:39:57 +00:00
|
|
|
return "ComponentsRegistry";
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, uint32_t componentType, int32_t defaultValue) {
|
|
|
|
const auto& iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (iter == this->mappedEntries.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iter->second;
|
|
|
|
|
|
|
|
/*
|
|
|
|
const auto& it = this->mappedEntries.find(id);
|
|
|
|
if (it != mappedEntries.end()) {
|
|
|
|
const auto& iter = it->second.find(componentType);
|
|
|
|
if (iter != it->second.end()) {
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CDCLIENT_CACHE_ALL
|
2022-07-28 13:39:57 +00:00
|
|
|
// Now get the data
|
2021-12-05 17:54:36 +00:00
|
|
|
std::stringstream query;
|
|
|
|
|
|
|
|
query << "SELECT * FROM ComponentsRegistry WHERE id = " << std::to_string(id);
|
|
|
|
|
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
|
2022-07-28 13:39:57 +00:00
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDComponentsRegistry entry;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.id = tableData.getIntField("id", -1);
|
|
|
|
entry.component_type = tableData.getIntField("component_type", -1);
|
|
|
|
entry.component_id = tableData.getIntField("component_id", -1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
//this->entries.push_back(entry);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//Darwin's stuff:
|
|
|
|
const auto& it = this->mappedEntries.find(entry.id);
|
|
|
|
if (it != mappedEntries.end()) {
|
|
|
|
const auto& iter = it->second.find(entry.component_type);
|
|
|
|
if (iter == it->second.end()) {
|
|
|
|
it->second.insert(std::make_pair(entry.component_type, entry.component_id));
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2021-12-05 17:54:36 +00:00
|
|
|
std::map<unsigned int, unsigned int> map;
|
|
|
|
map.insert(std::make_pair(entry.component_type, entry.component_id));
|
|
|
|
this->mappedEntries.insert(std::make_pair(entry.id, map));
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
tableData.finalize();
|
|
|
|
|
|
|
|
const auto& it2 = this->mappedEntries.find(id);
|
|
|
|
if (it2 != mappedEntries.end()) {
|
|
|
|
const auto& iter = it2->second.find(componentType);
|
|
|
|
if (iter != it2->second.end()) {
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
#endif
|
|
|
|
}
|
2023-01-07 09:48:59 +00:00
|
|
|
|