RTI Recording Service Version 7.7.0
EStorageFormat.hpp
1/*
2 * (c) Copyright, Real-Time Innovations, 2016-.
3 * All rights reserved.
4 * No duplications, whole or partial, manual or electronic, may be made
5 * without express written permission. Any such copies, or
6 * revisions thereof, must display this notice unaltered.
7 * This code contains trade secrets of Real-Time Innovations, Inc.
8 */
9
10#ifndef HPP_RTI_RECORDING_STORAGE_ESTORAGEFORMAT_HPP_
11#define HPP_RTI_RECORDING_STORAGE_ESTORAGEFORMAT_HPP_
12
13#include <stdint.h>
14
15#include "reda/reda_string.h"
16#include "dds_c/dds_c_infrastructure.h"
17
18#include "dds/core/Exception.hpp"
19
20namespace rti { namespace recording { namespace storage {
21
22class EStorageFormat {
23public:
24
25 static const DDS_DataRepresentationId_t INVALID_REPRESENTATION =
26 static_cast<DDS_DataRepresentationId_t>(
27 RTI_CDR_ENCAPSULATION_ID_INVALID);
28
29 static const EStorageFormat XCDR() {
30 static const EStorageFormat XCDR(
31 0,
32 "XCDR",
33 DDS_XCDR_DATA_REPRESENTATION);
34 return XCDR;
35 }
36 static const EStorageFormat XCDR2() {
37 static const EStorageFormat XCDR2(
38 1,
39 "XCDR2",
40 DDS_XCDR2_DATA_REPRESENTATION);
41 return XCDR2;
42 }
43 static const EStorageFormat XCDR_AUTO() {
44 static const EStorageFormat XCDR_AUTO(
45 2,
46 "XCDR_AUTO",
47 DDS_AUTO_DATA_REPRESENTATION);
48 return XCDR_AUTO;
49 }
50 static const EStorageFormat JSON_SQLITE() {
51 static const EStorageFormat JSON_SQLITE(
52 3,
53 "JSON_SQLITE",
54 INVALID_REPRESENTATION);
55 return JSON_SQLITE;
56 }
60 static const EStorageFormat DESERIALIZED() {
61 static const EStorageFormat DESERIALIZED(
62 4,
63 "DESERIALIZED",
64 INVALID_REPRESENTATION);
65 return DESERIALIZED;
66 }
67
68 static EStorageFormat from_string_ignore_case(const std::string& value)
69 {
70 if (REDAString_iCompare(
71 value.c_str(),
72 XCDR().enum_value().c_str()) == 0) {
73 return XCDR();
74 } else if (REDAString_iCompare(
75 value.c_str(),
76 XCDR2().enum_value().c_str()) == 0) {
77 return XCDR2();
78 } else if (REDAString_iCompare(
79 value.c_str(),
80 XCDR_AUTO().enum_value().c_str()) == 0) {
81 return XCDR_AUTO();
82 } else if (REDAString_iCompare(
83 value.c_str(),
84 JSON_SQLITE().enum_value().c_str()) == 0) {
85 return JSON_SQLITE();
86 } else {
87 throw dds::core::UnsupportedError(
88 "Unrecognized DB Format value, must be one of "
89 "{XCDR,XCDR2,XCDR_AUTO,JSON_SQLITE}");
90 }
91 }
92
93 EStorageFormat(const EStorageFormat& other)
94 : enum_value_(other.enum_value_),
95 enum_string_(other.enum_string_),
96 data_rep_id_(other.data_rep_id_){}
97
98 void operator =(const EStorageFormat& other)
99 {
100 enum_value_ = other.enum_value_;
101 enum_string_ = other.enum_string_;
102 data_rep_id_ = other.data_rep_id_;
103 }
104
105 bool operator ==(const EStorageFormat& other) const
106 {
107 return enum_value_ == other.enum_value_;
108 }
109
110 bool operator !=(const EStorageFormat& other) const
111 {
112 return enum_value_ != other.enum_value_;
113 }
114
115 uint32_t value() const { return enum_value_; }
116
117 const std::string& enum_value() const { return enum_string_; }
118
123 DDS_DataRepresentationId_t data_representation() const
124 {
125 return data_rep_id_;
126 }
127
128private:
129 uint32_t enum_value_;
130 std::string enum_string_;
131 DDS_DataRepresentationId_t data_rep_id_;
132
133 EStorageFormat(
134 const uint32_t value,
135 const std::string& enum_string,
136 const DDS_DataRepresentationId_t rep_id) :
137 enum_value_(value),
138 enum_string_(enum_string),
139 data_rep_id_(rep_id) {}
140
141};
142
143} } } /* namespace rti::recording::storage */
144
145#endif /* HPP_RTI_RECORDING_STORAGE_ESTORAGEFORMAT_HPP_ */
The RTI namespace.
Definition: RecordingServiceImpl.hpp:22