5#ifndef GEMMI_TO_CIF_HPP_
6#define GEMMI_TO_CIF_HPP_
62 std::string
str()
const {
71 s +=
"align_pairs=" + std::to_string(
align_pairs) +
",";
73 s +=
"align_loops=" + std::to_string(
align_loops) +
",";
87 os.write(buf, ptr - buf);
90 void write(
const char* s,
size_t len) {
91 constexpr int margin =
sizeof(buf) - 512;
92 if (ptr - buf + len >
margin) {
99 std::memcpy(ptr, s, len);
103 write(s.c_str(), s.size());
110 std::memset(ptr,
' ', n);
125 for (
size_t pos = 0, end = 0; end != std::string::npos; pos = end + 1) {
126 end = value.find(
"\r\n", pos);
127 size_t len = (end == std::string::npos ? value.size() : end) - pos;
128 os.
write(value.c_str() + pos, len);
139 if (name.size() + value.size() > 120) {
143 if (name.size() <
options.align_pairs)
155 for (
size_t i = 0;
i != loop.
tags.size(); ++
i)
160 os.
write(
"loop_", 5);
161 for (
const std::string& tag : loop.
tags) {
171 for (
const std::string& val : loop.
values) {
178 w = std::min(w, (
size_t)
options.align_loops);
183 for (
const std::string& val : loop.
values) {
191 if (col !=
ncol - 1) {
212 os.
write(
"save_", 5);
217 os.
write(
"save_\n", 6);
228inline bool should_be_separated_(
const Item& a,
const Item& b) {
234 auto adot = a.pair[0].find(
'.');
235 if (
adot == std::string::npos)
237 auto bdot = b.pair[0].find(
'.');
244 os.
write(
"data_", 5);
249 const Item* prev =
nullptr;
253 if (prev && !
options.compact && should_be_separated_(*prev, item)) {
268 for (
const Block& block :
doc.blocks) {
struct Document that represents the CIF file (but can also be read from a different representation,...
std::ostream with buffering.
void operator<<(const std::string &s)
void write(const char *s, size_t len)
BufOstream(std::ostream &os_)
void write_cif_block_to_stream(std::ostream &os_, const Block &block, WriteOptions options=WriteOptions())
bool is_text_field(const std::string &val)
Style
deprecated, use cif::WriteOptions instead
void write_out_loop(BufOstream &os, const Loop &loop, WriteOptions options)
void write_out_pair(BufOstream &os, const std::string &name, const std::string &value, WriteOptions options)
void write_out_item(BufOstream &os, const Item &item, WriteOptions options)
void write_cif_to_stream(std::ostream &os, const Document &doc, WriteOptions options=WriteOptions())
void write_text_field(BufOstream &os, const std::string &value)
std::vector< Item > items
std::vector< std::string > tags
std::vector< std::string > values
WriteOptions(Style style)
bool compact
no blank lines between categories, only between blocks
bool misuse_hash
put '#' (empty comments) before/after categories
std::uint16_t align_pairs
width reserved for tags in pairs (e.g. 34 = value starts at 35th column)
bool prefer_pairs
write single-row loops as pairs
std::uint16_t align_loops
if non-zero, determines max width of each column in a loop and aligns all values to this width; the w...