VRS
A file format for sensor data.
Loading...
Searching...
No Matches
WriteFileHandler.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 <vrs/os/CompilerAttributes.h>
20
21#include "ErrorCode.h"
22#include "FileHandler.h"
23
24namespace vrs {
25
26using std::string;
27using std::vector;
28
47 public:
48 WriteFileHandler() = default;
49
51 static unique_ptr<WriteFileHandler> make(const string& fileHandlerName);
52
56 virtual int create(const FileSpec& spec) {
57 return spec.chunks.empty() ? INVALID_FILE_SPEC : create(spec.chunks.front(), spec.extras);
58 }
59
64 virtual int create(const string& newFilePath, const map<string, string>& options = {}) = 0;
65
70 virtual int createSplitFile(const FileSpec& spec, const string& initialFilePath) {
71 // create the (first) user record chunk
72 if (spec.chunks.size() == 1) {
73 return create(spec.chunks.front() + "_1", spec.extras);
74 } else {
75 return create(initialFilePath, spec.extras);
76 }
77 }
78
83 virtual void addSplitHead(MAYBE_UNUSED FileSpec& inOutSpec) {}
84
87 virtual bool reopenForUpdatesSupported() const = 0;
88
92 virtual int reopenForUpdates() = 0;
93
96 bool isReadOnly() const override = 0;
97
103 virtual int write(const void* buffer, size_t length) = 0;
105 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
106 int write(const T& object) {
107 return write(&object, sizeof(object));
108 }
109
115 virtual int overwrite(const void* buffer, size_t length) = 0;
117 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
118 int overwrite(const T& object) {
119 return overwrite(&object, sizeof(object));
120 }
121
125 virtual int addChunk() = 0;
128 virtual int truncate() = 0;
130 virtual bool getCurrentChunk(string& outChunkPath, size_t& outChunkIndex) const = 0;
131};
132
133} // namespace vrs
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:73
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:46
int write(const T &object)
Helper for trivially copyable objects.
Definition WriteFileHandler.h:106
virtual void addSplitHead(MAYBE_UNUSED FileSpec &inOutSpec)
Definition WriteFileHandler.h:83
virtual bool reopenForUpdatesSupported() const =0
virtual int overwrite(const void *buffer, size_t length)=0
int overwrite(const T &object)
Helper for trivially copyable objects.
Definition WriteFileHandler.h:118
virtual int truncate()=0
bool isReadOnly() const override=0
virtual int reopenForUpdates()=0
virtual int write(const void *buffer, size_t length)=0
virtual int create(const string &newFilePath, const map< string, string > &options={})=0
virtual int addChunk()=0
static unique_ptr< WriteFileHandler > make(const string &fileHandlerName)
Create a new WriteFileHandler from a name.
Definition FileHandlerFactory.cpp:214
virtual int create(const FileSpec &spec)
Definition WriteFileHandler.h:56
virtual bool getCurrentChunk(string &outChunkPath, size_t &outChunkIndex) const =0
Get the path of the current chunk, or an empty string if no chunk is open.
virtual int createSplitFile(const FileSpec &spec, const string &initialFilePath)
Definition WriteFileHandler.h:70
Definition Compressor.cpp:113
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:37