Exemplo n.º 1
0
void addMetadata(PyObject *dict, MetadataNode m)
{

    if (! dict)
    {
        return;
    }

    if (!PyDict_Check(dict) )
        throw pdal::pdal_error("'metadata' member must be a dictionary!");

    std::string name = readPythonString(dict, "name");
    std::string value = readPythonString(dict, "value");

    std::string type = readPythonString(dict, "type");
    if (type.empty())
        type = Metadata::inferType(value);

    std::string description = readPythonString(dict, "description");

    PyObject *submeta = PyDict_GetItemString(dict, "children");
    if (submeta)
    {
        if (!PyList_Check(submeta))
            throw pdal::pdal_error("'children' metadata member must be a list!");

        for (Py_ssize_t i = 0; i < PyList_Size(submeta); ++i)
        {
            PyObject* p = PyList_GetItem(submeta, i);
            addMetadata(p, m);
        }
        MetadataNode child =  m.addWithType(name, value, type, description);
    }
}
Exemplo n.º 2
0
void addMetadata(PyObject *list, MetadataNode m)
{

    if (!PyList_Check(list))
        return;

    for (Py_ssize_t i = 0; i < PyList_Size(list); ++i)
    {
        PyObject *tuple = PyList_GetItem(list, i);
        if (!PyTuple_Check(tuple) || PyTuple_Size(tuple) != 5)
            continue;

        std::string name = readPythonString(tuple, 0);
        std::string value = readPythonString(tuple, 1);

        std::string type = readPythonString(tuple, 2);
        if (type.empty())
            type = Metadata::inferType(value);

        std::string description = readPythonString(tuple, 3);

        PyObject *submeta = PyTuple_GetItem(tuple, 4);
        MetadataNode child =  m.addWithType(name, value, type, description);
        if (submeta)
            addMetadata(submeta, child);
    }
}