Program Listing for File LoggerFactory.h

Return to documentation for file (include/flamegpu/io/LoggerFactory.h)

#ifndef INCLUDE_FLAMEGPU_IO_LOGGERFACTORY_H_
#define INCLUDE_FLAMEGPU_IO_LOGGERFACTORY_H_

#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <filesystem>

#include "flamegpu/io/Logger.h"
#include "flamegpu/io/JSONLogger.h"
#include "flamegpu/io/XMLLogger.h"

namespace flamegpu {
namespace io {
class LoggerFactory {
 public:
    static std::unique_ptr<Logger> createLogger(const std::string &output_path, bool prettyPrint, bool truncateFile = true) {
        const std::string extension = std::filesystem::path(output_path).extension().string();

        if (extension == ".xml") {
            return std::make_unique<XMLLogger>(output_path, prettyPrint, truncateFile);
        } else if (extension == ".json") {
            return std::make_unique<JSONLogger>(output_path, prettyPrint, truncateFile);
        }
        THROW exception::UnsupportedFileType("File '%s' is not a type which can be written "
            "by StateWriterFactory::createLogger().",
            output_path.c_str());
    }
};
}  // namespace io
}  // namespace flamegpu

#endif  // INCLUDE_FLAMEGPU_IO_LOGGERFACTORY_H_