Exemple #1
0
void Pothos::Util::BlockDescriptionParser::feedStream(std::istream &is)
{
    for (const auto &contiguousBlock : extractContiguousBlocks(is))
    {
        const auto obj = parseCommentBlockForMarkup(contiguousBlock);
        if (not obj) continue;

        //store into the array of all description objects
        _impl->array->add(obj);

        //get a list of all paths including aliases
        std::vector<std::string> paths;
        paths.push_back(obj->getValue<std::string>("path"));
        if (obj->has("aliases")) for (const auto &alias : *obj->getArray("aliases"))
        {
            paths.push_back(alias.toString());
        }

        //store mapping for each factory path
        for (const auto &path : paths)
        {
            _impl->factories.push_back(path);
            _impl->objects[path] = obj;
        }
    }
}
Exemple #2
0
void PothosUtilBase::docParse(const std::vector<std::string> &inputFilePaths)
{
    Poco::JSON::Array arrayOut;
    for (const auto &inputFilePath : inputFilePaths)
    {

        std::ifstream inputFile(inputFilePath.c_str());
        const auto contiguousBlocks = extractContiguousBlocks(inputFile);
        inputFile.close();

        for (const auto &contiguousBlock : contiguousBlocks)
        {
            try
            {
                Poco::SharedPtr<Poco::JSON::Object> jsonOut(new Poco::JSON::Object());
                *jsonOut = parseCommentBlockForMarkup(contiguousBlock);
                if (jsonOut->has("path")) arrayOut.add(jsonOut);
            }
            catch (const Pothos::Exception &ex)
            {
                throw Pothos::SyntaxException(inputFilePath, ex);
            }
        }
    }

    //write to output (file if specified, otherwise stdout)
    const auto outputFilePath = this->config().getString("outputFile", "");
    const size_t indentSpaces = 4;
    if (outputFilePath.empty())
    {
        std::cout << std::endl;
        Poco::JSON::Stringifier::stringify(arrayOut, std::cout, indentSpaces);
        std::cout << std::endl;
    }
    else
    {
        const auto outputFileName = Poco::Path(outputFilePath).getBaseName();
        const auto outputFileExt = Poco::Path(outputFilePath).getExtension();

        std::ofstream outputFile(outputFilePath.c_str());
        if (outputFileExt == "json") arrayOut.stringify(outputFile, indentSpaces);
        else if (outputFileExt == "cpp") jsonArrayToCppStaticBlock(arrayOut, outputFile, outputFileName);
        else throw Pothos::Exception("PothosUtilBase::docParse()", "unsupported file extension: " + outputFilePath);
        outputFile << std::endl;
        outputFile.close();
    }
}