VRS
A file format for sensor data.
Loading...
Searching...
No Matches
FileHandlerFactory.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 <map>
20#include <memory>
21#include <mutex>
22#include <string>
23
24#include <vrs/ForwardDefinitions.h>
25#include <vrs/VrsExport.h>
26
27namespace vrs {
28
29using std::map;
30using std::mutex;
31using std::string;
32using std::unique_ptr;
33
36class VRS_API FileHandlerFactory {
37 public:
38 static FileHandlerFactory& getInstance();
39
41 void registerFileDelegator(const string& name, unique_ptr<FileDelegator>&& delegator);
42 void unregisterFileDelegator(const string& name);
43
46 void registerExtraDelegator(
47 const string& extraName,
48 const string& extraValue,
49 unique_ptr<FileDelegator>&& delegator);
50 void unregisterExtraDelegator(const string& extraName, const string& extraValue);
51 FileDelegator* getExtraDelegator(const FileSpec& fileSpec);
52 FileDelegator* getExtraDelegator(const string& extraName, const string& extraValue);
53
55 void registerFileHandler(unique_ptr<FileHandler>&& fileHandler);
56 void unregisterFileHandler(const string& fileHandlerName);
57 unique_ptr<FileHandler> getFileHandler(const string& name);
58 FileDelegator* getFileDelegator(const string& name);
59
81 virtual int delegateOpen(const string& path, unique_ptr<FileHandler>& outNewDelegate);
82 virtual int delegateOpen(const FileSpec& fileSpec, unique_ptr<FileHandler>& outNewDelegate);
83
87 virtual int parseUri(FileSpec& inOutFileSpec, size_t colonIndex);
88
89 protected:
91 virtual ~FileHandlerFactory() = default;
92
93 private:
94 mutex mutex_;
95 map<string, unique_ptr<FileDelegator>> fileDelegatorMap_;
96 map<string, unique_ptr<FileHandler>> fileHandlerMap_;
97 map<string, map<string, unique_ptr<FileDelegator>>> extraDelegatorMap_;
98};
99
100} // namespace vrs
Class to abstract the delegate file open operation for VRS file.
Definition FileDelegator.h:32
A factory system for FileHandlers, allowing the runtime registration & usage of custom FileHandler im...
Definition FileHandlerFactory.h:36
Definition Compressor.cpp:113
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:42