#ifndef ODF_APP_HPP #define ODF_APP_HPP #include #include #include #include namespace odf { // ==================================================================== // 前置声明 // ==================================================================== class TextRun; class Paragraph; class Document; // ==================================================================== // TextRun — 文本片段 // ==================================================================== /** * @brief 表示文档中的一个文本片段,可携带格式属性。 */ class TextRun { public: /** * @brief 构造一个 TextRun 对象。 * @param text 文本内容 * @param bold 是否加粗(默认 false) * @param italic 是否斜体(默认 false) */ explicit TextRun(std::string text, bool bold = false, bool italic = false); /// @brief 返回文本内容(只读)。 const std::string& text() const noexcept { return text_; } /// @brief 是否加粗。 bool is_bold() const noexcept { return bold_; } /// @brief 是否斜体。 bool is_italic() const noexcept { return italic_; } /** * @brief 将本 TextRun 输出到输出流(纯文本格式)。 * @param os 输出流 */ void write(std::ostream& os) const; private: std::string text_; bool bold_; bool italic_; }; // ==================================================================== // Paragraph — 段落 // ==================================================================== /** * @brief 表示文档中的一个段落,由若干 TextRun 组成。 */ class Paragraph { public: /// @brief 默认构造空段落。 Paragraph() = default; /** * @brief 向段落末尾追加一个文本片段。 * @param run 待追加的 TextRun(支持移动语义) */ void add_run(TextRun run); /// @brief 返回段落中所有文本片段(只读)。 const std::vector& runs() const noexcept { return runs_; } /** * @brief 将本段落输出到输出流。 * @param os 输出流 */ void write(std::ostream& os) const; private: std::vector runs_; }; // ==================================================================== // Document — 文档模型 // ==================================================================== /** * @brief 文档模型,包含一组段落。 */ class Document { public: /// @brief 默认构造空文档。 Document() = default; /** * @brief 向文档末尾追加一个段落。 * @param para 待追加的 Paragraph(支持移动语义) */ void add_paragraph(Paragraph para); /// @brief 返回文档中的所有段落(只读)。 const std::vector& paragraphs() const noexcept { return paragraphs_; } /** * @brief 将整个文档输出为纯文本到输出流。 * @param os 输出流 */ void write(std::ostream& os) const; /** * @brief 返回文档的纯文本字符串表示。 * @return 纯文本字符串 */ std::string to_string() const; private: std::vector paragraphs_; }; } // namespace odf #endif // ODF_APP_HPP