VRS
A file format for sensor data.
Loading...
Searching...
No Matches
DataPieceStringMap.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#ifndef DATA_PIECES_STRING_MAP_H
20#define DATA_PIECES_STRING_MAP_H
21
22#ifndef DATA_PIECES_H
23#include "DataPieces.h"
24#endif
25
26namespace vrs {
27
28using std::ostream;
29using std::string;
30using std::vector;
31
36template <typename T>
38 public:
40 explicit DataPieceStringMap(const string& label)
41 : DataPiece(label, DataPieceType::StringMap, DataLayout::kVariableSize) {}
44 explicit DataPieceStringMap(const MakerBundle& bundle);
45
48 const string& getElementTypeName() const override {
49 return vrs::getTypeName<T>();
50 }
53 size_t getVariableSize() const override;
58 size_t collectVariableData(int8_t* data, size_t bufferSize) override;
59
62 const map<string, T>& stagedValues() const {
63 return stagedValues_;
64 }
67 map<string, T>& stagedValues() {
68 return stagedValues_;
69 }
72 void stage(const map<string, T>& values) {
73 stagedValues_ = values;
74 }
77 void stage(map<string, T>&& values) {
78 stagedValues_ = std::move(values);
79 }
80
84 bool get(map<string, T>& outValues) const;
85
88 const map<string, T>& getDefault() const {
89 return defaultValues_;
90 }
93 void setDefault(const map<string, T>& values) {
94 defaultValues_ = values;
95 }
98 void setDefault(map<string, T>&& values) {
99 defaultValues_ = std::move(values);
100 }
101
104 bool isAvailable() const override {
105 size_t count = 0;
106 return layout_.getVarData<int8_t>(offset_, count) != nullptr;
107 }
108
113 void print(ostream& out, const string& indent) const override;
118 void printCompact(ostream& out, const string& indent) const override;
119
124 bool isSame(const DataPiece* rhs) const override;
125
129 void serialize(JsonWrapper& jsonWrapper, const JsonFormatProfileSpec& profile) override;
130
133 bool stageCurrentValue() override {
134 return get(stagedValues());
135 }
136
140 unique_ptr<DataPiece> clone() const override {
141 auto other = std::make_unique<DataPieceStringMap<T>>(getLabel());
142 other->tags_ = tags_;
143 other->required_ = required_;
144 other->defaultValues_ = defaultValues_;
145 return other;
146 }
147
148 protected:
149 bool stageFrom(const DataPiece* original) override {
150 const DataPieceStringMap<T>* origMap = reinterpret_cast<const DataPieceStringMap<T>*>(original);
151 return origMap->get(stagedValues_);
152 }
153
154 private:
155 map<string, T> stagedValues_; // values to write to disk
156 map<string, T> defaultValues_;
157};
158
159} // namespace vrs
160
161#endif // DATA_PIECES_STRING_MAP_H
The DataLayout class describes the data stored inside a DataLayoutContentBlock.
Definition DataLayout.h:191
vector< int8_t > & getVarData()
Definition DataLayout.h:242
Abstract class representing a piece of information part of a DataLayout.
Definition DataPieces.h:40
const string & getLabel() const
Definition DataPieces.h:76
DataPiece map container, with string keys and values of type T.
Definition DataPieceStringMap.h:37
void setDefault(map< string, T > &&values)
Definition DataPieceStringMap.h:98
void printCompact(ostream &out, const string &indent) const override
Definition DataLayout.cpp:1628
unique_ptr< DataPiece > clone() const override
Definition DataPieceStringMap.h:140
void stage(map< string, T > &&values)
Definition DataPieceStringMap.h:77
void print(ostream &out, const string &indent) const override
Definition DataLayout.cpp:1594
bool stageCurrentValue() override
Definition DataPieceStringMap.h:133
bool isAvailable() const override
Definition DataPieceStringMap.h:104
size_t getVariableSize() const override
Definition DataLayout.cpp:1549
DataPieceStringMap(const string &label)
Definition DataPieceStringMap.h:40
bool stageFrom(const DataPiece *original) override
Stage value from another piece known to be of the same type.
Definition DataPieceStringMap.h:149
const string & getElementTypeName() const override
Definition DataPieceStringMap.h:48
void stage(const map< string, T > &values)
Definition DataPieceStringMap.h:72
map< string, T > & stagedValues()
Definition DataPieceStringMap.h:67
bool isSame(const DataPiece *rhs) const override
Definition DataLayout.cpp:1656
size_t collectVariableData(int8_t *data, size_t bufferSize) override
Definition DataLayout.cpp:1558
const map< string, T > & stagedValues() const
Definition DataPieceStringMap.h:62
void serialize(JsonWrapper &jsonWrapper, const JsonFormatProfileSpec &profile) override
Definition DataLayout.cpp:1665
bool get(map< string, T > &outValues) const
Definition DataLayout.cpp:1570
const map< string, T > & getDefault() const
Definition DataPieceStringMap.h:88
void setDefault(const map< string, T > &values)
Definition DataPieceStringMap.h:93
Definition AsyncDiskFileChunk.hpp:49
DataPieceType
Specifier for a type of DataPiece.
Definition DataLayout.h:57
@ StringMap
Map with string keys, and T values.
When printing out a DataLayout as json, this class allows to specify what should be included in the g...
Definition DataLayout.h:84