StatusCode generate(SchemaFormat format, const QString &specFileName) { QFile specsFile(specFileName); specsFile.open(QIODevice::ReadOnly); const QByteArray data = specsFile.readAll(); if (data.isEmpty()) { printf("Unable to read the file.\n"); return InvalidArgument; } specsFile.close(); GeneratorNG generator; bool success = true; switch (format) { case JsonFormat: success = generator.loadDataFromJson(data); break; case TextFormat: success = generator.loadDataFromText(data); break; } if (!success) { printf("Unable to parse the scheme.\n"); return SchemaReadError; } generator.generate(); replacingHelper(QLatin1String("../TLValues.hpp"), 8, QLatin1String("TLValues"), generator.codeOfTLValues); replacingHelper(QLatin1String("../TLTypes.hpp"), 0, QLatin1String("TLTypes"), generator.codeOfTLTypes); replacingHelper(QLatin1String("../CTelegramStream.hpp"), 4, QLatin1String("read operators"), generator.codeStreamReadDeclarations); replacingHelper(QLatin1String("../CTelegramStream.cpp"), 0, QLatin1String("read operators implementation"), generator.codeStreamReadDefinitions); replacingHelper(QLatin1String("../CTelegramStream.cpp"), 0, QLatin1String("vector read templates instancing"), generator.codeStreamReadTemplateInstancing); replacingHelper(QLatin1String("../CTelegramStream.hpp"), 4, QLatin1String("write operators"), generator.codeStreamWriteDeclarations); replacingHelper(QLatin1String("../CTelegramStream.cpp"), 0, QLatin1String("write operators implementation"), generator.codeStreamWriteDefinitions); replacingHelper(QLatin1String("../CTelegramStream.cpp"), 0, QLatin1String("vector write templates instancing"), generator.codeStreamWriteTemplateInstancing); replacingHelper(QLatin1String("../CTelegramConnection.hpp"), 4, QLatin1String("Telegram API methods declaration"), generator.codeConnectionDeclarations); replacingHelper(QLatin1String("../CTelegramConnection.cpp"), 0, QLatin1String("Telegram API methods implementation"), generator.codeConnectionDefinitions); replacingHelper(QLatin1String("../TLTypesDebug.hpp"), 0, QLatin1String("TLTypes debug operators"), generator.codeDebugWriteDeclarations); replacingHelper(QLatin1String("../TLTypesDebug.cpp"), 0, QLatin1String("TLTypes debug operators"), generator.codeDebugWriteDefinitions); printf("Spec file successfully used for generation.\n"); return NoError; }
void Package::fromDirectory(const std::string &dir) { LOG(INFO) << "Reading package from directory \"" << dir << "\"."; setConfigVar(Directory, dir); activateFlag(HasDirectory); QFile specsFile(QString::fromStdString(dir + "/PackageSpecs.yml")); specsFile.open(QFile::ReadOnly); if(specsFile.isReadable()) { loadSpecs(specsFile.readAll().toStdString()); } else { LOG(WARNING) << "The package in the directory \"" << dir << "\" has no \"PackageSpecs.yml\" file!"; m_isValid = false; } }
StatusCode format(const QString &specFileName) { QFile specsFile(specFileName); if (!specsFile.open(QIODevice::ReadOnly)) { return FileAccessError; } QByteArray data = specsFile.readAll(); specsFile.close(); if (!specsFile.open(QIODevice::WriteOnly)) { return FileAccessError; } QJsonDocument document = QJsonDocument::fromJson(data); specsFile.write(document.toJson()); specsFile.close(); printf("Spec file successfully formatted.\n"); return NoError; }