mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 16:43:00 +00:00
More work on isolating into plug-ins
This commit is contained in:
@@ -7,49 +7,44 @@
|
||||
#include "../ifcgeom/Serializer.h"
|
||||
#include "../ifcparse/file.h"
|
||||
#include "../plugin/plugin.h"
|
||||
#include "../serializers/document_serializer_plugin.h"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
class SERIALIZERS_API XmlSerializer : public Serializer {
|
||||
class XmlSerializer : public Serializer {
|
||||
private:
|
||||
XmlSerializer* implementation_ = nullptr;
|
||||
boost::shared_ptr<Serializer> implementation_;
|
||||
|
||||
protected:
|
||||
std::string xml_filename;
|
||||
|
||||
public:
|
||||
XmlSerializer(ifcopenshell::file* file, const std::string& xml_filename);
|
||||
XmlSerializer(ifcopenshell::file* file, const std::string& xml_filename)
|
||||
: xml_filename(xml_filename)
|
||||
{
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
ifcopenshell::serializers::document_serializer_context context;
|
||||
context.file = file;
|
||||
context.output_filename = xml_filename;
|
||||
context.schema_name = file->schema()->name();
|
||||
implementation_ = ifcopenshell::serializers::document_serializer_registry_instance().create("xml", context);
|
||||
}
|
||||
|
||||
virtual ~XmlSerializer() {}
|
||||
|
||||
bool ready() { return true; }
|
||||
void writeHeader() {}
|
||||
|
||||
void finalize() { implementation_->finalize(); }
|
||||
void finalize() {
|
||||
if (!implementation_) {
|
||||
throw ifcopenshell::exception("No XML serializer implementation constructed");
|
||||
}
|
||||
implementation_->finalize();
|
||||
}
|
||||
void setFile(ifcopenshell::file*) { throw ifcopenshell::exception("Should be supplied on construction"); }
|
||||
};
|
||||
|
||||
struct SERIALIZERS_API XmlSerializerFactory {
|
||||
typedef boost::function2<XmlSerializer*, ifcopenshell::file*, std::string> fn;
|
||||
|
||||
class SERIALIZERS_API Factory {
|
||||
public:
|
||||
Factory();
|
||||
void bind(const std::string& schema_name, fn, const ifcopenshell::plugin::module& module = ifcopenshell::plugin::module());
|
||||
XmlSerializer* construct(const std::string& schema_name, ifcopenshell::file*, std::string);
|
||||
|
||||
private:
|
||||
struct entry {
|
||||
fn fn_;
|
||||
ifcopenshell::plugin::module module_;
|
||||
};
|
||||
|
||||
std::map<std::string, entry> entries_;
|
||||
};
|
||||
|
||||
static Factory& implementations();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user