#ifndef FLEXBUF_OUTPUTVALUE_HPP_ #define FLEXBUF_OUTPUTVALUE_HPP_ #include #include #include #include #include "rfl/Ref.hpp" #include "rfl/always_false.hpp" #include "rfl/flexbuf/OutputVar.hpp" namespace rfl { namespace flexbuf { template class OutputValue : public OutputVar { public: OutputValue(T _val) : val_(_val) {} ~OutputValue() = default; /// Inserts all elements into the builder. void insert(const std::optional& _key, flexbuffers::Builder* _fbb) final { if constexpr (std::is_same, std::string>()) { if (_key) { _fbb->String(_key->c_str(), val_); } else { _fbb->String(val_); } } else if constexpr (std::is_same, bool>()) { if (_key) { _fbb->Bool(_key->c_str(), val_); } else { _fbb->Bool(val_); } } else if constexpr (std::is_floating_point>()) { if (_key) { _fbb->Double(_key->c_str(), val_); } else { _fbb->Double(val_); } } else if constexpr (std::is_integral>()) { if (_key) { _fbb->Int(_key->c_str(), val_); } else { _fbb->Int(val_); } } else { static_assert(always_false_v, "Unsupported type"); } }; /// Whether this is null. bool is_null() const final { return false; } private: /// The underlying value. T val_; }; } // namespace flexbuf } // namespace rfl #endif