Files
IfcOpenShell/src/serializers/JsonSerializer.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
C++
Raw Normal View History

2025-11-17 14:06:39 +01:00
#ifndef JSONSERIALIZER_H
#define JSONSERIALIZER_H
#ifdef WITH_GLTF
#include "../ifcgeom/Serializer.h"
2026-03-31 15:32:36 +02:00
#include "../ifcparse/file.h"
2026-04-17 11:24:09 +02:00
#include "../plugin/plugin.h"
2025-11-17 14:06:39 +01:00
#include "../serializers/serializers_api.h"
2026-04-18 15:46:21 +02:00
#include "../serializers/document_serializer_plugin.h"
2025-11-17 14:06:39 +01:00
2026-04-18 15:46:21 +02:00
#include <boost/shared_ptr.hpp>
2025-11-17 14:06:39 +01:00
2026-04-18 15:46:21 +02:00
class JsonSerializer : public Serializer {
2025-11-17 14:06:39 +01:00
public:
enum Dialect {
JSON_DIALECT_CREOOX
};
private:
2026-04-18 15:46:21 +02:00
boost::shared_ptr<Serializer> implementation_;
2025-11-17 14:06:39 +01:00
protected:
std::string json_filename;
Dialect dialect_;
public:
JsonSerializer(ifcopenshell::file* file, const std::string& json_filename, Dialect dialect = Dialect::JSON_DIALECT_CREOOX, Logger& logger = Logger::Root())
2026-04-18 15:46:21 +02:00
: json_filename(json_filename)
, dialect_(dialect)
{
if (!file) {
return;
}
ifcopenshell::serializers::document_serializer_context context;
context.file = file;
context.output_filename = json_filename;
context.schema_name = file->schema()->name();
context.dialect = static_cast<int>(dialect);
implementation_ = ifcopenshell::serializers::document_serializer_registry_instance().create("json", context);
}
2025-11-17 14:06:39 +01:00
virtual ~JsonSerializer() {}
bool ready() { return true; }
void writeHeader() {}
2026-04-18 15:46:21 +02:00
void finalize() {
if (!implementation_) {
throw ifcopenshell::exception("No JSON serializer implementation constructed");
}
implementation_->finalize();
}
2026-03-31 15:32:36 +02:00
void setFile(ifcopenshell::file*) { throw ifcopenshell::exception("Should be supplied on construction"); }
2025-11-17 14:06:39 +01:00
};
#endif
#endif