First documented attempts to use prompt generator to generate its own code. The generated code commit is here: COMMIT
PPROMPT:
[PROMPT ASSEMBLY]
+
So now we will create a class into which we will put Cmds_code_analyzer::dirs_
but as a class, so the item that will contain a QString will be named AnalyzerModule
the class with the collection will then be AnalyzerModuleCol
leave dirs_ for now, I will swap it later
REPAIR PROMPT:
Please use the same style as in the other code_analyzer classes.
REPAIR PROMPT:
In AnalyzerModuleCol, provide a get by index; do not use iterators.
ANSWER:
class AnalyzerModule
//=============================================================================
{
public:
/// @section Construction
explicit AnalyzerModule(const QString& dirPath)
: dirPath_(dirPath) {}
/// @section Accessors
const QString& dirPath() const { return dirPath_; }
QString moduleName() const { return QFileInfo(dirPath_).dirName(); }
bool exists() const { return QDir(dirPath_).exists(); }
//=============================================================================
protected:
/// @section Data
QString dirPath_;
};
class AnalyzerModuleCol
//=============================================================================
{
public:
/// @section Construction
AnalyzerModuleCol() = default;
/// @section Methods
void add(const QString& dir)
{
modules_.append(AnalyzerModule(dir));
}
int count() const
{
return modules_.count();
}
bool isEmpty() const
{
return modules_.isEmpty();
}
const AnalyzerModule& get(int index) const
{
return modules_.at(index);
}
//=============================================================================
protected:
/// @section Data
QList<AnalyzerModule> modules_;
};
PROMPT:
class AnalyzerModule
//=============================================================================
{
public:
/// @section Construction
explicit AnalyzerModule(const QString& dirPath)
: dirPath_(dirPath)
{
}
/// @section Accessors
const QString& dirPath() const { return dirPath_; }
//=============================================================================
protected:
/// @section Data
QString dirPath_;
};
class AnalyzerModuleCol
//=============================================================================
{
public:
/// @section Construction
AnalyzerModuleCol() = default;
/// @section Methods
void add(const QString& dir)
{
modules_.append(AnalyzerModule(dir));
}
int count() const
{
return modules_.count();
}
const AnalyzerModule& get(int index) const
{
return modules_.at(index);
}
//=============================================================================
protected:
/// @section Data
QList<AnalyzerModule> modules_;
};
perfecto
Now add a method that returns a QStringList, so that we can perform a cheap substitution where, for example, …
ANSWER:
QStringList toStringList() const
{
QStringList result;
for (int i = 0; i < modules_.count(); ++i) {
result.append(modules_.at(i).dirPath());
}
return result;
}