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 "FileHandler.h"
22
23namespace vrs {
24
25using std::string;
26using std::vector;
27
46 public:
47 WriteFileHandler() = default;
48
50 static unique_ptr<WriteFileHandler> make(const string& fileHandlerName);
51
55 virtual int create(const FileSpec& spec) {
56 return spec.chunks.empty() ? INVALID_FILE_SPEC : create(spec.chunks.front(), spec.extras);
57 }
58
63 virtual int create(const string& newFilePath, const map<string, string>& options = {}) = 0;
64
69 virtual int createSplitFile(const FileSpec& spec, const string& initialFilePath) {
70 // create the (first) user record chunk
71 if (spec.chunks.size() == 1) {
72 return create(spec.chunks.front() + "_1", spec.extras);
73 } else {
74 return create(initialFilePath, spec.extras);
75 }
76 }
77
82 virtual void addSplitHead(MAYBE_UNUSED FileSpec& inOutSpec) {}
83
86 virtual bool reopenForUpdatesSupported() const = 0;
87
91 virtual int reopenForUpdates() = 0;
92
95 bool isReadOnly() const override = 0;
96
102 virtual int write(const void* buffer, size_t length) = 0;
104 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
105 int write(const T& object) {
106 return write(&object, sizeof(object));
107 }
108
114 virtual int overwrite(const void* buffer, size_t length) = 0;
116 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
117 int overwrite(const T& object) {
118 return overwrite(&object, sizeof(object));
119 }
120
124 virtual int addChunk() = 0;
127 virtual int truncate() = 0;
129 virtual bool getCurrentChunk(string& outChunkPath, size_t& outChunkIndex) const = 0;
130};
131
132} // namespace vrs
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:71
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:45
int write(const T &object)
Helper for trivially copyable objects.
Definition WriteFileHandler.h:105
virtual void addSplitHead(MAYBE_UNUSED FileSpec &inOutSpec)
Definition WriteFileHandler.h:82
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:117
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:213
virtual int create(const FileSpec &spec)
Definition WriteFileHandler.h:55
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:69
Definition AsyncDiskFileChunk.hpp:49
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:37