void PipelineManager::setOptions(Stage& stage, const Options& addOps) { // First apply common options. stage.setOptions(m_commonOptions); // Apply additional reader/writer options, making sure they replace any // common options. stage.removeOptions(addOps); stage.addOptions(addOps); // Apply options provided on the command line, overriding others. Options& ops = stageOptions(stage); stage.removeOptions(ops); stage.addOptions(ops); }
void PipelineReaderJSON::parsePipeline(Json::Value& tree) { std::map<std::string, Stage*> tags; std::vector<Stage*> inputs; Json::ArrayIndex last = tree.size() - 1; for (Json::ArrayIndex i = 0; i < tree.size(); ++i) { Json::Value& node = tree[i]; std::string filename; std::string tag; std::string type; std::vector<Stage*> specifiedInputs; Options options; // strings are assumed to be filenames if (node.isString()) { filename = node.asString(); } else { type = extractType(node); filename = extractFilename(node); tag = extractTag(node, tags); specifiedInputs = extractInputs(node, tags); if (!specifiedInputs.empty()) inputs = specifiedInputs; options = extractOptions(node); } Stage *s = nullptr; // The type is inferred from a filename as a reader if it's not // the last stage or if there's only one. if ((type.empty() && (i == 0 || i != last)) || Utils::startsWith(type, "readers.")) { s = &m_manager.makeReader(filename, type); if (specifiedInputs.size()) throw pdal_error("JSON pipeline: Inputs not permitted for " " reader: '" + filename + "'."); inputs.push_back(s); } else if (type.empty() || Utils::startsWith(type, "writers.")) { s = &m_manager.makeWriter(filename, type); for (Stage *ts : inputs) s->setInput(*ts); inputs.clear(); } else { s = &m_manager.makeFilter(type); for (Stage *ts : inputs) s->setInput(*ts); inputs.clear(); inputs.push_back(s); if (filename.size()) options.add("filename", filename); } // s should be valid at this point. makeXXX will throw if the stage // couldn't be constructed. s->addOptions(options); if (tag.size()) tags[tag] = s; } }