MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / assert_existance

Method assert_existance

src/ifcparse/IfcFile.cpp:361–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361IfcUtil::IfcBaseClass* IfcParse::impl::rocks_db_file_storage::assert_existance(size_t number, instance_ref r) {
362#ifdef IFOPSH_WITH_ROCKSDB
363 if (r == IfcParse::impl::rocks_db_file_storage::entityinstance_ref) {
364 auto it = instance_cache_.find(number);
365 if (it != instance_cache_.end()) {
366 return it->second;
367 }
368 } else {
369 auto it = type_instance_cache_.find(number);
370 if (it != type_instance_cache_.end()) {
371 return it->second;
372 }
373 }
374
375 std::string v;
376
377 rocksdb::Status s = db->Get(rocksdb::ReadOptions{}, (r == entityinstance_ref ? "i|" : "t|") + std::to_string(number) + "|_", &v);
378 if (s.ok()) {
379 size_t s;
380 memcpy(&s, v.data(), sizeof(size_t));
381 if (s >= file->schema()->declarations().size()) {
382 throw std::runtime_error("");
383 }
384 auto decl = file->schema()->declarations()[s];
385 bool is_entity = decl->as_entity() != nullptr;
386 if (is_entity != (r == entityinstance_ref)) {
387 throw std::runtime_error("Incorrect reference");
388 }
389 IfcEntityInstanceData data(rocks_db_attribute_storage{});
390 IfcUtil::IfcBaseClass* inst;
391 if (file->instantiate_typed_instances) {
392 inst = file->schema()->instantiate(decl, std::move(data));
393 } else {
394 inst = new IfcUtil::IfcLateBoundEntity(decl, std::move(data));
395 }
396 inst->id_ = number;
397 inst->file_ = file;
398 if (r == IfcParse::impl::rocks_db_file_storage::entityinstance_ref) {
399 instance_cache_.insert({ number, inst });
400 } else {
401 type_instance_cache_.insert({ number, inst });
402 }
403 return inst;
404 } else {
405 throw IfcException("Instance #" + boost::lexical_cast<std::string>(number) + " not found");
406 }
407#else
408 throw IfcException("RocksDB support not compiled in");
409#endif
410}
411
412namespace {
413 rocksdb::DB* init_db(const std::string& filepath, bool readonly) {

Callers 3

deserializeMethod · 0.80

Calls 9

to_stringFunction · 0.85
GetMethod · 0.80
dataMethod · 0.80
instantiateMethod · 0.80
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
schemaMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected