Skip to content

Commit

Permalink
fable: Provide fable/fable_fwd.hpp header for forward declarations
Browse files Browse the repository at this point in the history
This follows the pattern set by other libraries, such as Boost
and nlohmann/json.
  • Loading branch information
cassava committed Apr 22, 2024
1 parent ac46bfa commit 107d756
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions fable/include/fable/fable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include <fable/fable_fwd.hpp>
#include <fable/conf.hpp>
#include <fable/confable.hpp>
#include <fable/enum.hpp>
Expand Down
51 changes: 51 additions & 0 deletions fable/include/fable/fable_fwd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2023 Robert Bosch GmbH
*
* Licensed 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* \file fable/fable_fwd.hpp
*/

#include <string>

#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/json_fwd.hpp>

namespace fable {

// from json.hpp
using Json = nlohmann::json;
using JsonPointer = nlohmann::json_pointer<std::string>;
using JsonType = nlohmann::detail::value_t;

// from conf.hpp
class Conf;

// from error.hpp
class Error;
class ConfError;
class SchemaError;

// from schema.hpp
class Schema;

// from confable.hpp
class Confable;

// from environment.hpp
class Environment;

} // namespace fable
6 changes: 3 additions & 3 deletions fable/include/fable/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ using Json = nlohmann::json;
* This makes it easier to talk/write about operations that deal with
* JSON pointers.
*/
using JsonPointer = Json::json_pointer;
using JsonPointer = nlohmann::json_pointer<std::string>;

/**
* The JsonType type maps to nlohmann::json::value_t.
*
* This makes it easier to talk/write about operations that deal on the
* underlying type that is stored in a Json value.
*/
using JsonType = Json::value_t;
using JsonType = nlohmann::detail::value_t;

/**
* Return a string representation of a JSON type.
Expand All @@ -100,7 +100,7 @@ std::string to_string(JsonType);
* See the documentation on each of these global variables for more details.
*/
template <typename InputType>
inline Json parse_json(InputType&& input) {
Json parse_json(InputType&& input) {
return Json::parse(std::forward<InputType>(input), nullptr, NLOHMANN_JSON_USE_EXCEPTIONS,
NLOHMANN_JSON_ALLOW_COMMENTS);
}
Expand Down

0 comments on commit 107d756

Please sign in to comment.