adamdebreceni commented on code in PR #1391: URL: https://github.com/apache/nifi-minifi-cpp/pull/1391#discussion_r979881994
########## libminifi/include/core/flow/Node.h: ########## @@ -0,0 +1,143 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <string_view> +#include <tuple> +#include <optional> +#include "nonstd/expected.hpp" + +namespace org::apache::nifi::minifi::core::flow { + +class Node { + public: + struct Cursor { + int line; + int column; + int pos; + }; + + class Impl; + class Iterator { + public: + class Value; + + class Impl { + public: + virtual Impl& operator++() = 0; + virtual bool operator==(const Impl& other) const = 0; + virtual Value operator*() const = 0; + bool operator!=(const Impl& other) const {return !(*this == other);} + + virtual std::unique_ptr<Impl> clone() const = 0; + virtual ~Impl() = default; + }; + + Iterator& operator++() { + impl_->operator++(); + return *this; + } + + explicit Iterator(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {} + Iterator(const Iterator& other): impl_(other.impl_->clone()) {} + Iterator(Iterator&&) = default; + Iterator& operator=(const Iterator& other) { + if (this == &other) { + return *this; + } + impl_ = other.impl_->clone(); + return *this; + } + Iterator& operator=(Iterator&&) = default; + + bool operator==(const Iterator& other) const {return impl_->operator==(*other.impl_);} + bool operator!=(const Iterator& other) const {return !(*this == other);} + + Value operator*() const; + + private: + std::unique_ptr<Impl> impl_; + }; + + class Impl { Review Comment: makes sense, renamed them ########## libminifi/include/core/flow/Node.h: ########## @@ -0,0 +1,143 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <string_view> +#include <tuple> +#include <optional> +#include "nonstd/expected.hpp" + +namespace org::apache::nifi::minifi::core::flow { + +class Node { + public: + struct Cursor { + int line; + int column; + int pos; + }; + + class Impl; + class Iterator { + public: + class Value; + + class Impl { + public: + virtual Impl& operator++() = 0; + virtual bool operator==(const Impl& other) const = 0; + virtual Value operator*() const = 0; + bool operator!=(const Impl& other) const {return !(*this == other);} + + virtual std::unique_ptr<Impl> clone() const = 0; + virtual ~Impl() = default; + }; + + Iterator& operator++() { + impl_->operator++(); + return *this; + } + + explicit Iterator(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {} + Iterator(const Iterator& other): impl_(other.impl_->clone()) {} + Iterator(Iterator&&) = default; + Iterator& operator=(const Iterator& other) { + if (this == &other) { + return *this; + } + impl_ = other.impl_->clone(); + return *this; + } + Iterator& operator=(Iterator&&) = default; + + bool operator==(const Iterator& other) const {return impl_->operator==(*other.impl_);} + bool operator!=(const Iterator& other) const {return !(*this == other);} + + Value operator*() const; + + private: + std::unique_ptr<Impl> impl_; + }; + + class Impl { + public: + virtual explicit operator bool() const = 0; + virtual bool isSequence() const = 0; + virtual bool isMap() const = 0; + virtual bool isNull() const = 0; + virtual bool isScalar() const = 0; + + virtual nonstd::expected<std::string, std::exception_ptr> getString() const = 0; + virtual nonstd::expected<int, std::exception_ptr> getInt() const = 0; + virtual nonstd::expected<unsigned int, std::exception_ptr> getUInt() const = 0; + virtual nonstd::expected<bool, std::exception_ptr> getBool() const = 0; + virtual nonstd::expected<int64_t, std::exception_ptr> getInt64() const = 0; + virtual nonstd::expected<uint64_t, std::exception_ptr> getUInt64() const = 0; + + virtual std::string getDebugString() const = 0; + + virtual size_t size() const = 0; + virtual Iterator begin() const = 0; + virtual Iterator end() const = 0; + virtual Node operator[](std::string_view key) const = 0; + + virtual std::optional<Cursor> getCursor() const {return std::nullopt;} Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
