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/ErrorCode.h>
20#include <vrs/FileHandler.h>
21#include <vrs/VrsExport.h>
22#include <vrs/os/CompilerAttributes.h>
23
24namespace vrs {
25
43class VRS_API WriteFileHandler : public FileHandler {
44 public:
45 WriteFileHandler() = default;
46
48 static unique_ptr<WriteFileHandler> make(const string& fileHandlerName);
49
53 virtual int create(const FileSpec& spec) {
54 return spec.chunks.empty() ? INVALID_FILE_SPEC : create(spec.chunks.front(), spec.extras);
55 }
56
61 virtual int create(const string& newFilePath, const FileSpec::Extras& options = {}) = 0;
62
67 virtual int createSplitFile(const FileSpec& spec, const string& initialFilePath) {
68 // create the (first) user record chunk
69 if (spec.chunks.size() == 1) {
70 return create(spec.chunks.front() + "_1", spec.extras);
71 } else {
72 return create(initialFilePath, spec.extras);
73 }
74 }
75
80 virtual void addSplitHead(MAYBE_UNUSED FileSpec& inOutSpec) {}
81
84 virtual bool reopenForUpdatesSupported() const = 0;
85
89 virtual int reopenForUpdates() = 0;
90
93 bool isReadOnly() const override = 0;
94
100 virtual int write(const void* buffer, size_t length) = 0;
102 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
103 int write(const T& object) {
104 return write(&object, sizeof(object));
105 }
106
112 virtual int overwrite(const void* buffer, size_t length) = 0;
114 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
115 int overwrite(const T& object) {
116 return overwrite(&object, sizeof(object));
117 }
118
122 virtual int addChunk() = 0;
125 virtual int truncate() = 0;
127 virtual bool getCurrentChunk(string& outChunkPath, size_t& outChunkIndex) const = 0;
128};
129
130} // namespace vrs
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:75
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:43
int write(const T &object)
Helper for trivially copyable objects.
Definition WriteFileHandler.h:103
virtual void addSplitHead(MAYBE_UNUSED FileSpec &inOutSpec)
Definition WriteFileHandler.h:80
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:115
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 addChunk()=0
virtual int create(const string &newFilePath, const FileSpec::Extras &options={})=0
virtual int create(const FileSpec &spec)
Definition WriteFileHandler.h:53
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:67
Definition Compressor.cpp:113
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:42
map< string, string, std::less<> > Extras
Definition FileSpec.h:45