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

Method write_streaming_

src/serializers/RocksDbSerializer.cpp:124–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124void 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) {

Callers

nothing calls this directly

Calls 15

get_schemaFunction · 0.85
to_stringFunction · 0.85
readInstanceMethod · 0.80
get_attribute_valueMethod · 0.80
apply_visitorMethod · 0.80
push_backMethod · 0.80
GetMethod · 0.80
dataMethod · 0.80
resizeMethod · 0.80
MergeMethod · 0.80
serializeFunction · 0.70
to_string_fixed_widthFunction · 0.70

Tested by

no test coverage detected