file.hpp (1399B)
1 #ifndef UUID_CACA9E02_5122_4C09_9463_73AD33BA5802 2 #define UUID_CACA9E02_5122_4C09_9463_73AD33BA5802 3 #pragma once 4 5 #include "../context.hpp" 6 #include "../../source.hpp" 7 #include "../../txt_serializable.hpp" 8 9 namespace Neptools::Stsc 10 { 11 12 enum class LIBSHIT_LUAGEN() Flavor 13 { 14 #define NEPTOOLS_GEN_STSC_FLAVOR(x, ...) \ 15 x(NOIRE, __VA_ARGS__) \ 16 x(POTBB, __VA_ARGS__) 17 #define NEPTOOLS_GEN_ENUM(x,y) x, 18 NEPTOOLS_GEN_STSC_FLAVOR(NEPTOOLS_GEN_ENUM,) 19 #undef NEPTOOLS_GEN_ENUM 20 }; 21 22 // not constexpr because it only 5 years to implement c++14 in gcc and broken 23 // in <gcc-9: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67026 24 inline const char* ToString(Flavor f) noexcept 25 { 26 switch (f) 27 { 28 #define NEPTOOLS_GEN_CASE(x,y) case Flavor::x: return #x; 29 NEPTOOLS_GEN_STSC_FLAVOR(NEPTOOLS_GEN_CASE,) 30 #undef NEPTOOLS_GEN_CASWE 31 }; 32 LIBSHIT_UNREACHABLE("Invalid Flavor value"); 33 } 34 35 class File final : public Context, public TxtSerializable 36 { 37 LIBSHIT_DYNAMIC_OBJECT; 38 public: 39 File(Flavor flavor) : flavor{flavor} {} 40 File(Source src, Flavor flavor); 41 42 Flavor flavor; 43 44 protected: 45 void Inspect_(std::ostream& os, unsigned indent) const override; 46 47 private: 48 void Parse_(Source& src); 49 50 void WriteTxt_(std::ostream& os) const override; 51 void ReadTxt_(std::istream& is) override; 52 }; 53 54 } 55 56 LIBSHIT_ENUM(Neptools::Stsc::Flavor); 57 58 #endif