VRS
A file format for sensor data.
Loading...
Searching...
No Matches
LegacyFormatsProvider.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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#pragma once
18
19#include <mutex>
20
21#include <vrs/RecordFormat.h>
22#include <vrs/VrsExport.h>
23
24namespace vrs {
25
26using std::map;
27using std::recursive_mutex;
28using std::string;
29using std::unique_ptr;
30using std::vector;
31
32class DataLayout;
33class LegacyFormatsProvider;
34
36class VRS_API RecordFormatRegistrar {
38 RecordFormatRegistrar() = default;
39
40 public:
41 // Public interface
42
45 static void registerProvider(unique_ptr<LegacyFormatsProvider> provider);
46
47 // VRS internal interface
48
51 static RecordFormatRegistrar& getInstance();
52
57 void getLegacyRecordFormats(RecordableTypeId id, RecordFormatMap& outFormats);
58
62 unique_ptr<DataLayout> getLegacyDataLayout(const ContentBlockId& blockId);
63
73 unique_ptr<DataLayout> getLatestDataLayout(RecordableTypeId typeId, Record::Type recordType);
74
77 bool addLegacyRecordFormat(
78 RecordableTypeId typeId,
79 Record::Type recordType,
80 uint32_t formatVersion,
81 const RecordFormat& format,
82 const vector<const DataLayout*>& layouts);
83
84 private:
85 const map<string, string>& getLegacyRegistry(RecordableTypeId typeId);
86 void registerProviderInternal(unique_ptr<LegacyFormatsProvider> provider);
87
88 recursive_mutex mutex_;
89 vector<unique_ptr<LegacyFormatsProvider>> providers_;
90 map<RecordableTypeId, map<string, string>> legacyRecordFormats_;
91};
92
101 public:
102 LegacyFormatsProvider() = default;
103 virtual ~LegacyFormatsProvider();
105 LegacyFormatsProvider& operator=(const LegacyFormatsProvider&) = delete;
107 LegacyFormatsProvider& operator=(LegacyFormatsProvider&&) = delete;
108
113
114 protected:
128 RecordableTypeId typeId,
129 Record::Type recordType,
130 uint32_t formatVersion,
131 const RecordFormat& format,
132 const vector<const DataLayout*>& layouts) {
133 return RecordFormatRegistrar::getInstance().addLegacyRecordFormat(
134 typeId, recordType, formatVersion, format, layouts);
135 }
136};
137
138} // namespace vrs
Helper to identify a particular content block within a file.
Definition RecordFormat.h:644
System to inject record format & data layout definitions for files created without.
Definition LegacyFormatsProvider.h:100
virtual void registerLegacyRecordFormats(RecordableTypeId typeId)=0
static bool addLegacyRecordFormat(RecordableTypeId typeId, Record::Type recordType, uint32_t formatVersion, const RecordFormat &format, const vector< const DataLayout * > &layouts)
Definition LegacyFormatsProvider.h:127
Description of the format of a VRS record as a succession of typed blocks of content.
Definition RecordFormat.h:688
Utility class to handle record format registry manipulations.
Definition LegacyFormatsProvider.h:36
Type
Definition Record.h:91
Definition Compressor.cpp:113
map< pair< Record::Type, uint32_t >, RecordFormat > RecordFormatMap
Map a pair of record type/format version to a record format, for a particular stream.
Definition RecordFormat.h:634
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:51