Initial commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#ifndef BASE_GENERATOR_H
|
||||
#define BASE_GENERATOR_H
|
||||
|
||||
#include "generator_interface.h"
|
||||
#include "range_limiter.h"
|
||||
#include <QDateTime>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
class BaseGenerator : public GeneratorInterface, public virtual RangeLimiter {
|
||||
private:
|
||||
QString entityName_;
|
||||
int lastPercentage_;
|
||||
mutable int fieldWidth_;
|
||||
qsizetype createdRecords_;
|
||||
qsizetype maximumRecords_;
|
||||
|
||||
public:
|
||||
ShouldLogSuccess defaultShouldLog(int percent, int seconds) const noexcept;
|
||||
ShouldLogSuccess shouldLogAllSuccesses() const noexcept;
|
||||
ShouldLogSuccess shouldLogEveryNPercent(int percent) const noexcept;
|
||||
ShouldLogSuccess shouldLogEveryNSeconds(
|
||||
int seconds, const ShouldLogSuccess &performOtherwise) const noexcept;
|
||||
ShouldLogSuccess shouldLogFirstAndLastPercent() const noexcept;
|
||||
|
||||
public:
|
||||
// Virtual methods
|
||||
void generateAll(const ShouldLogSuccess &shouldLogSuccess) final;
|
||||
|
||||
void generateByFillRatio(double fillRatio,
|
||||
const ShouldLogSuccess &shouldLogSuccess) final;
|
||||
|
||||
void generateByRecordCount(qint64 totalRecordsToCreate,
|
||||
const ShouldLogSuccess &shouldLogSuccess) final;
|
||||
|
||||
protected:
|
||||
inline BaseGenerator(const QString &entityName) noexcept;
|
||||
|
||||
// General methods
|
||||
inline QString formatDateTime(const QDateTime &dateTime_) const noexcept;
|
||||
inline qsizetype createdRecords() const noexcept;
|
||||
|
||||
private: // create* methods depends on clearStaleData and createRecord
|
||||
QString createFailureMessage(const QString &errorMessage) const override;
|
||||
QString createSuccessMessage() const override;
|
||||
QString createTemplateMessage() const override;
|
||||
|
||||
// Non-virtual method
|
||||
void generateImplementation(std::function<bool()> shouldContinue,
|
||||
std::function<bool()> shouldLogSuccess);
|
||||
|
||||
void updatePercentage(); // Depends on createRecord
|
||||
|
||||
protected: // Non-const methods
|
||||
virtual RepositoryResult createRecord() = 0;
|
||||
virtual bool prepareData() = 0;
|
||||
virtual void clearStaleData() = 0;
|
||||
};
|
||||
|
||||
BaseGenerator::BaseGenerator(const QString &entityName) noexcept
|
||||
: createdRecords_(0), entityName_(entityName), fieldWidth_(0),
|
||||
lastPercentage_(-1) {}
|
||||
|
||||
inline qsizetype BaseGenerator::createdRecords() const noexcept {
|
||||
return createdRecords_;
|
||||
}
|
||||
|
||||
QString
|
||||
BaseGenerator::formatDateTime(const QDateTime &dateTime_) const noexcept {
|
||||
return dateTime_.toString("yyyy-MM-dd'T'HH:mm:ss.000");
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user