szaszm commented on code in PR #1335: URL: https://github.com/apache/nifi-minifi-cpp/pull/1335#discussion_r886734051
########## libminifi/include/utils/Cron.h: ########## @@ -0,0 +1,55 @@ +/** + * 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 <exception> +#include <string> +#include <chrono> +#include <optional> +#include <memory> +#include <utility> +#include "date/tz.h" + +namespace org::apache::nifi::minifi::utils { +class BadCronExpression : public std::exception { + public: + explicit BadCronExpression(std::string msg) : msg_(std::move(msg)) {} + + [[nodiscard]] const char* what() const noexcept override { return (msg_.c_str()); } + + private: + std::string msg_; +}; + +class CronField { + public: + virtual ~CronField() = default; + + [[nodiscard]] virtual bool matches(date::local_seconds time_point) const = 0; +}; + +class Cron { + public: + explicit Cron(const std::string& expression); + Cron(Cron&& cron) = default; Review Comment: I'd say either remove this line and rely on the implicit move ctor, or declare all 5 special member functions. ########## libminifi/include/utils/TestUtils.h: ########## @@ -65,6 +69,10 @@ class ManualClock : public timeutils::Clock { std::chrono::milliseconds time_{0}; }; +#ifdef WIN32 +void dateSetInstall(const std::string& install); Review Comment: Could you add a comment about why this is needed? ########## libminifi/include/utils/Cron.h: ########## @@ -0,0 +1,55 @@ +/** + * 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 <exception> +#include <string> +#include <chrono> +#include <optional> +#include <memory> +#include <utility> +#include "date/tz.h" + +namespace org::apache::nifi::minifi::utils { +class BadCronExpression : public std::exception { + public: + explicit BadCronExpression(std::string msg) : msg_(std::move(msg)) {} + + [[nodiscard]] const char* what() const noexcept override { return (msg_.c_str()); } + + private: + std::string msg_; Review Comment: Avoid allocation in exception types. Instead use a base class that already provides a message buffer, and let it handle the message string, like we do in `minifi::Exception`. (Consider using that as your base class.) I couldn't find the reference, but basically exceptions have to copy the message to a special internal buffer anyway, because they need to be nothrow copyable. -- 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]
