.. _program_listing_file_include_flamegpu_io_StateWriterFactory.h: Program Listing for File StateWriterFactory.h ============================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/flamegpu/io/StateWriterFactory.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef INCLUDE_FLAMEGPU_IO_STATEWRITERFACTORY_H_ #define INCLUDE_FLAMEGPU_IO_STATEWRITERFACTORY_H_ #include #include #include #include "flamegpu/io/StateWriter.h" #include "flamegpu/io/XMLStateWriter.h" #include "flamegpu/io/JSONStateWriter.h" namespace flamegpu { namespace io { class StateWriterFactory { public: static StateWriter* createWriter( const std::string& output_file) { const std::string extension = std::filesystem::path(output_file).extension().string(); if (extension == ".xml") { return new XMLStateWriter(); } else if (extension == ".json") { return new JSONStateWriter(); } THROW exception::UnsupportedFileType("File '%s' is not a type which can be written " "by StateWriterFactory::createWriter().", output_file.c_str()); } static std::string detectSupportedFileExt(const std::string &user_file_ext) { std::string rtn = user_file_ext; // Move entire string to lower case std::transform(rtn.begin(), rtn.end(), rtn.begin(), [](unsigned char c) { return std::use_facet< std::ctype>(std::locale()).tolower(c); }); // Strip first character if it is '.' if (rtn[0] == '.') rtn = rtn.substr(1); // Compare against supported formats if (rtn == "xml" || rtn == "json") { return rtn; } return ""; } }; } // namespace io } // namespace flamegpu #endif // INCLUDE_FLAMEGPU_IO_STATEWRITERFACTORY_H_