nvfuser-cu121-torch25 0.2.25.dev20250201__cp310-cp310-manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- nvfuser/_C.cpython-310-x86_64-linux-gnu.so +0 -0
- nvfuser/__init__.py +618 -0
- nvfuser/__init__.pyi +4 -0
- nvfuser/contrib/__init__.py +9 -0
- nvfuser/contrib/nn/__init__.py +13 -0
- nvfuser/contrib/nn/normalization.py +725 -0
- nvfuser/include/nvfuser/alias_analysis.h +116 -0
- nvfuser/include/nvfuser/bfs.h +929 -0
- nvfuser/include/nvfuser/codegen.h +26 -0
- nvfuser/include/nvfuser/compute_at.h +28 -0
- nvfuser/include/nvfuser/compute_at_map.h +394 -0
- nvfuser/include/nvfuser/contiguity.h +351 -0
- nvfuser/include/nvfuser/cuda_utils.h +50 -0
- nvfuser/include/nvfuser/debug.h +50 -0
- nvfuser/include/nvfuser/device_lower/analysis/bank_conflict.h +53 -0
- nvfuser/include/nvfuser/device_lower/analysis/circular_buffer.h +109 -0
- nvfuser/include/nvfuser/device_lower/analysis/device_version.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/divisible_split.h +28 -0
- nvfuser/include/nvfuser/device_lower/analysis/fused_reduction.h +36 -0
- nvfuser/include/nvfuser/device_lower/analysis/index_compute.h +322 -0
- nvfuser/include/nvfuser/device_lower/analysis/predicate_elimination.h +71 -0
- nvfuser/include/nvfuser/device_lower/analysis/sync_information.h +47 -0
- nvfuser/include/nvfuser/device_lower/analysis/tensor_memory.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/thread_predicate.h +158 -0
- nvfuser/include/nvfuser/device_lower/analysis/tma.h +93 -0
- nvfuser/include/nvfuser/device_lower/analysis/trivial_broadcast.h +75 -0
- nvfuser/include/nvfuser/device_lower/id_model_options.h +135 -0
- nvfuser/include/nvfuser/device_lower/lower2device.h +391 -0
- nvfuser/include/nvfuser/device_lower/pass/alias_memory.h +37 -0
- nvfuser/include/nvfuser/device_lower/pass/allocation.h +32 -0
- nvfuser/include/nvfuser/device_lower/pass/circular_buffer.h +191 -0
- nvfuser/include/nvfuser/device_lower/pass/expr_sort.h +17 -0
- nvfuser/include/nvfuser/device_lower/pass/fusion_simplifier.h +21 -0
- nvfuser/include/nvfuser/device_lower/pass/grid_serialization.h +26 -0
- nvfuser/include/nvfuser/device_lower/pass/index.h +200 -0
- nvfuser/include/nvfuser/device_lower/pass/inline_ptx.h +16 -0
- nvfuser/include/nvfuser/device_lower/pass/insert_syncs.h +39 -0
- nvfuser/include/nvfuser/device_lower/pass/instrument.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/loop_rotation.h +150 -0
- nvfuser/include/nvfuser/device_lower/pass/loops.h +68 -0
- nvfuser/include/nvfuser/device_lower/pass/magic_zero.h +86 -0
- nvfuser/include/nvfuser/device_lower/pass/misaligned_vectorization.h +118 -0
- nvfuser/include/nvfuser/device_lower/pass/predicate.h +23 -0
- nvfuser/include/nvfuser/device_lower/pass/replace_size.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/scalar_hoist.h +115 -0
- nvfuser/include/nvfuser/device_lower/pass/unroll.h +98 -0
- nvfuser/include/nvfuser/device_lower/pass/vectorize_welford.h +45 -0
- nvfuser/include/nvfuser/device_lower/pass/warp_reduce.h +23 -0
- nvfuser/include/nvfuser/device_lower/utils.h +382 -0
- nvfuser/include/nvfuser/device_lower/validation.h +74 -0
- nvfuser/include/nvfuser/disjoint_set.h +556 -0
- nvfuser/include/nvfuser/dispatch.h +334 -0
- nvfuser/include/nvfuser/driver_api.h +49 -0
- nvfuser/include/nvfuser/dynamic_transform.h +316 -0
- nvfuser/include/nvfuser/dynamic_type/C++20/type_traits +37 -0
- nvfuser/include/nvfuser/dynamic_type/dynamic_type.h +969 -0
- nvfuser/include/nvfuser/dynamic_type/error.h +24 -0
- nvfuser/include/nvfuser/dynamic_type/type_traits.h +703 -0
- nvfuser/include/nvfuser/evaluator_common.h +295 -0
- nvfuser/include/nvfuser/exceptions.h +283 -0
- nvfuser/include/nvfuser/expr_evaluator.h +125 -0
- nvfuser/include/nvfuser/expr_simplifier.h +218 -0
- nvfuser/include/nvfuser/flatbuffers/allocator.h +68 -0
- nvfuser/include/nvfuser/flatbuffers/array.h +253 -0
- nvfuser/include/nvfuser/flatbuffers/base.h +486 -0
- nvfuser/include/nvfuser/flatbuffers/buffer.h +154 -0
- nvfuser/include/nvfuser/flatbuffers/buffer_ref.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/code_generator.h +80 -0
- nvfuser/include/nvfuser/flatbuffers/code_generators.h +234 -0
- nvfuser/include/nvfuser/flatbuffers/default_allocator.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/detached_buffer.h +114 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffer_builder.h +1225 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffers.h +272 -0
- nvfuser/include/nvfuser/flatbuffers/flatc.h +130 -0
- nvfuser/include/nvfuser/flatbuffers/flex_flat_util.h +36 -0
- nvfuser/include/nvfuser/flatbuffers/flexbuffers.h +1889 -0
- nvfuser/include/nvfuser/flatbuffers/grpc.h +300 -0
- nvfuser/include/nvfuser/flatbuffers/hash.h +127 -0
- nvfuser/include/nvfuser/flatbuffers/idl.h +1359 -0
- nvfuser/include/nvfuser/flatbuffers/minireflect.h +420 -0
- nvfuser/include/nvfuser/flatbuffers/reflection.h +522 -0
- nvfuser/include/nvfuser/flatbuffers/reflection_generated.h +1471 -0
- nvfuser/include/nvfuser/flatbuffers/registry.h +128 -0
- nvfuser/include/nvfuser/flatbuffers/stl_emulation.h +513 -0
- nvfuser/include/nvfuser/flatbuffers/string.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/struct.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/table.h +168 -0
- nvfuser/include/nvfuser/flatbuffers/util.h +731 -0
- nvfuser/include/nvfuser/flatbuffers/vector.h +393 -0
- nvfuser/include/nvfuser/flatbuffers/vector_downward.h +273 -0
- nvfuser/include/nvfuser/flatbuffers/verifier.h +317 -0
- nvfuser/include/nvfuser/fusion.h +511 -0
- nvfuser/include/nvfuser/fusion_guard.h +37 -0
- nvfuser/include/nvfuser/fusion_profiler.h +311 -0
- nvfuser/include/nvfuser/fusion_segmenter.h +751 -0
- nvfuser/include/nvfuser/global_allocator.h +27 -0
- nvfuser/include/nvfuser/grouped_reduction.h +47 -0
- nvfuser/include/nvfuser/host_ir/container.h +60 -0
- nvfuser/include/nvfuser/host_ir/executor.h +152 -0
- nvfuser/include/nvfuser/host_ir/host_ir.h +320 -0
- nvfuser/include/nvfuser/host_ir/lower.h +35 -0
- nvfuser/include/nvfuser/id_model/circular_buffer_indexing.h +56 -0
- nvfuser/include/nvfuser/id_model/contiguity.h +166 -0
- nvfuser/include/nvfuser/id_model/id_model.h +359 -0
- nvfuser/include/nvfuser/id_model/id_model_index_compute.h +81 -0
- nvfuser/include/nvfuser/id_model/indexing.h +208 -0
- nvfuser/include/nvfuser/id_model/indexing_traversal.h +72 -0
- nvfuser/include/nvfuser/id_model/indexing_utils.h +62 -0
- nvfuser/include/nvfuser/id_model/loop_promotion.h +180 -0
- nvfuser/include/nvfuser/id_model/predicate_indexing.h +104 -0
- nvfuser/include/nvfuser/id_model/schedule.h +54 -0
- nvfuser/include/nvfuser/id_model/to_string.h +87 -0
- nvfuser/include/nvfuser/id_model/transform_replay.h +58 -0
- nvfuser/include/nvfuser/id_model/utils.h +176 -0
- nvfuser/include/nvfuser/id_model/validation_utils.h +55 -0
- nvfuser/include/nvfuser/index_compute.h +651 -0
- nvfuser/include/nvfuser/instrumentation.h +107 -0
- nvfuser/include/nvfuser/ir/all_nodes.h +14 -0
- nvfuser/include/nvfuser/ir/base_nodes.h +687 -0
- nvfuser/include/nvfuser/ir/builder.h +215 -0
- nvfuser/include/nvfuser/ir/builder_passkey.h +29 -0
- nvfuser/include/nvfuser/ir/cloner.h +185 -0
- nvfuser/include/nvfuser/ir/container.h +226 -0
- nvfuser/include/nvfuser/ir/graphviz.h +119 -0
- nvfuser/include/nvfuser/ir/interface_nodes.h +957 -0
- nvfuser/include/nvfuser/ir/internal_base_nodes.h +744 -0
- nvfuser/include/nvfuser/ir/internal_nodes.h +2792 -0
- nvfuser/include/nvfuser/ir/iostream.h +98 -0
- nvfuser/include/nvfuser/ir/printer.h +57 -0
- nvfuser/include/nvfuser/ir/utils.h +801 -0
- nvfuser/include/nvfuser/iter_visitor.h +661 -0
- nvfuser/include/nvfuser/kernel.h +299 -0
- nvfuser/include/nvfuser/kernel_db/kernel_db.h +109 -0
- nvfuser/include/nvfuser/kernel_db/utils.h +37 -0
- nvfuser/include/nvfuser/kernel_ir.h +1457 -0
- nvfuser/include/nvfuser/kernel_ir_dispatch.h +147 -0
- nvfuser/include/nvfuser/linked_hash_map.h +97 -0
- nvfuser/include/nvfuser/logical_domain_map.h +577 -0
- nvfuser/include/nvfuser/macros.h +23 -0
- nvfuser/include/nvfuser/mma_type.h +257 -0
- nvfuser/include/nvfuser/multidevice/c10d_mock.h +175 -0
- nvfuser/include/nvfuser/multidevice/communication.h +232 -0
- nvfuser/include/nvfuser/multidevice/communicator.h +179 -0
- nvfuser/include/nvfuser/multidevice/device_mesh.h +95 -0
- nvfuser/include/nvfuser/multidevice/executor.h +107 -0
- nvfuser/include/nvfuser/multidevice/multidevice.h +18 -0
- nvfuser/include/nvfuser/multidevice/utils.h +187 -0
- nvfuser/include/nvfuser/non_divisible_split.h +86 -0
- nvfuser/include/nvfuser/opaque_type.h +129 -0
- nvfuser/include/nvfuser/ops/alias.h +192 -0
- nvfuser/include/nvfuser/ops/all_ops.h +13 -0
- nvfuser/include/nvfuser/ops/arith.h +712 -0
- nvfuser/include/nvfuser/ops/composite.h +130 -0
- nvfuser/include/nvfuser/ops/indexing.h +55 -0
- nvfuser/include/nvfuser/ops/normalization.h +263 -0
- nvfuser/include/nvfuser/ops/utils.h +127 -0
- nvfuser/include/nvfuser/options.h +313 -0
- nvfuser/include/nvfuser/parallel_dimension_map.h +95 -0
- nvfuser/include/nvfuser/parallel_type_bitmap.h +365 -0
- nvfuser/include/nvfuser/polymorphic_value.h +432 -0
- nvfuser/include/nvfuser/predicate_compute.h +213 -0
- nvfuser/include/nvfuser/python_frontend/distributed_tensor.h +50 -0
- nvfuser/include/nvfuser/python_frontend/fusion_cache.h +298 -0
- nvfuser/include/nvfuser/python_frontend/fusion_definition.h +372 -0
- nvfuser/include/nvfuser/python_frontend/fusion_record.h +3124 -0
- nvfuser/include/nvfuser/python_frontend/fusion_state.h +143 -0
- nvfuser/include/nvfuser/python_frontend/python_bindings.h +27 -0
- nvfuser/include/nvfuser/python_frontend/segmentation.h +246 -0
- nvfuser/include/nvfuser/python_frontend/translation.h +20 -0
- nvfuser/include/nvfuser/python_frontend/translation_utils.h +308 -0
- nvfuser/include/nvfuser/scheduler/all_schedulers.h +17 -0
- nvfuser/include/nvfuser/scheduler/ampere_multi_matmul.h +206 -0
- nvfuser/include/nvfuser/scheduler/cache_policy_refiner.h +19 -0
- nvfuser/include/nvfuser/scheduler/compile_time_info.h +322 -0
- nvfuser/include/nvfuser/scheduler/debug_utils.h +68 -0
- nvfuser/include/nvfuser/scheduler/expr_eval_sched.h +45 -0
- nvfuser/include/nvfuser/scheduler/heuristic.h +113 -0
- nvfuser/include/nvfuser/scheduler/hopper_multi_matmul.h +204 -0
- nvfuser/include/nvfuser/scheduler/mark_aliases.h +19 -0
- nvfuser/include/nvfuser/scheduler/matmul.h +40 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic.h +293 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin.h +65 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin_api.h +99 -0
- nvfuser/include/nvfuser/scheduler/matmul_utils.h +54 -0
- nvfuser/include/nvfuser/scheduler/mma_utils.h +500 -0
- nvfuser/include/nvfuser/scheduler/multi_matmul.h +74 -0
- nvfuser/include/nvfuser/scheduler/no_op.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner.h +49 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner_outer.h +51 -0
- nvfuser/include/nvfuser/scheduler/normalization_outer.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_utils.h +379 -0
- nvfuser/include/nvfuser/scheduler/pointwise.h +183 -0
- nvfuser/include/nvfuser/scheduler/pointwise_heuristic.h +118 -0
- nvfuser/include/nvfuser/scheduler/pointwise_utils.h +24 -0
- nvfuser/include/nvfuser/scheduler/reduction.h +43 -0
- nvfuser/include/nvfuser/scheduler/reduction_heuristic.h +339 -0
- nvfuser/include/nvfuser/scheduler/reduction_utils.h +159 -0
- nvfuser/include/nvfuser/scheduler/registry.h +97 -0
- nvfuser/include/nvfuser/scheduler/registry_utils.h +111 -0
- nvfuser/include/nvfuser/scheduler/resize.h +41 -0
- nvfuser/include/nvfuser/scheduler/resize_heuristic.h +67 -0
- nvfuser/include/nvfuser/scheduler/runtime_info.h +166 -0
- nvfuser/include/nvfuser/scheduler/scheduler_types.h +80 -0
- nvfuser/include/nvfuser/scheduler/transpose.h +114 -0
- nvfuser/include/nvfuser/scheduler/transpose_heuristic.h +164 -0
- nvfuser/include/nvfuser/scheduler/utils.h +771 -0
- nvfuser/include/nvfuser/scheduler/vectorize_helper.h +349 -0
- nvfuser/include/nvfuser/serde/factory.h +55 -0
- nvfuser/include/nvfuser/serde/fusion_cache_generated.h +4319 -0
- nvfuser/include/nvfuser/serde/fusion_record.h +124 -0
- nvfuser/include/nvfuser/serde/polymorphic_value.h +52 -0
- nvfuser/include/nvfuser/serde/utils.h +34 -0
- nvfuser/include/nvfuser/struct.inl +127 -0
- nvfuser/include/nvfuser/swizzle.h +54 -0
- nvfuser/include/nvfuser/sys_utils.h +40 -0
- nvfuser/include/nvfuser/tensor_metadata.h +118 -0
- nvfuser/include/nvfuser/tma.h +124 -0
- nvfuser/include/nvfuser/transform_iter.h +522 -0
- nvfuser/include/nvfuser/transform_replay.h +297 -0
- nvfuser/include/nvfuser/transform_rfactor.h +33 -0
- nvfuser/include/nvfuser/transform_view.h +136 -0
- nvfuser/include/nvfuser/type.h +1125 -0
- nvfuser/include/nvfuser/type_promotion.h +61 -0
- nvfuser/include/nvfuser/utils.h +619 -0
- nvfuser/include/nvfuser/val_graph.h +446 -0
- nvfuser/include/nvfuser/val_graph_visitor.h +259 -0
- nvfuser/include/nvfuser/validator_utils.h +92 -0
- nvfuser/include/nvfuser/vectorization_info.h +31 -0
- nvfuser/include/nvfuser/visibility.h +21 -0
- nvfuser/lib/libnvfuser_codegen.so +0 -0
- nvfuser/nvfuser_version.py +69 -0
- nvfuser/pytorch_utils.py +184 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig-release.cmake +20 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig.cmake +106 -0
- nvfuser/utils.py +18 -0
- nvfuser/version.py +1 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/LICENSE +976 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/METADATA +20 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/RECORD +242 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/WHEEL +5 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/top_level.txt +1 -0
- nvfuser_cu121_torch25.libs/libnvToolsExt-847d78f2.so.1.0.0 +0 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2017 Google Inc. All rights reserved.
|
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
|
+
|
17
|
+
#ifndef FLATBUFFERS_REGISTRY_H_
|
18
|
+
#define FLATBUFFERS_REGISTRY_H_
|
19
|
+
|
20
|
+
#include "flatbuffers/base.h"
|
21
|
+
#include "flatbuffers/idl.h"
|
22
|
+
|
23
|
+
namespace flatbuffers {
|
24
|
+
|
25
|
+
// Convenience class to easily parse or generate text for arbitrary FlatBuffers.
|
26
|
+
// Simply pre-populate it with all schema filenames that may be in use, and
|
27
|
+
// This class will look them up using the file_identifier declared in the
|
28
|
+
// schema.
|
29
|
+
class Registry {
|
30
|
+
public:
|
31
|
+
// Call this for all schemas that may be in use. The identifier has
|
32
|
+
// a function in the generated code, e.g. MonsterIdentifier().
|
33
|
+
void Register(const char *file_identifier, const char *schema_path) {
|
34
|
+
Schema schema;
|
35
|
+
schema.path_ = schema_path;
|
36
|
+
schemas_[file_identifier] = schema;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Generate text from an arbitrary FlatBuffer by looking up its
|
40
|
+
// file_identifier in the registry.
|
41
|
+
bool FlatBufferToText(const uint8_t *flatbuf, size_t len, std::string *dest) {
|
42
|
+
// Get the identifier out of the buffer.
|
43
|
+
// If the buffer is truncated, exit.
|
44
|
+
if (len < sizeof(uoffset_t) + kFileIdentifierLength) {
|
45
|
+
lasterror_ = "buffer truncated";
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
std::string ident(
|
49
|
+
reinterpret_cast<const char *>(flatbuf) + sizeof(uoffset_t),
|
50
|
+
kFileIdentifierLength);
|
51
|
+
// Load and parse the schema.
|
52
|
+
Parser parser;
|
53
|
+
if (!LoadSchema(ident, &parser)) return false;
|
54
|
+
// Now we're ready to generate text.
|
55
|
+
if (!GenerateText(parser, flatbuf, dest)) {
|
56
|
+
lasterror_ = "unable to generate text for FlatBuffer binary";
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
|
62
|
+
// Converts a binary buffer to text using one of the schemas in the registry,
|
63
|
+
// use the file_identifier to indicate which.
|
64
|
+
// If DetachedBuffer::data() is null then parsing failed.
|
65
|
+
DetachedBuffer TextToFlatBuffer(const char *text,
|
66
|
+
const char *file_identifier) {
|
67
|
+
// Load and parse the schema.
|
68
|
+
Parser parser;
|
69
|
+
if (!LoadSchema(file_identifier, &parser)) return DetachedBuffer();
|
70
|
+
// Parse the text.
|
71
|
+
if (!parser.Parse(text)) {
|
72
|
+
lasterror_ = parser.error_;
|
73
|
+
return DetachedBuffer();
|
74
|
+
}
|
75
|
+
// We have a valid FlatBuffer. Detach it from the builder and return.
|
76
|
+
return parser.builder_.Release();
|
77
|
+
}
|
78
|
+
|
79
|
+
// Modify any parsing / output options used by the other functions.
|
80
|
+
void SetOptions(const IDLOptions &opts) { opts_ = opts; }
|
81
|
+
|
82
|
+
// If schemas used contain include statements, call this function for every
|
83
|
+
// directory the parser should search them for.
|
84
|
+
void AddIncludeDirectory(const char *path) { include_paths_.push_back(path); }
|
85
|
+
|
86
|
+
// Returns a human readable error if any of the above functions fail.
|
87
|
+
const std::string &GetLastError() { return lasterror_; }
|
88
|
+
|
89
|
+
private:
|
90
|
+
bool LoadSchema(const std::string &ident, Parser *parser) {
|
91
|
+
// Find the schema, if not, exit.
|
92
|
+
auto it = schemas_.find(ident);
|
93
|
+
if (it == schemas_.end()) {
|
94
|
+
// Don't attach the identifier, since it may not be human readable.
|
95
|
+
lasterror_ = "identifier for this buffer not in the registry";
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
auto &schema = it->second;
|
99
|
+
// Load the schema from disk. If not, exit.
|
100
|
+
std::string schematext;
|
101
|
+
if (!LoadFile(schema.path_.c_str(), false, &schematext)) {
|
102
|
+
lasterror_ = "could not load schema: " + schema.path_;
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
// Parse schema.
|
106
|
+
parser->opts = opts_;
|
107
|
+
if (!parser->Parse(schematext.c_str(), include_paths_.data(),
|
108
|
+
schema.path_.c_str())) {
|
109
|
+
lasterror_ = parser->error_;
|
110
|
+
return false;
|
111
|
+
}
|
112
|
+
return true;
|
113
|
+
}
|
114
|
+
|
115
|
+
struct Schema {
|
116
|
+
std::string path_;
|
117
|
+
// TODO(wvo) optionally cache schema file or parsed schema here.
|
118
|
+
};
|
119
|
+
|
120
|
+
std::string lasterror_;
|
121
|
+
IDLOptions opts_;
|
122
|
+
std::vector<const char *> include_paths_;
|
123
|
+
std::map<std::string, Schema> schemas_;
|
124
|
+
};
|
125
|
+
|
126
|
+
} // namespace flatbuffers
|
127
|
+
|
128
|
+
#endif // FLATBUFFERS_REGISTRY_H_
|
@@ -0,0 +1,513 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2017 Google Inc. All rights reserved.
|
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
|
+
|
17
|
+
#ifndef FLATBUFFERS_STL_EMULATION_H_
|
18
|
+
#define FLATBUFFERS_STL_EMULATION_H_
|
19
|
+
|
20
|
+
// clang-format off
|
21
|
+
#include "flatbuffers/base.h"
|
22
|
+
|
23
|
+
#include <string>
|
24
|
+
#include <type_traits>
|
25
|
+
#include <vector>
|
26
|
+
#include <memory>
|
27
|
+
#include <limits>
|
28
|
+
|
29
|
+
#ifndef FLATBUFFERS_USE_STD_OPTIONAL
|
30
|
+
// Detect C++17 compatible compiler.
|
31
|
+
// __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
|
32
|
+
#if (defined(__cplusplus) && __cplusplus >= 201703L) \
|
33
|
+
|| (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
|
34
|
+
#define FLATBUFFERS_USE_STD_OPTIONAL 1
|
35
|
+
#else
|
36
|
+
#define FLATBUFFERS_USE_STD_OPTIONAL 0
|
37
|
+
#endif // (defined(__cplusplus) && __cplusplus >= 201703L) ...
|
38
|
+
#endif // FLATBUFFERS_USE_STD_OPTIONAL
|
39
|
+
|
40
|
+
#if FLATBUFFERS_USE_STD_OPTIONAL
|
41
|
+
#include <optional>
|
42
|
+
#endif
|
43
|
+
|
44
|
+
#ifndef FLATBUFFERS_USE_STD_SPAN
|
45
|
+
// Testing __cpp_lib_span requires including either <version> or <span>,
|
46
|
+
// both of which were added in C++20.
|
47
|
+
// See: https://en.cppreference.com/w/cpp/utility/feature_test
|
48
|
+
#if defined(__cplusplus) && __cplusplus >= 202002L
|
49
|
+
#define FLATBUFFERS_USE_STD_SPAN 1
|
50
|
+
#endif
|
51
|
+
#endif // FLATBUFFERS_USE_STD_SPAN
|
52
|
+
|
53
|
+
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
54
|
+
#include <array>
|
55
|
+
#include <span>
|
56
|
+
#else
|
57
|
+
// Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
|
58
|
+
#if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
59
|
+
#define FLATBUFFERS_SPAN_MINIMAL
|
60
|
+
#else
|
61
|
+
// Enable implicit construction of a span<T,N> from a std::array<T,N>.
|
62
|
+
#include <array>
|
63
|
+
#endif
|
64
|
+
#endif // defined(FLATBUFFERS_USE_STD_SPAN)
|
65
|
+
|
66
|
+
// This header provides backwards compatibility for older versions of the STL.
|
67
|
+
namespace flatbuffers {
|
68
|
+
|
69
|
+
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
70
|
+
template <typename T>
|
71
|
+
using numeric_limits = std::numeric_limits<T>;
|
72
|
+
#else
|
73
|
+
template <typename T> class numeric_limits :
|
74
|
+
public std::numeric_limits<T> {};
|
75
|
+
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
76
|
+
|
77
|
+
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
78
|
+
template <typename T> using is_scalar = std::is_scalar<T>;
|
79
|
+
template <typename T, typename U> using is_same = std::is_same<T,U>;
|
80
|
+
template <typename T> using is_floating_point = std::is_floating_point<T>;
|
81
|
+
template <typename T> using is_unsigned = std::is_unsigned<T>;
|
82
|
+
template <typename T> using is_enum = std::is_enum<T>;
|
83
|
+
template <typename T> using make_unsigned = std::make_unsigned<T>;
|
84
|
+
template<bool B, class T, class F>
|
85
|
+
using conditional = std::conditional<B, T, F>;
|
86
|
+
template<class T, T v>
|
87
|
+
using integral_constant = std::integral_constant<T, v>;
|
88
|
+
template <bool B>
|
89
|
+
using bool_constant = integral_constant<bool, B>;
|
90
|
+
using true_type = std::true_type;
|
91
|
+
using false_type = std::false_type;
|
92
|
+
#else
|
93
|
+
// MSVC 2010 doesn't support C++11 aliases.
|
94
|
+
template <typename T> struct is_scalar : public std::is_scalar<T> {};
|
95
|
+
template <typename T, typename U> struct is_same : public std::is_same<T,U> {};
|
96
|
+
template <typename T> struct is_floating_point :
|
97
|
+
public std::is_floating_point<T> {};
|
98
|
+
template <typename T> struct is_unsigned : public std::is_unsigned<T> {};
|
99
|
+
template <typename T> struct is_enum : public std::is_enum<T> {};
|
100
|
+
template <typename T> struct make_unsigned : public std::make_unsigned<T> {};
|
101
|
+
template<bool B, class T, class F>
|
102
|
+
struct conditional : public std::conditional<B, T, F> {};
|
103
|
+
template<class T, T v>
|
104
|
+
struct integral_constant : public std::integral_constant<T, v> {};
|
105
|
+
template <bool B>
|
106
|
+
struct bool_constant : public integral_constant<bool, B> {};
|
107
|
+
typedef bool_constant<true> true_type;
|
108
|
+
typedef bool_constant<false> false_type;
|
109
|
+
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
110
|
+
|
111
|
+
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
112
|
+
template <class T> using unique_ptr = std::unique_ptr<T>;
|
113
|
+
#else
|
114
|
+
// MSVC 2010 doesn't support C++11 aliases.
|
115
|
+
// We're manually "aliasing" the class here as we want to bring unique_ptr
|
116
|
+
// into the flatbuffers namespace. We have unique_ptr in the flatbuffers
|
117
|
+
// namespace we have a completely independent implementation (see below)
|
118
|
+
// for C++98 STL implementations.
|
119
|
+
template <class T> class unique_ptr : public std::unique_ptr<T> {
|
120
|
+
public:
|
121
|
+
unique_ptr() {}
|
122
|
+
explicit unique_ptr(T* p) : std::unique_ptr<T>(p) {}
|
123
|
+
unique_ptr(std::unique_ptr<T>&& u) { *this = std::move(u); }
|
124
|
+
unique_ptr(unique_ptr&& u) { *this = std::move(u); }
|
125
|
+
unique_ptr& operator=(std::unique_ptr<T>&& u) {
|
126
|
+
std::unique_ptr<T>::reset(u.release());
|
127
|
+
return *this;
|
128
|
+
}
|
129
|
+
unique_ptr& operator=(unique_ptr&& u) {
|
130
|
+
std::unique_ptr<T>::reset(u.release());
|
131
|
+
return *this;
|
132
|
+
}
|
133
|
+
unique_ptr& operator=(T* p) {
|
134
|
+
return std::unique_ptr<T>::operator=(p);
|
135
|
+
}
|
136
|
+
};
|
137
|
+
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
138
|
+
|
139
|
+
#if FLATBUFFERS_USE_STD_OPTIONAL
|
140
|
+
template<class T>
|
141
|
+
using Optional = std::optional<T>;
|
142
|
+
using nullopt_t = std::nullopt_t;
|
143
|
+
inline constexpr nullopt_t nullopt = std::nullopt;
|
144
|
+
|
145
|
+
#else
|
146
|
+
// Limited implementation of Optional<T> type for a scalar T.
|
147
|
+
// This implementation limited by trivial types compatible with
|
148
|
+
// std::is_arithmetic<T> or std::is_enum<T> type traits.
|
149
|
+
|
150
|
+
// A tag to indicate an empty flatbuffers::optional<T>.
|
151
|
+
struct nullopt_t {
|
152
|
+
explicit FLATBUFFERS_CONSTEXPR_CPP11 nullopt_t(int) {}
|
153
|
+
};
|
154
|
+
|
155
|
+
#if defined(FLATBUFFERS_CONSTEXPR_DEFINED)
|
156
|
+
namespace internal {
|
157
|
+
template <class> struct nullopt_holder {
|
158
|
+
static constexpr nullopt_t instance_ = nullopt_t(0);
|
159
|
+
};
|
160
|
+
template<class Dummy>
|
161
|
+
constexpr nullopt_t nullopt_holder<Dummy>::instance_;
|
162
|
+
}
|
163
|
+
static constexpr const nullopt_t &nullopt = internal::nullopt_holder<void>::instance_;
|
164
|
+
|
165
|
+
#else
|
166
|
+
namespace internal {
|
167
|
+
template <class> struct nullopt_holder {
|
168
|
+
static const nullopt_t instance_;
|
169
|
+
};
|
170
|
+
template<class Dummy>
|
171
|
+
const nullopt_t nullopt_holder<Dummy>::instance_ = nullopt_t(0);
|
172
|
+
}
|
173
|
+
static const nullopt_t &nullopt = internal::nullopt_holder<void>::instance_;
|
174
|
+
|
175
|
+
#endif
|
176
|
+
|
177
|
+
template<class T>
|
178
|
+
class Optional FLATBUFFERS_FINAL_CLASS {
|
179
|
+
// Non-scalar 'T' would extremely complicated Optional<T>.
|
180
|
+
// Use is_scalar<T> checking because flatbuffers flatbuffers::is_arithmetic<T>
|
181
|
+
// isn't implemented.
|
182
|
+
static_assert(flatbuffers::is_scalar<T>::value, "unexpected type T");
|
183
|
+
|
184
|
+
public:
|
185
|
+
~Optional() {}
|
186
|
+
|
187
|
+
FLATBUFFERS_CONSTEXPR_CPP11 Optional() FLATBUFFERS_NOEXCEPT
|
188
|
+
: value_(), has_value_(false) {}
|
189
|
+
|
190
|
+
FLATBUFFERS_CONSTEXPR_CPP11 Optional(nullopt_t) FLATBUFFERS_NOEXCEPT
|
191
|
+
: value_(), has_value_(false) {}
|
192
|
+
|
193
|
+
FLATBUFFERS_CONSTEXPR_CPP11 Optional(T val) FLATBUFFERS_NOEXCEPT
|
194
|
+
: value_(val), has_value_(true) {}
|
195
|
+
|
196
|
+
FLATBUFFERS_CONSTEXPR_CPP11 Optional(const Optional &other) FLATBUFFERS_NOEXCEPT
|
197
|
+
: value_(other.value_), has_value_(other.has_value_) {}
|
198
|
+
|
199
|
+
FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(const Optional &other) FLATBUFFERS_NOEXCEPT {
|
200
|
+
value_ = other.value_;
|
201
|
+
has_value_ = other.has_value_;
|
202
|
+
return *this;
|
203
|
+
}
|
204
|
+
|
205
|
+
FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(nullopt_t) FLATBUFFERS_NOEXCEPT {
|
206
|
+
value_ = T();
|
207
|
+
has_value_ = false;
|
208
|
+
return *this;
|
209
|
+
}
|
210
|
+
|
211
|
+
FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(T val) FLATBUFFERS_NOEXCEPT {
|
212
|
+
value_ = val;
|
213
|
+
has_value_ = true;
|
214
|
+
return *this;
|
215
|
+
}
|
216
|
+
|
217
|
+
void reset() FLATBUFFERS_NOEXCEPT {
|
218
|
+
*this = nullopt;
|
219
|
+
}
|
220
|
+
|
221
|
+
void swap(Optional &other) FLATBUFFERS_NOEXCEPT {
|
222
|
+
std::swap(value_, other.value_);
|
223
|
+
std::swap(has_value_, other.has_value_);
|
224
|
+
}
|
225
|
+
|
226
|
+
FLATBUFFERS_CONSTEXPR_CPP11 FLATBUFFERS_EXPLICIT_CPP11 operator bool() const FLATBUFFERS_NOEXCEPT {
|
227
|
+
return has_value_;
|
228
|
+
}
|
229
|
+
|
230
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool has_value() const FLATBUFFERS_NOEXCEPT {
|
231
|
+
return has_value_;
|
232
|
+
}
|
233
|
+
|
234
|
+
FLATBUFFERS_CONSTEXPR_CPP11 const T& operator*() const FLATBUFFERS_NOEXCEPT {
|
235
|
+
return value_;
|
236
|
+
}
|
237
|
+
|
238
|
+
const T& value() const {
|
239
|
+
FLATBUFFERS_ASSERT(has_value());
|
240
|
+
return value_;
|
241
|
+
}
|
242
|
+
|
243
|
+
T value_or(T default_value) const FLATBUFFERS_NOEXCEPT {
|
244
|
+
return has_value() ? value_ : default_value;
|
245
|
+
}
|
246
|
+
|
247
|
+
private:
|
248
|
+
T value_;
|
249
|
+
bool has_value_;
|
250
|
+
};
|
251
|
+
|
252
|
+
template<class T>
|
253
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& opt, nullopt_t) FLATBUFFERS_NOEXCEPT {
|
254
|
+
return !opt;
|
255
|
+
}
|
256
|
+
template<class T>
|
257
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(nullopt_t, const Optional<T>& opt) FLATBUFFERS_NOEXCEPT {
|
258
|
+
return !opt;
|
259
|
+
}
|
260
|
+
|
261
|
+
template<class T, class U>
|
262
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const U& rhs) FLATBUFFERS_NOEXCEPT {
|
263
|
+
return static_cast<bool>(lhs) && (*lhs == rhs);
|
264
|
+
}
|
265
|
+
|
266
|
+
template<class T, class U>
|
267
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const T& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT {
|
268
|
+
return static_cast<bool>(rhs) && (lhs == *rhs);
|
269
|
+
}
|
270
|
+
|
271
|
+
template<class T, class U>
|
272
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT {
|
273
|
+
return static_cast<bool>(lhs) != static_cast<bool>(rhs)
|
274
|
+
? false
|
275
|
+
: !static_cast<bool>(lhs) ? false : (*lhs == *rhs);
|
276
|
+
}
|
277
|
+
#endif // FLATBUFFERS_USE_STD_OPTIONAL
|
278
|
+
|
279
|
+
|
280
|
+
// Very limited and naive partial implementation of C++20 std::span<T,Extent>.
|
281
|
+
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
282
|
+
inline constexpr std::size_t dynamic_extent = std::dynamic_extent;
|
283
|
+
template<class T, std::size_t Extent = std::dynamic_extent>
|
284
|
+
using span = std::span<T, Extent>;
|
285
|
+
|
286
|
+
#else // !defined(FLATBUFFERS_USE_STD_SPAN)
|
287
|
+
FLATBUFFERS_CONSTEXPR std::size_t dynamic_extent = static_cast<std::size_t>(-1);
|
288
|
+
|
289
|
+
// Exclude this code if MSVC2010 or non-STL Android is active.
|
290
|
+
// The non-STL Android doesn't have `std::is_convertible` required for SFINAE.
|
291
|
+
#if !defined(FLATBUFFERS_SPAN_MINIMAL)
|
292
|
+
namespace internal {
|
293
|
+
// This is SFINAE helper class for checking of a common condition:
|
294
|
+
// > This overload only participates in overload resolution
|
295
|
+
// > Check whether a pointer to an array of From can be converted
|
296
|
+
// > to a pointer to an array of To.
|
297
|
+
// This helper is used for checking of 'From -> const From'.
|
298
|
+
template<class To, std::size_t Extent, class From, std::size_t N>
|
299
|
+
struct is_span_convertible {
|
300
|
+
using type =
|
301
|
+
typename std::conditional<std::is_convertible<From (*)[], To (*)[]>::value
|
302
|
+
&& (Extent == dynamic_extent || N == Extent),
|
303
|
+
int, void>::type;
|
304
|
+
};
|
305
|
+
|
306
|
+
template<typename T>
|
307
|
+
struct SpanIterator {
|
308
|
+
// TODO: upgrade to std::random_access_iterator_tag.
|
309
|
+
using iterator_category = std::forward_iterator_tag;
|
310
|
+
using difference_type = std::ptrdiff_t;
|
311
|
+
using value_type = typename std::remove_cv<T>::type;
|
312
|
+
using reference = T&;
|
313
|
+
using pointer = T*;
|
314
|
+
|
315
|
+
// Convince MSVC compiler that this iterator is trusted (it is verified).
|
316
|
+
#ifdef _MSC_VER
|
317
|
+
using _Unchecked_type = pointer;
|
318
|
+
#endif // _MSC_VER
|
319
|
+
|
320
|
+
SpanIterator(pointer ptr) : ptr_(ptr) {}
|
321
|
+
reference operator*() const { return *ptr_; }
|
322
|
+
pointer operator->() { return ptr_; }
|
323
|
+
SpanIterator& operator++() { ptr_++; return *this; }
|
324
|
+
SpanIterator operator++(int) { auto tmp = *this; ++(*this); return tmp; }
|
325
|
+
|
326
|
+
friend bool operator== (const SpanIterator& lhs, const SpanIterator& rhs) { return lhs.ptr_ == rhs.ptr_; }
|
327
|
+
friend bool operator!= (const SpanIterator& lhs, const SpanIterator& rhs) { return lhs.ptr_ != rhs.ptr_; }
|
328
|
+
|
329
|
+
private:
|
330
|
+
pointer ptr_;
|
331
|
+
};
|
332
|
+
} // namespace internal
|
333
|
+
#endif // !defined(FLATBUFFERS_SPAN_MINIMAL)
|
334
|
+
|
335
|
+
// T - element type; must be a complete type that is not an abstract
|
336
|
+
// class type.
|
337
|
+
// Extent - the number of elements in the sequence, or dynamic.
|
338
|
+
template<class T, std::size_t Extent = dynamic_extent>
|
339
|
+
class span FLATBUFFERS_FINAL_CLASS {
|
340
|
+
public:
|
341
|
+
typedef T element_type;
|
342
|
+
typedef T& reference;
|
343
|
+
typedef const T& const_reference;
|
344
|
+
typedef T* pointer;
|
345
|
+
typedef const T* const_pointer;
|
346
|
+
typedef std::size_t size_type;
|
347
|
+
|
348
|
+
static FLATBUFFERS_CONSTEXPR size_type extent = Extent;
|
349
|
+
|
350
|
+
// Returns the number of elements in the span.
|
351
|
+
FLATBUFFERS_CONSTEXPR_CPP11 size_type size() const FLATBUFFERS_NOEXCEPT {
|
352
|
+
return count_;
|
353
|
+
}
|
354
|
+
|
355
|
+
// Returns the size of the sequence in bytes.
|
356
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
357
|
+
size_type size_bytes() const FLATBUFFERS_NOEXCEPT {
|
358
|
+
return size() * sizeof(element_type);
|
359
|
+
}
|
360
|
+
|
361
|
+
// Checks if the span is empty.
|
362
|
+
FLATBUFFERS_CONSTEXPR_CPP11 bool empty() const FLATBUFFERS_NOEXCEPT {
|
363
|
+
return size() == 0;
|
364
|
+
}
|
365
|
+
|
366
|
+
// Returns a pointer to the beginning of the sequence.
|
367
|
+
FLATBUFFERS_CONSTEXPR_CPP11 pointer data() const FLATBUFFERS_NOEXCEPT {
|
368
|
+
return data_;
|
369
|
+
}
|
370
|
+
|
371
|
+
#if !defined(FLATBUFFERS_SPAN_MINIMAL)
|
372
|
+
using Iterator = internal::SpanIterator<T>;
|
373
|
+
|
374
|
+
Iterator begin() const { return Iterator(data()); }
|
375
|
+
Iterator end() const { return Iterator(data() + size()); }
|
376
|
+
#endif
|
377
|
+
|
378
|
+
// Returns a reference to the idx-th element of the sequence.
|
379
|
+
// The behavior is undefined if the idx is greater than or equal to size().
|
380
|
+
FLATBUFFERS_CONSTEXPR_CPP11 reference operator[](size_type idx) const {
|
381
|
+
return data()[idx];
|
382
|
+
}
|
383
|
+
|
384
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span(const span &other) FLATBUFFERS_NOEXCEPT
|
385
|
+
: data_(other.data_), count_(other.count_) {}
|
386
|
+
|
387
|
+
FLATBUFFERS_CONSTEXPR_CPP14 span &operator=(const span &other)
|
388
|
+
FLATBUFFERS_NOEXCEPT {
|
389
|
+
data_ = other.data_;
|
390
|
+
count_ = other.count_;
|
391
|
+
}
|
392
|
+
|
393
|
+
// Limited implementation of
|
394
|
+
// `template <class It> constexpr std::span(It first, size_type count);`.
|
395
|
+
//
|
396
|
+
// Constructs a span that is a view over the range [first, first + count);
|
397
|
+
// the resulting span has: data() == first and size() == count.
|
398
|
+
// The behavior is undefined if [first, first + count) is not a valid range,
|
399
|
+
// or if (extent != flatbuffers::dynamic_extent && count != extent).
|
400
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
401
|
+
explicit span(pointer first, size_type count) FLATBUFFERS_NOEXCEPT
|
402
|
+
: data_ (Extent == dynamic_extent ? first : (Extent == count ? first : nullptr)),
|
403
|
+
count_(Extent == dynamic_extent ? count : (Extent == count ? Extent : 0)) {
|
404
|
+
// Make span empty if the count argument is incompatible with span<T,N>.
|
405
|
+
}
|
406
|
+
|
407
|
+
// Exclude this code if MSVC2010 is active. The MSVC2010 isn't C++11
|
408
|
+
// compliant, it doesn't support default template arguments for functions.
|
409
|
+
#if defined(FLATBUFFERS_SPAN_MINIMAL)
|
410
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr),
|
411
|
+
count_(0) {
|
412
|
+
static_assert(extent == 0 || extent == dynamic_extent, "invalid span");
|
413
|
+
}
|
414
|
+
|
415
|
+
#else
|
416
|
+
// Constructs an empty span whose data() == nullptr and size() == 0.
|
417
|
+
// This overload only participates in overload resolution if
|
418
|
+
// extent == 0 || extent == flatbuffers::dynamic_extent.
|
419
|
+
// A dummy template argument N is need dependency for SFINAE.
|
420
|
+
template<std::size_t N = 0,
|
421
|
+
typename internal::is_span_convertible<element_type, Extent, element_type, (N - N)>::type = 0>
|
422
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr),
|
423
|
+
count_(0) {
|
424
|
+
static_assert(extent == 0 || extent == dynamic_extent, "invalid span");
|
425
|
+
}
|
426
|
+
|
427
|
+
// Constructs a span that is a view over the array arr; the resulting span
|
428
|
+
// has size() == N and data() == std::data(arr). These overloads only
|
429
|
+
// participate in overload resolution if
|
430
|
+
// extent == std::dynamic_extent || N == extent is true and
|
431
|
+
// std::remove_pointer_t<decltype(std::data(arr))>(*)[]
|
432
|
+
// is convertible to element_type (*)[].
|
433
|
+
template<std::size_t N,
|
434
|
+
typename internal::is_span_convertible<element_type, Extent, element_type, N>::type = 0>
|
435
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span(element_type (&arr)[N]) FLATBUFFERS_NOEXCEPT
|
436
|
+
: data_(arr), count_(N) {}
|
437
|
+
|
438
|
+
template<class U, std::size_t N,
|
439
|
+
typename internal::is_span_convertible<element_type, Extent, U, N>::type = 0>
|
440
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT
|
441
|
+
: data_(arr.data()), count_(N) {}
|
442
|
+
|
443
|
+
//template<class U, std::size_t N,
|
444
|
+
// int = 0>
|
445
|
+
//FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT
|
446
|
+
// : data_(arr.data()), count_(N) {}
|
447
|
+
|
448
|
+
template<class U, std::size_t N,
|
449
|
+
typename internal::is_span_convertible<element_type, Extent, U, N>::type = 0>
|
450
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span(const std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT
|
451
|
+
: data_(arr.data()), count_(N) {}
|
452
|
+
|
453
|
+
// Converting constructor from another span s;
|
454
|
+
// the resulting span has size() == s.size() and data() == s.data().
|
455
|
+
// This overload only participates in overload resolution
|
456
|
+
// if extent == std::dynamic_extent || N == extent is true and U (*)[]
|
457
|
+
// is convertible to element_type (*)[].
|
458
|
+
template<class U, std::size_t N,
|
459
|
+
typename internal::is_span_convertible<element_type, Extent, U, N>::type = 0>
|
460
|
+
FLATBUFFERS_CONSTEXPR_CPP11 span(const flatbuffers::span<U, N> &s) FLATBUFFERS_NOEXCEPT
|
461
|
+
: span(s.data(), s.size()) {
|
462
|
+
}
|
463
|
+
|
464
|
+
#endif // !defined(FLATBUFFERS_SPAN_MINIMAL)
|
465
|
+
|
466
|
+
private:
|
467
|
+
// This is a naive implementation with 'count_' member even if (Extent != dynamic_extent).
|
468
|
+
pointer const data_;
|
469
|
+
size_type count_;
|
470
|
+
};
|
471
|
+
#endif // defined(FLATBUFFERS_USE_STD_SPAN)
|
472
|
+
|
473
|
+
#if !defined(FLATBUFFERS_SPAN_MINIMAL)
|
474
|
+
template<class ElementType, std::size_t Extent>
|
475
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
476
|
+
flatbuffers::span<ElementType, Extent> make_span(ElementType(&arr)[Extent]) FLATBUFFERS_NOEXCEPT {
|
477
|
+
return span<ElementType, Extent>(arr);
|
478
|
+
}
|
479
|
+
|
480
|
+
template<class ElementType, std::size_t Extent>
|
481
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
482
|
+
flatbuffers::span<const ElementType, Extent> make_span(const ElementType(&arr)[Extent]) FLATBUFFERS_NOEXCEPT {
|
483
|
+
return span<const ElementType, Extent>(arr);
|
484
|
+
}
|
485
|
+
|
486
|
+
template<class ElementType, std::size_t Extent>
|
487
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
488
|
+
flatbuffers::span<ElementType, Extent> make_span(std::array<ElementType, Extent> &arr) FLATBUFFERS_NOEXCEPT {
|
489
|
+
return span<ElementType, Extent>(arr);
|
490
|
+
}
|
491
|
+
|
492
|
+
template<class ElementType, std::size_t Extent>
|
493
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
494
|
+
flatbuffers::span<const ElementType, Extent> make_span(const std::array<ElementType, Extent> &arr) FLATBUFFERS_NOEXCEPT {
|
495
|
+
return span<const ElementType, Extent>(arr);
|
496
|
+
}
|
497
|
+
|
498
|
+
template<class ElementType, std::size_t Extent>
|
499
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
500
|
+
flatbuffers::span<ElementType, dynamic_extent> make_span(ElementType *first, std::size_t count) FLATBUFFERS_NOEXCEPT {
|
501
|
+
return span<ElementType, dynamic_extent>(first, count);
|
502
|
+
}
|
503
|
+
|
504
|
+
template<class ElementType, std::size_t Extent>
|
505
|
+
FLATBUFFERS_CONSTEXPR_CPP11
|
506
|
+
flatbuffers::span<const ElementType, dynamic_extent> make_span(const ElementType *first, std::size_t count) FLATBUFFERS_NOEXCEPT {
|
507
|
+
return span<const ElementType, dynamic_extent>(first, count);
|
508
|
+
}
|
509
|
+
#endif // !defined(FLATBUFFERS_SPAN_MINIMAL)
|
510
|
+
|
511
|
+
} // namespace flatbuffers
|
512
|
+
|
513
|
+
#endif // FLATBUFFERS_STL_EMULATION_H_
|