ODF_TEST/include/app.hpp

127 lines
3.2 KiB
C++
Raw Permalink Normal View History

2026-05-19 08:32:36 +00:00
#ifndef ODF_APP_HPP
#define ODF_APP_HPP
#include <string>
#include <vector>
#include <memory>
#include <ostream>
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<TextRun>& runs() const noexcept { return runs_; }
/**
* @brief
* @param os
*/
void write(std::ostream& os) const;
private:
std::vector<TextRun> runs_;
};
// ====================================================================
// Document — 文档模型
// ====================================================================
/**
* @brief
*/
class Document {
public:
/// @brief 默认构造空文档。
Document() = default;
/**
* @brief
* @param para Paragraph
*/
void add_paragraph(Paragraph para);
/// @brief 返回文档中的所有段落(只读)。
const std::vector<Paragraph>& paragraphs() const noexcept { return paragraphs_; }
/**
* @brief
* @param os
*/
void write(std::ostream& os) const;
/**
* @brief
* @return
*/
std::string to_string() const;
private:
std::vector<Paragraph> paragraphs_;
};
} // namespace odf
#endif // ODF_APP_HPP