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
36// Exported base class meant to be subclassed, for example FakeFileHandlerFactory in tests.
37class VRS_API FileHandlerFactory { // NOLINT(cppcoreguidelines-virtual-class-destructor)
38 public:
39 static FileHandlerFactory& getInstance();
40
42 void registerFileDelegator(const string& name, unique_ptr<FileDelegator>&& delegator);
43 void unregisterFileDelegator(const string& name);
44
47 void registerExtraDelegator(
48 const string& extraName,
49 const string& extraValue,
50 unique_ptr<FileDelegator>&& delegator);
51 void unregisterExtraDelegator(const string& extraName, const string& extraValue);
52 FileDelegator* getExtraDelegator(const FileSpec& fileSpec);
53 FileDelegator* getExtraDelegator(const string& extraName, const string& extraValue);
54
57 void registerFileHandler(unique_ptr<FileHandler>&& fileHandler);
58
62 void registerFileHandler(const string& name, unique_ptr<FileHandler>&& fileHandler);
63 void unregisterFileHandler(const string& fileHandlerName);
64 unique_ptr<FileHandler> getFileHandler(const string& name);
65 FileDelegator* getFileDelegator(const string& name);
66
88 virtual int delegateOpen(const string& path, unique_ptr<FileHandler>& outNewDelegate);
89 virtual int delegateOpen(const FileSpec& fileSpec, unique_ptr<FileHandler>& outNewDelegate);
90
94 virtual int parseUri(FileSpec& inOutFileSpec, size_t colonIndex);
95
96 protected:
98 virtual ~FileHandlerFactory() = default;
99
100 private:
101 mutex mutex_;
102 map<string, unique_ptr<FileDelegator>> fileDelegatorMap_;
103 map<string, unique_ptr<FileHandler>> fileHandlerMap_;
104 map<string, map<string, unique_ptr<FileDelegator>>> extraDelegatorMap_;
105};
106
107} // 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:37
Definition Compressor.cpp:119
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:43