$darkmode
ignore.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
24 #pragma once
25 
26 #include <string> // for string
27 #include <utility> // for move
28 
29 #include <fable/schema/interface.hpp> // for Base<>
30 
31 namespace fable::schema {
32 
43 class Ignore : public Base<Ignore> {
44  public: // Constructors
45  using Type = struct {};
46 
47  Ignore() : Base(JsonType::object, "ignored") {}
48  explicit Ignore(std::string desc, JsonType t = JsonType::object) : Base(t, std::move(desc)) {}
49 
50  public: // Overrides
51  [[nodiscard]] Json json_schema() const override {
52  Json j = Json::object({});
53  this->augment_schema(j);
54  return j;
55  }
56 
57  bool validate(const Conf& /*unused*/, std::optional<SchemaError>& /*unused*/) const override { return true; }
58  using Interface::to_json;
59  void to_json(Json& j) const override { j = nullptr; }
60  void from_conf(const Conf& /*unused*/) override {}
61  void reset_ptr() override {}
62 
63  [[nodiscard]] Json serialize(const Type& /*unused*/) const { return nullptr; } // NOLINT(readability-convert-member-functions-to-static)
64  [[nodiscard]] Type deserialize(const Conf& /*unused*/) const { return {}; }
65  void serialize_into(Json& /*unused*/, const Type& /*unused*/) const {}
66  void deserialize_into(const Conf& /*unused*/, Type& /*unused*/) const {}
67 };
68 
69 inline Ignore make_schema(std::string desc, JsonType t = JsonType::object) {
70  return Ignore(std::move(desc), t);
71 }
72 
73 } // namespace fable::schema
Definition: conf.hpp:76
Definition: interface.hpp:398
Definition: ignore.hpp:43
bool validate(const Conf &, std::optional< SchemaError > &) const override
Definition: ignore.hpp:57
Json json_schema() const override
Definition: ignore.hpp:51
void from_conf(const Conf &) override
Definition: ignore.hpp:60
void to_json(Json &j) const override
Definition: ignore.hpp:59
void reset_ptr() override
Definition: ignore.hpp:61
virtual Json to_json() const
Definition: interface.hpp:254
nlohmann::json Json
Definition: fable_fwd.hpp:35
nlohmann::detail::value_t JsonType
Definition: fable_fwd.hpp:37