forked from schrodinger/maeparser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.cpp
More file actions
54 lines (44 loc) · 1.27 KB
/
Writer.cpp
File metadata and controls
54 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "Writer.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <fstream>
#include <iostream>
#include "MaeBlock.hpp"
using namespace std;
using boost::algorithm::ends_with;
namespace schrodinger
{
namespace mae
{
Writer::Writer(std::shared_ptr<ostream> stream)
{
m_out = stream;
write_opening_block();
}
Writer::Writer(std::string fname)
{
auto pregzip_stream = new ofstream();
pregzip_stream->open(fname, std::ios_base::out | std::ios_base::binary);
if (ends_with(fname, ".maegz") || ends_with(fname, ".mae.gz")) {
m_gzip_stream =
std::make_shared<boost::iostreams::filtering_ostreambuf>();
m_gzip_compressor = make_shared<boost::iostreams::gzip_compressor>();
m_gzip_stream->push(*m_gzip_compressor);
m_gzip_stream->push(*pregzip_stream);
m_out = std::make_shared<std::ostream>(m_gzip_stream.get());
} else {
m_out.reset(dynamic_cast<ostream*>(pregzip_stream));
}
write_opening_block();
}
void Writer::write(const std::shared_ptr<Block>& block)
{
block->write(*m_out);
}
void Writer::write_opening_block()
{
shared_ptr<Block> b = make_shared<Block>("");
b->setStringProperty("s_m_m2io_version", "2.0.0");
write(b);
}
} // namespace mae
} // namespace schrodinger