MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
etag.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
14#pragma once
15
16#include <cstdint>
17#include <sstream>
18#include <string>
19#include <vector>
20namespace mdf {
21
29enum class ETagDataType : uint8_t {
30 StringType = 0,
31 DecimalType = 1,
32 IntegerType = 2,
33 FloatType = 3,
34 BooleanType = 4,
35 DateType = 5,
36 TimeType = 6,
37 DateTimeType = 7
38};
39
51class ETag {
52 public:
59 void Name(const std::string& name) { name_ = name; }
60
65 [[nodiscard]] const std::string& Name() const { return name_; }
66
71 void Description(const std::string& desc) { desc_ = desc; }
72
77 [[nodiscard]] const std::string& Description() const { return desc_; }
78
83 void Unit(const std::string& unit) { unit_ = unit; }
84
89 [[nodiscard]] const std::string& Unit() const { return unit_; }
90
96 void UnitRef(const std::string& unit_ref) { unit_ref_ = unit_ref; }
97
102 [[nodiscard]] const std::string& UnitRef() const { return unit_ref_; }
103
105 [[nodiscard]] ETagDataType DataType() const;
106
114 void Type(const std::string& type) { type_ = type; }
115
121 [[nodiscard]] const std::string& Type() const { return type_; }
122
128 void Language(const std::string& language) { language_ = language; }
129
134 [[nodiscard]] const std::string& Language() const { return language_; }
135
140 void ReadOnly(bool read_only) { read_only_ = read_only; }
141
146 [[nodiscard]] bool ReadOnly() const { return read_only_; }
147
154 void CreatorIndex(int index) { creator_index_ = index; }
155
160 [[nodiscard]] int CreatorIndex() const { return creator_index_; }
161
167 template <typename T>
168 void Value(const T& value);
169
175 template <typename T>
176 [[nodiscard]] T Value() const;
177
184 void AddTag(const ETag& tag);
185
190 [[nodiscard]] const std::vector<ETag>& TreeList() const { return tree_list_; }
191
192 private:
193 std::string name_;
194 std::string desc_;
195 std::string unit_;
196 std::string unit_ref_;
197 std::string type_;
198 std::string language_;
199 std::string value_;
200 bool read_only_ = false;
201 int creator_index_ = -1;
202
203 std::vector<ETag> tree_list_;
204};
205
206template <typename T>
207void ETag::Value(const T& value) {
208 std::ostringstream temp;
209 temp << value;
210 value_ = temp.str();
211}
212
217template <>
218void ETag::Value(const bool& value);
219
220template <typename T>
221T ETag::Value() const {
222 T temp_value = {};
223 if (!value_.empty()) {
224 std::istringstream temp(value_);
225 temp >> temp_value;
226 }
227 return temp_value;
228}
229
234template <>
235[[nodiscard]] bool ETag::Value() const;
236
241template <>
242[[nodiscard]] std::string ETag::Value() const;
243} // namespace mdf
Helper class for meta data items in an MDF file.
Definition etag.h:51
void UnitRef(const std::string &unit_ref)
Reference unit.
Definition etag.h:96
void CreatorIndex(int index)
Index to FH block.
Definition etag.h:154
bool ReadOnly() const
Indicates that the value is read-only.
Definition etag.h:146
ETagDataType DataType() const
Retuns the data type.
int CreatorIndex() const
Index to file history block.
Definition etag.h:160
const std::string & Type() const
Data type of the value.
Definition etag.h:121
const std::string & Unit() const
Unit of value.
Definition etag.h:89
T Value() const
Returns the tag value.
Definition etag.h:221
void Language(const std::string &language)
Language of the value.
Definition etag.h:128
const std::string & Name() const
Returns the name attribute.
Definition etag.h:65
void AddTag(const ETag &tag)
Adds a tag and define this to be a list of tags (tree).
const std::vector< ETag > & TreeList() const
Return a list of tags.
Definition etag.h:190
void Description(const std::string &desc)
Optional attribute in an e-tag or tree-tag.
Definition etag.h:71
void ReadOnly(bool read_only)
The value is read-only.
Definition etag.h:140
void Type(const std::string &type)
Data type of the value.
Definition etag.h:114
const std::string & UnitRef() const
Reference unit.
Definition etag.h:102
const std::string & Description() const
Description text.
Definition etag.h:77
void DataType(ETagDataType type)
Sets the data type.
void Unit(const std::string &unit)
Optional unit of the value in a nn e-tag..
Definition etag.h:83
const std::string & Language() const
Language code.
Definition etag.h:134
void Name(const std::string &name)
Sets the name attribute in an e-tag or a tree-tag.
Definition etag.h:59
Main namespace for the MDF library.
Definition canmessage.h:17
ETagDataType
The e-tag may optional have a data type below. The value in the XML file is of course string but the ...
Definition etag.h:29
@ TimeType
Time value ISO.
@ DecimalType
Decimal value (use float instead)
@ DateType
Date value according to ISO (YYYY-MM-DD).
@ BooleanType
Boolean tru/false value.
@ DateTimeType
Date and Time ISO string (YYYY-MM-DD hh:mm:ss)
@ FloatType
Floating point value.
@ IntegerType
Integer value.
@ StringType
Text value.