WsParser_VS/libWords/libwords.h

124 lines
2.7 KiB
C
Raw Permalink Normal View History

2025-02-02 12:54:32 +00:00
#pragma once
#include "libwords_global.h"
#include <memory>
#include <QtCore/QString>
2025-02-08 05:40:36 +00:00
#include <QtCore/QTextStream>
2025-02-02 12:54:32 +00:00
namespace lib_words {
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
*/
class IWordBase {
public:
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
* @return
*/
virtual QString file() const = 0;
/**
2025-02-11 14:32:10 +00:00
* @brief
* @return
2025-02-02 12:54:32 +00:00
*/
virtual uint64_t position() const = 0;
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
* @return
*/
virtual QString content() const = 0;
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
* @return
*/
virtual int row() const = 0;
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
* @return
*/
virtual int column() const = 0;
2025-02-04 14:26:34 +00:00
};
class IPrimitiveWord : public IWordBase {
public:
2025-02-02 12:54:32 +00:00
/**
2025-02-11 14:32:10 +00:00
* @brief .
2025-02-02 12:54:32 +00:00
*
* \return
*/
2025-02-07 07:06:27 +00:00
virtual std::shared_ptr<const IPrimitiveWord> nextWord() const = 0;
2025-02-02 12:54:32 +00:00
};
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
*/
2025-02-04 14:26:34 +00:00
class LIBWORDS_EXPORT WordContent : public IPrimitiveWord {
2025-02-02 12:54:32 +00:00
private:
int row_n, col_n;
uint64_t doc_offset;
QString text_n, path_p;
public:
2025-02-12 13:50:45 +00:00
WordContent(int r, int c, const QString& t, const QString& p);
2025-02-02 12:54:32 +00:00
// WordBase interface
public:
virtual QString file() const override;
virtual uint64_t position() const override;
virtual QString content() const override;
virtual int row() const override;
virtual int column() const override;
2025-02-07 07:06:27 +00:00
virtual std::shared_ptr<const IPrimitiveWord> nextWord() const override;
2025-02-02 12:54:32 +00:00
};
2025-02-04 14:26:34 +00:00
class LIBWORDS_EXPORT WordImpl : public IPrimitiveWord {
2025-02-02 12:54:32 +00:00
private:
std::shared_ptr<const IWordBase> content_ptr;
2025-02-07 07:06:27 +00:00
std::shared_ptr<const IPrimitiveWord> next_ptr;
2025-02-02 12:54:32 +00:00
public:
2025-02-07 07:06:27 +00:00
WordImpl(std::shared_ptr<const IWordBase> content, std::shared_ptr<const IPrimitiveWord> next);
2025-02-02 12:54:32 +00:00
2025-02-11 14:32:10 +00:00
// 通过 IWordBase 继承
2025-02-02 12:54:32 +00:00
QString file() const override;
virtual uint64_t position() const override;
QString content() const override;
int row() const override;
int column() const override;
2025-02-07 07:06:27 +00:00
std::shared_ptr<const IPrimitiveWord> nextWord() const override;
2025-02-02 12:54:32 +00:00
};
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
*/
class LIBWORDS_EXPORT WordReader {
private:
QList<std::shared_ptr<const IWordBase>> parse_line(uint64_t start_pos, int row, const QString& line_text, const QString& path) const;
2025-02-08 05:40:36 +00:00
QList<std::shared_ptr<const IWordBase>> extract_primary(QTextStream& in, const QString &f_path) const;
2025-02-02 12:54:32 +00:00
public:
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
*/
2025-02-08 05:40:36 +00:00
std::shared_ptr<const IPrimitiveWord> wordsFrom(QTextStream& tin, const QString& path) const;
2025-02-02 12:54:32 +00:00
};
/**
2025-02-11 14:32:10 +00:00
* @brief
2025-02-02 12:54:32 +00:00
*/
class LIBWORDS_EXPORT WordsException {
private:
QString msg_store;
public:
WordsException(const QString& message);
virtual QString message() const;
};
2025-02-24 07:02:23 +00:00
LIBWORDS_EXPORT uint qHash(const std::shared_ptr<const IPrimitiveWord>& t, uint seed = 0) Q_DECL_NOTHROW;
2025-02-02 12:54:32 +00:00
}