mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Some successes writing and reading
This commit is contained in:
@@ -43,8 +43,8 @@ namespace {
|
||||
!std::is_same_v<std::remove_cv_t<std::remove_pointer_t<T>>, IfcUtil::IfcBaseClass>)
|
||||
{
|
||||
std::string str;
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "a|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
impl::deserialize(str, val);
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "i|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
impl::deserialize(array_.db_ptr, str, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace {
|
||||
return array_.storage_ptr->has<T>(index_);
|
||||
} else {
|
||||
std::string str;
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "a|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "i|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
return str[0] == TypeEncoder::encode_type<T>();
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace {
|
||||
return array_.storage_ptr->index(index_);
|
||||
} else {
|
||||
std::string str;
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "a|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "i|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
return (size_t) str[0] - 'A';
|
||||
}
|
||||
}
|
||||
@@ -107,11 +107,11 @@ AttributeValue::operator std::string() const
|
||||
return dispatch_get_<EnumerationReference>(array_, storage_model_, instance_name_, index_).value();
|
||||
} else {
|
||||
std::string str;
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "a|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "i|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
size_t v;
|
||||
memcpy(&v, str.data() + 1, sizeof(size_t));
|
||||
auto decl = schema_->declarations()[v]->as_enumeration_type();
|
||||
memcpy(&v, str.data() + 5, sizeof(size_t));
|
||||
memcpy(&v, str.data() + 1 + sizeof(size_t), sizeof(size_t));
|
||||
return decl->lookup_enum_value(v);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ AttributeValue::operator EnumerationReference() const
|
||||
return dispatch_get_<EnumerationReference>(array_, storage_model_, instance_name_, index_);
|
||||
} else {
|
||||
std::string str;
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "a|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "i|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
size_t v;
|
||||
memcpy(&v, str.data() + 1, sizeof(size_t));
|
||||
auto decl = schema_->declarations()[v]->as_enumeration_type();
|
||||
@@ -144,12 +144,17 @@ AttributeValue::operator IfcUtil::IfcBaseClass* () const
|
||||
return dispatch_get_<IfcUtil::IfcBaseClass*>(array_, storage_model_, instance_name_, index_);
|
||||
} else {
|
||||
std::string str;
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "a|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
array_.db_ptr->db->Get(rocksdb::ReadOptions{}, "i|" + std::to_string(instance_name_) + "|" + std::to_string(index_), &str);
|
||||
size_t v;
|
||||
memcpy(&v, str.data() + 1, sizeof(size_t));
|
||||
auto decl = schema_->declarations()[v]->as_enumeration_type();
|
||||
memcpy(&v, str.data() + 5, sizeof(size_t));
|
||||
return array_.db_ptr->assert_existance(v);
|
||||
memcpy(&v, str.data() + 2, sizeof(size_t));
|
||||
if (str[1] == 'e') {
|
||||
// entity reference, by #Name
|
||||
return array_.db_ptr->assert_existance(v, IfcParse::impl::rocks_db_file_storage::by_name);
|
||||
} else if (str[1] == 't') {
|
||||
// type reference by Identity
|
||||
return array_.db_ptr->assert_existance(v, IfcParse::impl::rocks_db_file_storage::by_identity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +221,7 @@ bool impl::serialize(std::string& val, const IfcUtil::IfcBaseClass* t)
|
||||
val[0] = TypeEncoder::encode_type<IfcUtil::IfcBaseClass*>();
|
||||
// 1 = entity - stored by id (entity name)
|
||||
// 2 = type - stored by identity (internal counter in class)
|
||||
val[1] = t->declaration().as_entity() ? 1 : 2;
|
||||
val[1] = t->declaration().as_entity() ? 'e' : 't';
|
||||
size_t iden = t->declaration().as_entity() ? t->id() : t->identity();
|
||||
memcpy(val.data() + 2, &iden, s);
|
||||
return true;
|
||||
@@ -230,16 +235,24 @@ bool impl::serialize(std::string& val, const EnumerationReference& v)
|
||||
size_t vv = v.enumeration()->index_in_schema();
|
||||
memcpy(val.data() + 1, &vv, sizeof(size_t));
|
||||
vv = v.index();
|
||||
memcpy(val.data() + 1, &vv, sizeof(size_t));
|
||||
memcpy(val.data() + 1 + sizeof(size_t), &vv, sizeof(size_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool impl::serialize(std::string& val, const aggregate_of_instance::ptr& t)
|
||||
{
|
||||
std::vector<size_t> ids;
|
||||
// @nb this has to be identity, because needs to work for typedecls as well
|
||||
std::transform(t->begin(), t->end(), std::back_inserter(ids), [](auto& x) { return x->identity(); });
|
||||
return false;
|
||||
// no attempt at alignment
|
||||
val.resize(t->size() * (sizeof(size_t) + 1) + 1);
|
||||
val[0] = TypeEncoder::encode_type<EnumerationReference>();
|
||||
char* ptr = val.data() + 1;
|
||||
for (auto it = t->begin(); it != t->end(); ++it) {
|
||||
*ptr = (*it)->declaration().as_entity() ? 'e' : 't';
|
||||
ptr++;
|
||||
size_t iden = (*it)->declaration().as_entity() ? (*it)->id() : (*it)->identity();
|
||||
memcpy(ptr, &iden, sizeof(size_t));
|
||||
ptr += sizeof(size_t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool impl::serialize(std::string& val, const aggregate_of_aggregate_of_instance::ptr& t)
|
||||
@@ -282,7 +295,7 @@ bool impl::serialize(std::string& val, const boost::dynamic_bitset<>& t)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool impl::deserialize(std::string& val, boost::logic::tribool& t) {
|
||||
bool impl::deserialize(IfcParse::impl::rocks_db_file_storage*, const std::string& val, boost::logic::tribool& t) {
|
||||
if (val[0] != TypeEncoder::encode_type<boost::logic::tribool>()) {
|
||||
return false;
|
||||
}
|
||||
@@ -297,7 +310,7 @@ bool impl::deserialize(std::string& val, boost::logic::tribool& t) {
|
||||
}
|
||||
}
|
||||
|
||||
bool impl::deserialize(std::string& val, boost::dynamic_bitset<>& t) {
|
||||
bool impl::deserialize(IfcParse::impl::rocks_db_file_storage*, const std::string& val, boost::dynamic_bitset<>& t) {
|
||||
if (val[0] != TypeEncoder::encode_type<boost::dynamic_bitset<>>()) {
|
||||
return false;
|
||||
}
|
||||
@@ -305,41 +318,64 @@ bool impl::deserialize(std::string& val, boost::dynamic_bitset<>& t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool impl::deserialize(std::string& val, aggregate_of_instance::ptr& t) {
|
||||
return false;
|
||||
bool impl::deserialize(IfcParse::impl::rocks_db_file_storage* storage, const std::string& val, aggregate_of_instance::ptr& t) {
|
||||
t.reset(new aggregate_of_instance);
|
||||
// val[0] = TypeEncoder::encode_type<EnumerationReference>();
|
||||
auto n = (val.size() - 1) / (sizeof(size_t) + 1);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
auto ptr = val.data() + 1 + (sizeof(size_t) + 1) * i;
|
||||
auto tt = *ptr;
|
||||
ptr++;
|
||||
size_t v;
|
||||
memcpy(&v, ptr, sizeof(size_t));
|
||||
if (tt == 'e') {
|
||||
t->push(storage->assert_existance(v, IfcParse::impl::rocks_db_file_storage::by_name));
|
||||
} else if (tt == 't') {
|
||||
t->push(storage->assert_existance(v, IfcParse::impl::rocks_db_file_storage::by_identity));
|
||||
} else {
|
||||
throw std::runtime_error("");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool impl::deserialize(std::string& val, aggregate_of_aggregate_of_instance::ptr& t) {
|
||||
bool impl::deserialize(IfcParse::impl::rocks_db_file_storage*, const std::string& val, aggregate_of_aggregate_of_instance::ptr& t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void rocks_db_attribute_storage::set(std::size_t index, const T& value)
|
||||
void rocks_db_attribute_storage::set(void* storage, const IfcParse::declaration* decl, std::size_t identity, std::size_t index, const T& value)
|
||||
{
|
||||
const bool is_header = decl->schema() == &Header_section_schema::get_schema();
|
||||
IfcParse::impl::rocks_db_file_storage* rdb_storage = (IfcParse::impl::rocks_db_file_storage*)storage;
|
||||
std::string v;
|
||||
impl::serialize(v, value);
|
||||
fs_->db->Put(rocksdb::WriteOptions{}, prefix_ + ("|" + std::to_string(index)), v);
|
||||
rdb_storage->db->Put(
|
||||
rocksdb::WriteOptions{},
|
||||
(is_header ? "h|" : "i|") +
|
||||
(is_header ? decl->name() : std::to_string(identity)) + "|" +
|
||||
std::to_string(index), v);
|
||||
}
|
||||
|
||||
template void rocks_db_attribute_storage::set<Blank>(size_t index, const Blank& value);
|
||||
template void rocks_db_attribute_storage::set<int>(size_t index, const int& value);
|
||||
template void rocks_db_attribute_storage::set<bool>(size_t index, const bool& value);
|
||||
template void rocks_db_attribute_storage::set<boost::logic::tribool>(size_t index, const boost::logic::tribool& value);
|
||||
template void rocks_db_attribute_storage::set<double>(size_t index, const double& value);
|
||||
template void rocks_db_attribute_storage::set<std::string>(size_t index, const std::string& value);
|
||||
template void rocks_db_attribute_storage::set<boost::dynamic_bitset<>>(size_t index, const boost::dynamic_bitset<>& value);
|
||||
template void rocks_db_attribute_storage::set<EnumerationReference>(size_t index, const EnumerationReference& value);
|
||||
template void rocks_db_attribute_storage::set<IfcUtil::IfcBaseClass*>(size_t index, IfcUtil::IfcBaseClass* const& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<int>>(size_t index, const std::vector<int>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<double>>(size_t index, const std::vector<double>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<std::string>>(size_t index, const std::vector<std::string>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<boost::dynamic_bitset<>>>(size_t index, const std::vector<boost::dynamic_bitset<>>& value);
|
||||
template void rocks_db_attribute_storage::set<aggregate_of_instance::ptr>(size_t index, const aggregate_of_instance::ptr& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<std::vector<int>>>(size_t index, const std::vector<std::vector<int>>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<std::vector<double>>>(size_t index, const std::vector<std::vector<double>>& value);
|
||||
template void rocks_db_attribute_storage::set<aggregate_of_aggregate_of_instance::ptr>(size_t index, const aggregate_of_aggregate_of_instance::ptr& value);
|
||||
template void rocks_db_attribute_storage::set<Blank>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const Blank& value);
|
||||
template void rocks_db_attribute_storage::set<int>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const int& value);
|
||||
template void rocks_db_attribute_storage::set<bool>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const bool& value);
|
||||
template void rocks_db_attribute_storage::set<boost::logic::tribool>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const boost::logic::tribool& value);
|
||||
template void rocks_db_attribute_storage::set<double>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const double& value);
|
||||
template void rocks_db_attribute_storage::set<std::string>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::string& value);
|
||||
template void rocks_db_attribute_storage::set<boost::dynamic_bitset<>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const boost::dynamic_bitset<>& value);
|
||||
template void rocks_db_attribute_storage::set<EnumerationReference>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const EnumerationReference& value);
|
||||
template void rocks_db_attribute_storage::set<IfcUtil::IfcBaseClass*>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, IfcUtil::IfcBaseClass* const& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<int>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::vector<int>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<double>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::vector<double>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<std::string>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::vector<std::string>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<boost::dynamic_bitset<>>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::vector<boost::dynamic_bitset<>>& value);
|
||||
template void rocks_db_attribute_storage::set<aggregate_of_instance::ptr>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const aggregate_of_instance::ptr& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<std::vector<int>>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::vector<std::vector<int>>& value);
|
||||
template void rocks_db_attribute_storage::set<std::vector<std::vector<double>>>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const std::vector<std::vector<double>>& value);
|
||||
template void rocks_db_attribute_storage::set<aggregate_of_aggregate_of_instance::ptr>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const aggregate_of_aggregate_of_instance::ptr& value);
|
||||
|
||||
// @todo why do these need to be included, but are not in BaseEntity::set()?
|
||||
template void rocks_db_attribute_storage::set<Derived>(size_t index, const Derived& value);
|
||||
template void rocks_db_attribute_storage::set<empty_aggregate_t>(size_t index, const empty_aggregate_t& value);
|
||||
template void rocks_db_attribute_storage::set<empty_aggregate_of_aggregate_t>(size_t index, const empty_aggregate_of_aggregate_t& value);
|
||||
template void rocks_db_attribute_storage::set<Derived>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const Derived& value);
|
||||
template void rocks_db_attribute_storage::set<empty_aggregate_t>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const empty_aggregate_t& value);
|
||||
template void rocks_db_attribute_storage::set<empty_aggregate_of_aggregate_t>(void* storage, const IfcParse::declaration* decl, std::size_t identity, size_t index, const empty_aggregate_of_aggregate_t& value);
|
||||
|
||||
Reference in New Issue
Block a user