| 153 | } |
| 154 | |
| 155 | uint64_t Hd3Block::Write(std::streambuf& buffer) { |
| 156 | const bool update = |
| 157 | FilePosition() > 0; // Write or update the values inside the block |
| 158 | if (!update) { |
| 159 | block_type_ = "HD"; |
| 160 | block_size_ = (2 + 2) + (3 * 4) + 2 + 10 + 8 + 4 * 32 + 3 * 2 + 32; |
| 161 | link_list_.resize(3, 0); |
| 162 | } |
| 163 | |
| 164 | uint64_t bytes = update ? MdfBlock::Update(buffer) : MdfBlock::Write(buffer); |
| 165 | |
| 166 | nof_dg_blocks_ = static_cast<uint16_t>(dg_list_.size()); |
| 167 | bytes += WriteNumber(buffer, nof_dg_blocks_); |
| 168 | bytes += WriteStr(buffer, timestamp_.date_, 10); |
| 169 | bytes += WriteStr(buffer, timestamp_.time_, 8); |
| 170 | bytes += WriteStr(buffer, author_, 32); |
| 171 | bytes += WriteStr(buffer, organisation_, 32); |
| 172 | bytes += WriteStr(buffer, project_, 32); |
| 173 | bytes += WriteStr(buffer, subject_, 32); |
| 174 | bytes += WriteNumber(buffer, timestamp_.local_timestamp_); |
| 175 | bytes += WriteNumber(buffer, timestamp_.utc_offset_); |
| 176 | bytes += WriteNumber(buffer, timestamp_.time_quality_); |
| 177 | bytes += WriteStr(buffer, timestamp_.timer_id_, 32); |
| 178 | |
| 179 | if (!update) { |
| 180 | UpdateBlockSize(buffer, bytes); |
| 181 | } |
| 182 | |
| 183 | if (!comment_.empty() && Link(kIndexTx) <= 0) { |
| 184 | Tx3Block tx(comment_); |
| 185 | tx.Init(*this); |
| 186 | tx.Write(buffer); |
| 187 | UpdateLink(buffer, kIndexTx, tx.FilePosition()); |
| 188 | } |
| 189 | |
| 190 | if (pr_block_ && Link(kIndexPr) <= 0) { |
| 191 | pr_block_->Init(*this); |
| 192 | pr_block_->Write(buffer); |
| 193 | UpdateLink(buffer, kIndexPr, pr_block_->FilePosition()); |
| 194 | } |
| 195 | |
| 196 | for (size_t index = 0; index < dg_list_.size(); ++index) { |
| 197 | auto &dg3 = dg_list_[index]; |
| 198 | if (!dg3) { |
| 199 | continue; |
| 200 | } |
| 201 | |
| 202 | // Only last DG is updated |
| 203 | const bool last_dg = |
| 204 | index + 1 >= dg_list_.size(); // Only last DG is updated |
| 205 | if (!last_dg && dg3->FilePosition() > 0) { |
| 206 | continue; |
| 207 | } |
| 208 | |
| 209 | dg3->Write(buffer); |
| 210 | if (index == 0) { |
| 211 | UpdateLink(buffer, kIndexDg, dg3->FilePosition()); |
| 212 | } else { |
nothing calls this directly
no test coverage detected