| 359 | } |
| 360 | |
| 361 | IfcUtil::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 | |
| 412 | namespace { |
| 413 | rocksdb::DB* init_db(const std::string& filepath, bool readonly) { |
no test coverage detected