#ifndef NNTPCHAN_MODEL_HPP #define NNTPCHAN_MODEL_HPP #include #include #include #include #include #include #include #include namespace nntpchan { namespace model { // MIME Header typedef std::map> PostHeader; // text post contents typedef std::string PostBody; // single file attachment, (orig_filename, hexdigest, thumb_filename) typedef std::tuple PostAttachment; // all attachments on a post typedef std::vector Attachments; // a post (header, Post Text, Attachments) typedef std::tuple Post; // a thread (many posts in post order) typedef std::vector Thread; // a board page is many threads in bump order typedef std::vector BoardPage; static inline const std::string &GetFilename(const PostAttachment &att) { return std::get<0>(att); } static inline const std::string &GetHexDigest(const PostAttachment &att) { return std::get<1>(att); } static inline const std::string &GetThumbnail(const PostAttachment &att) { return std::get<2>(att); } static inline const PostHeader &GetHeader(const Post &post) { return std::get<0>(post); } static inline const PostBody &GetBody(const Post &post) { return std::get<1>(post); } static inline const Attachments &GetAttachments(const Post &post) { return std::get<2>(post); } static inline const std::string &HeaderIFind(const PostHeader &header, const std::string &val, const std::string &fallback) { std::string ival = ToLower(val); auto itr = std::find_if(header.begin(), header.end(), [ival](const auto &item) -> bool { return ToLower(item.first) == ival; }); if (itr == std::end(header)) return fallback; else return itr->second[0]; } using Model = std::variant; } } #endif