| 64 | void handleInputTag(const std::string& tag, const TagMap& tags, std::vector<Stage *>& inputs); |
| 65 | |
| 66 | void parsePipeline(NL::json& tree, PipelineManager& manager) |
| 67 | { |
| 68 | TagMap tags; |
| 69 | std::vector<Stage*> inputs; |
| 70 | |
| 71 | size_t last = tree.size() - 1; |
| 72 | for (size_t i = 0; i < tree.size(); ++i) |
| 73 | { |
| 74 | NL::json& node = tree.at(i); |
| 75 | |
| 76 | FileSpec spec; |
| 77 | std::string tag; |
| 78 | std::string type; |
| 79 | std::vector<Stage*> specifiedInputs; |
| 80 | Options options; |
| 81 | |
| 82 | // strings are assumed to be filenames |
| 83 | if (node.is_string()) |
| 84 | { |
| 85 | spec.ingest(node.get<std::string>()); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | type = extractType(node); |
| 90 | spec = extractFilename(node); |
| 91 | tag = extractTag(node, tags); |
| 92 | specifiedInputs = extractInputs(node, tags); |
| 93 | if (!specifiedInputs.empty()) |
| 94 | inputs = specifiedInputs; |
| 95 | options = extractOptions(node); |
| 96 | } |
| 97 | |
| 98 | Stage *s = nullptr; |
| 99 | |
| 100 | // The type is inferred from a filename as a reader if it's not |
| 101 | // the last stage or if there's only one. |
| 102 | if ((type.empty() && (i == 0 || i != last)) || |
| 103 | Utils::startsWith(type, "readers.")) |
| 104 | { |
| 105 | StringList files = Utils::glob(spec.u8string()); |
| 106 | if (files.empty()) |
| 107 | files.push_back(spec.u8string()); |
| 108 | |
| 109 | for (const std::string& path : files) |
| 110 | { |
| 111 | spec.setFilePath(path); |
| 112 | ReaderCreationOptions ops { spec, type, nullptr, options, tag }; |
| 113 | s = &manager.makeReader(ops); |
| 114 | |
| 115 | if (specifiedInputs.size()) |
| 116 | throw pdal_error("JSON pipeline: Inputs not permitted for " |
| 117 | " reader: '" + path + "'."); |
| 118 | inputs.push_back(s); |
| 119 | } |
| 120 | } |
| 121 | else if (type.empty() || Utils::startsWith(type, "writers.")) |
| 122 | { |
| 123 | StageCreationOptions ops { spec.u8string(), type, nullptr, options, tag }; |
no test coverage detected