|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * License); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "common/path.h" |
| 21 | + |
| 22 | +#ifdef ENABLE_ANTLR4 |
| 23 | +#include "parser/path_nodes_generator.h" |
| 24 | +#endif |
| 25 | + |
| 26 | +namespace storage { |
| 27 | + |
| 28 | +Path::Path() = default; |
| 29 | + |
| 30 | +Path::Path(std::string& device, std::string& measurement) |
| 31 | + : measurement_(measurement), |
| 32 | + device_id_(std::make_shared<StringArrayDeviceID>(device)) { |
| 33 | + full_path_ = device + "." + measurement; |
| 34 | +} |
| 35 | + |
| 36 | +Path::Path(const std::string& path_sc, bool if_split) { |
| 37 | + if (!path_sc.empty()) { |
| 38 | + if (!if_split) { |
| 39 | + full_path_ = path_sc; |
| 40 | + device_id_ = std::make_shared<StringArrayDeviceID>(path_sc); |
| 41 | + } else { |
| 42 | +#ifdef ENABLE_ANTLR4 |
| 43 | + std::vector<std::string> nodes = |
| 44 | + PathNodesGenerator::invokeParser(path_sc); |
| 45 | +#else |
| 46 | + std::vector<std::string> nodes = |
| 47 | + IDeviceID::split_string(path_sc, '.'); |
| 48 | +#endif |
| 49 | + if (nodes.size() > 1) { |
| 50 | + device_id_ = std::make_shared<StringArrayDeviceID>( |
| 51 | + std::vector<std::string>(nodes.begin(), nodes.end() - 1)); |
| 52 | + measurement_ = nodes[nodes.size() - 1]; |
| 53 | + full_path_ = device_id_->get_device_name() + "." + measurement_; |
| 54 | + } else { |
| 55 | + full_path_ = path_sc; |
| 56 | + device_id_ = std::make_shared<StringArrayDeviceID>(); |
| 57 | + measurement_ = path_sc; |
| 58 | + } |
| 59 | + } |
| 60 | + } else { |
| 61 | + full_path_ = ""; |
| 62 | + device_id_ = std::make_shared<StringArrayDeviceID>(); |
| 63 | + measurement_ = ""; |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +} // namespace storage |
0 commit comments