Skip to content

Commit a923588

Browse files
committed
fable: Rename fable::schema::Array to Vector
This is orthogonal with the standard library (std::vector) and allows us to add the Array type, which corresponds to the std::array type. BREAKING CHANGE: If you used fable::schema::Array directly you need to rename it to fable::schema::Vector. This is especially important as a future commit will introduce a separate Array schema type.
1 parent d5ddf0f commit a923588

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

engine/src/stack.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ inline auto id_path_prototype(std::string&& desc = "") {
107107
*/
108108
using IncludeConf = boost::filesystem::path;
109109
using IncludeSchema = decltype(schema::make_schema(static_cast<IncludeConf*>(nullptr), ""));
110-
using IncludesSchema = schema::Array<IncludeConf, IncludeSchema>;
110+
using IncludesSchema = schema::Vector<IncludeConf, IncludeSchema>;
111111

112112
// --------------------------------------------------------------------------------------------- //
113113

fable/include/fable/schema.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
#include <utility> // for move
121121
#include <vector> // for vector<>
122122

123-
#include <fable/schema/array.hpp> // for Array<>
124123
#include <fable/schema/boolean.hpp> // for Boolean
125124
#include <fable/schema/confable.hpp> // for FromConfable
126125
#include <fable/schema/const.hpp> // for Const<>
@@ -137,6 +136,7 @@
137136
#include <fable/schema/string.hpp> // for String
138137
#include <fable/schema/struct.hpp> // for Struct
139138
#include <fable/schema/variant.hpp> // for Variant
139+
#include <fable/schema/vector.hpp> // for Vector<>
140140

141141
// It is important that this include comes after all the other ones,
142142
// so that it has access to ALL the previous definitions.

fable/include/fable/schema/array.hpp renamed to fable/include/fable/schema/vector.hpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818
/**
19-
* \file fable/schema/array.hpp
19+
* \file fable/schema/vector.hpp
2020
* \see fable/schema/xmagic.hpp
2121
* \see fable/schema.hpp
2222
* \see fable/schema_test.cpp
@@ -37,21 +37,21 @@ namespace fable {
3737
namespace schema {
3838

3939
template <typename T, typename P>
40-
class Array : public Base<Array<T, P>> {
40+
class Vector : public Base<Vector<T, P>> {
4141
public: // Types and Constructors
4242
using Type = std::vector<T>;
4343
using PrototypeSchema = std::remove_cv_t<std::remove_reference_t<P>>;
4444

45-
Array(Type* ptr, std::string desc);
46-
Array(Type* ptr, PrototypeSchema prototype)
47-
: Base<Array<T, P>>(JsonType::array), prototype_(std::move(prototype)), ptr_(ptr) {}
48-
Array(Type* ptr, PrototypeSchema prototype, std::string desc)
49-
: Base<Array<T, P>>(JsonType::array, std::move(desc)), prototype_(std::move(prototype)), ptr_(ptr) {}
45+
Vector(Type* ptr, std::string desc);
46+
Vector(Type* ptr, PrototypeSchema prototype)
47+
: Base<Vector<T, P>>(JsonType::array), prototype_(std::move(prototype)), ptr_(ptr) {}
48+
Vector(Type* ptr, PrototypeSchema prototype, std::string desc)
49+
: Base<Vector<T, P>>(JsonType::array, std::move(desc)), prototype_(std::move(prototype)), ptr_(ptr) {}
5050

5151
#if 0
5252
// This is defined in: fable/schema/xmagic.hpp
53-
Array(Type* ptr, std::string desc)
54-
: Array(ptr, make_prototype<T>(), std::move(desc)) {}
53+
Vector(Type* ptr, std::string desc)
54+
: Vector(ptr, make_prototype<T>(), std::move(desc)) {}
5555
#endif
5656

5757
public: // Specials
@@ -71,21 +71,21 @@ class Array : public Base<Array<T, P>> {
7171
/**
7272
* Set whether deserialization should extend the underlying array.
7373
*/
74-
Array<T, P> extend(bool value) && {
74+
Vector<T, P> extend(bool value) && {
7575
option_extend_ = value;
7676
return std::move(*this);
7777
}
7878

7979
size_t min_items() const { return min_items_; }
8080
void set_min_items(size_t value) { min_items_ = value; }
81-
Array<T, P> min_items(size_t value) && {
81+
Vector<T, P> min_items(size_t value) && {
8282
min_items_ = value;
8383
return std::move(*this);
8484
}
8585

8686
size_t max_items() const { return max_items_; }
8787
void set_max_items(size_t value) { max_items_ = value; }
88-
Array<T, P> max_items(size_t value) && {
88+
Vector<T, P> max_items(size_t value) && {
8989
max_items_ = value;
9090
return std::move(*this);
9191
}
@@ -174,8 +174,8 @@ class Array : public Base<Array<T, P>> {
174174
};
175175

176176
template <typename T, typename P, typename S>
177-
Array<T, P> make_schema(std::vector<T>* ptr, P&& prototype, S&& desc) {
178-
return Array<T, P>(ptr, std::forward<P>(prototype), std::forward<S>(desc));
177+
Vector<T, P> make_schema(std::vector<T>* ptr, P&& prototype, S&& desc) {
178+
return Vector<T, P>(ptr, std::forward<P>(prototype), std::forward<S>(desc));
179179
}
180180

181181
} // namespace schema

fable/include/fable/schema/xmagic.hpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,23 @@
4040
#include <utility> // for move
4141
#include <vector> // for vector<>
4242

43-
#include <fable/schema/array.hpp> // for Array<>
43+
#include <fable/fable_fwd.hpp> // for Confable
4444
#include <fable/schema/confable.hpp> // for FromConfable<>
4545
#include <fable/schema/const.hpp> // for Const<>
4646
#include <fable/schema/map.hpp> // for Map<>
4747
#include <fable/schema/optional.hpp> // for Optional<>
48+
#include <fable/schema/vector.hpp> // for Vector<>
4849

4950
namespace fable {
50-
51-
// Forward declarations:
52-
class Confable;
53-
5451
namespace schema {
5552

5653
template <typename T, typename P>
57-
Array<T, P>::Array(std::vector<T>* ptr, std::string desc)
58-
: Array<T, P>(ptr, make_prototype<T>(), std::move(desc)) {}
54+
Vector<T, P>::Vector(std::vector<T>* ptr, std::string desc)
55+
: Vector<T, P>(ptr, make_prototype<T>(), std::move(desc)) {}
5956

6057
template <typename T, typename S>
61-
Array<T, decltype(make_prototype<T>())> make_schema(std::vector<T>* ptr, S&& desc) {
62-
return Array<T, decltype(make_prototype<T>())>(ptr, std::forward<S>(desc));
58+
Vector<T, decltype(make_prototype<T>())> make_schema(std::vector<T>* ptr, S&& desc) {
59+
return Vector<T, decltype(make_prototype<T>())>(ptr, std::forward<S>(desc));
6360
}
6461

6562
template <typename T, typename P>

fable/src/fable/schema/enum_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ TEST(fable_schema_enum, struct_enum) {
6464
TEST(fable_schema_enum, vector_enum_ok) {
6565
using namespace fable::schema; // NOLINT(build/namespaces)
6666
std::vector<LogLevel> xs;
67-
Array<LogLevel, Enum<LogLevel>> s{&xs, ""};
67+
Vector<LogLevel, Enum<LogLevel>> s{&xs, ""};
6868

6969
fable::assert_to_json(s, "[]");
7070
fable::assert_from_eq_to(s, R"([
@@ -77,7 +77,7 @@ TEST(fable_schema_enum, vector_enum_ok) {
7777
TEST(fable_schema_enum, vector_struct_enum) {
7878
using namespace fable::schema; // NOLINT(build/namespaces)
7979
std::vector<LoggerStruct> xs;
80-
Array<LoggerStruct, FromConfable<LoggerStruct>> s{&xs, ""};
80+
Vector<LoggerStruct, FromConfable<LoggerStruct>> s{&xs, ""};
8181

8282
fable::assert_to_json(s, "[]");
8383
fable::assert_from_eq_to(s, R"([

0 commit comments

Comments
 (0)