$darkmode
boolean.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 
33 class Boolean : public Base<Boolean> {
34  public: // Types and Constructors
35  using Type = bool;
36 
37  Boolean(Type* ptr, std::string desc);
38 
39  public: // Overrides
40  [[nodiscard]] Json json_schema() const override;
41  bool validate(const Conf& c, std::optional<SchemaError>& err) const override;
42  using Interface::to_json;
43  void to_json(Json& j) const override;
44  void from_conf(const Conf& c) override;
45  [[nodiscard]] Json serialize(const Type& x) const;
46  [[nodiscard]] Type deserialize(const Conf& c) const;
47  void serialize_into(Json& j, const Type& x) const;
48  void deserialize_into(const Conf& c, Type& x) const;
49  void reset_ptr() override;
50 
51  private:
52  Type* ptr_{nullptr};
53 };
54 
55 template <typename S>
56 Boolean make_schema(bool* ptr, S&& desc) {
57  return {ptr, std::forward<S>(desc)};
58 }
59 
60 } // namespace fable::schema
Definition: conf.hpp:82
Definition: interface.hpp:398
Definition: boolean.hpp:33
void from_conf(const Conf &c) override
Definition: boolean.cpp:50
Json json_schema() const override
Definition: boolean.cpp:33
virtual Json to_json() const
Definition: interface.hpp:254
bool validate(const Conf &c, std::optional< SchemaError > &err) const override
Definition: boolean.cpp:41
void reset_ptr() override
Definition: boolean.cpp:63
virtual Json to_json() const
Definition: interface.hpp:254
nlohmann::json Json
Definition: fable_fwd.hpp:35