approach to pass stringstream to serializers

This commit is contained in:
Thomas Krijnen
2021-07-11 15:01:31 +02:00
parent eeaf04c6ea
commit 975379a3a4
5 changed files with 90 additions and 54 deletions
+37 -1
View File
@@ -27,7 +27,7 @@
class SerializerSettings : public IfcGeom::IteratorSettings
{
public:
enum Setting
enum Setting : uint64_t
{
/// Use entity names instead of unique IDs for naming elements.
/// Applicable for OBJ, DAE, and SVG output.
@@ -64,6 +64,42 @@ public:
enum { DEFAULT_PRECISION = 15 };
};
class stream_or_filename {
private:
std::shared_ptr<std::ofstream> ofs_;
std::shared_ptr<std::ostringstream> oss_;
boost::optional<std::string> filename_;
public:
std::ostream& stream;
stream_or_filename(const std::string& fn)
: ofs_(new std::ofstream(IfcUtil::path::from_utf8(fn).c_str()))
, stream(*ofs_)
{}
stream_or_filename()
: oss_(new std::ostringstream)
, stream(*oss_)
{}
std::string get_value() const {
return oss_->str();
}
boost::optional<std::string> filename() const {
return filename_;
}
bool is_ready() {
if (ofs_) {
return ofs_->is_open();
} else {
return true;
}
}
};
class GeometrySerializer : public Serializer {
public:
GeometrySerializer(const SerializerSettings& settings) : settings_(settings) {}