| 122 | } |
| 123 | |
| 124 | void RocksDbSerializer::write_streaming_() { |
| 125 | const auto& input_filename = std::get<std::string>(file_); |
| 126 | |
| 127 | IfcParse::impl::rocks_db_file_storage storage(rocksdb_filename_, nullptr); |
| 128 | |
| 129 | std::string tmp; |
| 130 | |
| 131 | IfcParse::InstanceStreamer streamer(input_filename); |
| 132 | |
| 133 | // We do not want to coerce attribute counts here, because we want |
| 134 | // to store exactly what is in the file for validation purposes |
| 135 | streamer.coerce_attribute_count = false; |
| 136 | |
| 137 | while (streamer) { |
| 138 | auto inst = streamer.readInstance(); |
| 139 | if (inst) { |
| 140 | // name can be zero in case of header instances |
| 141 | auto name = std::get<0>(*inst); |
| 142 | const auto* decl = std::get<1>(*inst); |
| 143 | const auto& data = std::get<2>(*inst); |
| 144 | |
| 145 | const bool is_header = decl->schema() == &Header_section_schema::get_schema(); |
| 146 | |
| 147 | std::vector<IfcUtil::IfcBaseClass*> simple_type_instances; |
| 148 | |
| 149 | for (size_t i = 0; i < data.storage_->size(); i++) { |
| 150 | auto val = data.get_attribute_value(nullptr, decl, 0, i); |
| 151 | val.apply_visitor([&](const auto& t) { |
| 152 | using T = std::decay_t<decltype(t)>; |
| 153 | if constexpr (std::is_same_v<T, IfcUtil::IfcBaseClass*>) { |
| 154 | // instance is per definition a simple type here, because instance |
| 155 | // references are not resolved yet, but provided in vector of |
| 156 | // references |
| 157 | simple_type_instances.push_back(t); |
| 158 | } |
| 159 | rocks_db_attribute_storage{}.set(&storage, decl, name, i, t); |
| 160 | }); |
| 161 | } |
| 162 | |
| 163 | std::set<size_t> type_identities_wrote_as_refs; |
| 164 | |
| 165 | for (auto& p : streamer.references()) { |
| 166 | // @nb cast to int in order not be interpreted as a char when appending to string |
| 167 | int index = p.first.index_; |
| 168 | |
| 169 | auto key = (is_header ? "h|" : (decl->as_entity() ? "i|" : "t|")) + |
| 170 | (is_header ? decl->name() : std::to_string(p.first.name_)) + "|" + |
| 171 | std::to_string(index); |
| 172 | |
| 173 | if (storage.db->Get(storage.ropts, key, &tmp) == rocksdb::Status::OK() && tmp.size() == (sizeof(size_t) + 2) && tmp[0] == TypeEncoder::encode_type<IfcUtil::IfcBaseClass*>() && tmp[1] == 't') |
| 174 | { |
| 175 | size_t iden; |
| 176 | memcpy(&iden, tmp.data() + 2, sizeof(size_t)); |
| 177 | key = "t|" + std::to_string(iden) + "|0"; |
| 178 | type_identities_wrote_as_refs.insert(iden); |
| 179 | } |
| 180 | |
| 181 | std::visit([&](const auto& v) { |
nothing calls this directly
no test coverage detected