BLPAPI C++ 3.26.6
Loading...
Searching...
No Matches
blpapi_messageformatter.h
Go to the documentation of this file.
1/* Copyright 2019. Bloomberg Finance L.P.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions: The above
9 * copyright notice and this permission notice shall be included in all copies
10 * or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18 * IN THE SOFTWARE.
19 */
20
37
38#ifndef INCLUDED_BLPAPI_MESSAGEFORMATTER
39#define INCLUDED_BLPAPI_MESSAGEFORMATTER
40
78
79#include <blpapi_call.h>
80#include <blpapi_defs.h>
81#include <blpapi_event.h>
82#include <blpapi_topic.h>
83#include <blpapi_types.h>
84
85#include <stddef.h>
86
87#ifdef __cplusplus
88extern "C" {
89#endif
90
92
95
113BLPAPI_EXPORT
114int blpapi_MessageFormatter_setValueBool(blpapi_MessageFormatter_t *formatter,
115 const blpapi_Name_t *typeName,
116 blpapi_Bool_t value);
117
135BLPAPI_EXPORT
136int blpapi_MessageFormatter_setValueChar(blpapi_MessageFormatter_t *formatter,
137 const blpapi_Name_t *typeName,
138 char value);
139
157BLPAPI_EXPORT
158int blpapi_MessageFormatter_setValueInt32(blpapi_MessageFormatter_t *formatter,
159 const blpapi_Name_t *typeName,
160 blpapi_Int32_t value);
161
179BLPAPI_EXPORT
180int blpapi_MessageFormatter_setValueInt64(blpapi_MessageFormatter_t *formatter,
181 const blpapi_Name_t *typeName,
182 blpapi_Int64_t value);
183
201BLPAPI_EXPORT
202int blpapi_MessageFormatter_setValueFloat32(
203 blpapi_MessageFormatter_t *formatter,
204 const blpapi_Name_t *typeName,
205 blpapi_Float32_t value);
206
224BLPAPI_EXPORT
225int blpapi_MessageFormatter_setValueFloat64(
226 blpapi_MessageFormatter_t *formatter,
227 const blpapi_Name_t *typeName,
228 blpapi_Float64_t value);
229
248BLPAPI_EXPORT
249int blpapi_MessageFormatter_setValueDatetime(
250 blpapi_MessageFormatter_t *formatter,
251 const blpapi_Name_t *typeName,
252 const blpapi_Datetime_t *value);
253
273BLPAPI_EXPORT
274int blpapi_MessageFormatter_setValueHighPrecisionDatetime(
275 blpapi_MessageFormatter_t *formatter,
276 const blpapi_Name_t *typeName,
277 const blpapi_HighPrecisionDatetime_t *value);
278
298BLPAPI_EXPORT
299int blpapi_MessageFormatter_setValueString(
300 blpapi_MessageFormatter_t *formatter,
301 const blpapi_Name_t *typeName,
302 const char *value);
303
323BLPAPI_EXPORT
324int blpapi_MessageFormatter_setValueFromName(
325 blpapi_MessageFormatter_t *formatter,
326 const blpapi_Name_t *typeName,
327 const blpapi_Name_t *value);
328
349BLPAPI_EXPORT
350int blpapi_MessageFormatter_setValueBytes(blpapi_MessageFormatter_t *formatter,
351 const blpapi_Name_t *typeName,
352 const char *value,
353 size_t length);
354
372BLPAPI_EXPORT
373int blpapi_MessageFormatter_setValueNull(
374 blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName);
375
398BLPAPI_EXPORT
399int blpapi_MessageFormatter_pushElement(
400 blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName);
401
417BLPAPI_EXPORT
418int blpapi_MessageFormatter_popElement(blpapi_MessageFormatter_t *formatter);
419
434BLPAPI_EXPORT
435int blpapi_MessageFormatter_appendValueBool(
436 blpapi_MessageFormatter_t *formatter, blpapi_Bool_t value);
437
452BLPAPI_EXPORT
453int blpapi_MessageFormatter_appendValueChar(
454 blpapi_MessageFormatter_t *formatter, char value);
455
470BLPAPI_EXPORT
471int blpapi_MessageFormatter_appendValueInt32(
472 blpapi_MessageFormatter_t *formatter, blpapi_Int32_t value);
473
488BLPAPI_EXPORT
489int blpapi_MessageFormatter_appendValueInt64(
490 blpapi_MessageFormatter_t *formatter, blpapi_Int64_t value);
491
507BLPAPI_EXPORT
508int blpapi_MessageFormatter_appendValueFloat32(
509 blpapi_MessageFormatter_t *formatter, blpapi_Float32_t value);
510
526BLPAPI_EXPORT
527int blpapi_MessageFormatter_appendValueFloat64(
528 blpapi_MessageFormatter_t *formatter, blpapi_Float64_t value);
529
546BLPAPI_EXPORT
547int blpapi_MessageFormatter_appendValueDatetime(
548 blpapi_MessageFormatter_t *formatter, const blpapi_Datetime_t *value);
549
567BLPAPI_EXPORT
568int blpapi_MessageFormatter_appendValueHighPrecisionDatetime(
569 blpapi_MessageFormatter_t *formatter,
570 const blpapi_HighPrecisionDatetime_t *value);
571
588BLPAPI_EXPORT
589int blpapi_MessageFormatter_appendValueString(
590 blpapi_MessageFormatter_t *formatter, const char *value);
591
607BLPAPI_EXPORT
608int blpapi_MessageFormatter_appendValueFromName(
609 blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *value);
610
626BLPAPI_EXPORT
627int blpapi_MessageFormatter_appendElement(
628 blpapi_MessageFormatter_t *formatter);
629
649BLPAPI_EXPORT
650int blpapi_MessageFormatter_FormatMessageJson(
651 blpapi_MessageFormatter_t *formatter, const char *message);
652
672BLPAPI_EXPORT
673int blpapi_MessageFormatter_FormatMessageXml(
674 blpapi_MessageFormatter_t *formatter, const char *message);
675
693BLPAPI_EXPORT
694int blpapi_MessageFormatter_copy(blpapi_MessageFormatter_t **formatter,
695 const blpapi_MessageFormatter_t *original);
696
711BLPAPI_EXPORT
712int blpapi_MessageFormatter_assign(
713 blpapi_MessageFormatter_t **lhs, const blpapi_MessageFormatter_t *rhs);
714
729BLPAPI_EXPORT
730int blpapi_MessageFormatter_destroy(blpapi_MessageFormatter_t *formatter);
731
748BLPAPI_EXPORT
749int blpapi_MessageFormatter_getElementDefinition(
750 blpapi_MessageFormatter_t *formatter,
751 blpapi_SchemaElementDefinition_t **definition);
752
769BLPAPI_EXPORT
770int blpapi_MessageFormatter_getElement(
771 blpapi_MessageFormatter_t *formatter, blpapi_Element_t **element);
772
775
776#ifdef __cplusplus
777} // extern "C"
778
779#include <string>
780#include <type_traits>
781
782namespace BloombergLP {
783namespace blpapi {
790
791namespace test {
792
809
810 private:
811 blpapi_MessageFormatter_t *d_handle;
812
813 public:
814 // CREATORS
815 explicit MessageFormatter(blpapi_MessageFormatter_t *handle);
820
821 MessageFormatter(const MessageFormatter& original);
826
832
833 // MANIPULATORS
838
839 void setElement(const Name& name, bool value);
847
848 void setElement(const Name& name, char value);
856
857 void setElement(const Name& name, Int32 value);
865
866 void setElement(const Name& name, Int64 value);
874
875 void setElement(const Name& name, Float32 value);
883
884 void setElement(const Name& name, Float64 value);
892
893 void setElement(const Name& name, const Datetime& value);
901
902 void setElement(const Name& name, const Datetime::HighPrecision& value);
910
911 void setElement(const Name& name, const char *value);
922
923 void setElement(const Name& name, const std::string& value);
932
933 void setElement(const Name& name, const Name& value);
941
942 void setElement(const Name& name, const void *value, size_t length);
954
955 template <typename BYTES,
956 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
957 = true>
958 void setElement(const Name& name, const BYTES& value);
971
972 void setElementNull(const Name& name);
981
982 void pushElement(const Name& name);
1003
1004 void popElement();
1013
1014 void appendValue(bool value);
1021
1022 void appendValue(char value);
1029
1030 void appendValue(Int32 value);
1037
1038 void appendValue(Int64 value);
1045
1046 void appendValue(Float32 value);
1053
1054 void appendValue(Float64 value);
1061
1062 void appendValue(const Datetime& value);
1069
1070 void appendValue(const Datetime::HighPrecision& value);
1077
1078 void appendValue(const char *value);
1085
1086 void appendValue(const std::string& value);
1095
1096 void appendValue(const Name& value);
1103
1104 void appendElement();
1111
1112 void formatMessageJson(const char *message);
1119
1120 void formatMessageXml(const char *message);
1127
1128 // ACCESSORS
1130 blpapi_MessageFormatter_t *impl() const;
1136};
1137
1140
1141// ============================================================================
1142// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
1143// ============================================================================
1144
1145// ----------------------
1146// class MessageFormatter
1147// ----------------------
1148
1149inline MessageFormatter::MessageFormatter(blpapi_MessageFormatter_t *handle)
1150 : d_handle(handle)
1151{
1152}
1153
1155{
1156 if (d_handle) {
1157 BLPAPI_CALL_UNCHECKED(blpapi_MessageFormatter_destroy)(d_handle);
1158 }
1159}
1160
1162{
1163 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageFormatter_copy)(
1164 &d_handle, original.impl()));
1165}
1166
1168 const MessageFormatter& rhs)
1169{
1170 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageFormatter_assign)(
1171 &d_handle, rhs.impl()));
1172 return *this;
1173}
1174
1175inline void MessageFormatter::setElement(const Name& name, bool value)
1176{
1178 BLPAPI_CALL(blpapi_MessageFormatter_setValueBool)(
1179 d_handle, name.impl(), value));
1180}
1181
1182inline void MessageFormatter::setElement(const Name& name, char value)
1183{
1185 BLPAPI_CALL(blpapi_MessageFormatter_setValueChar)(
1186 d_handle, name.impl(), value));
1187}
1188
1189inline void MessageFormatter::setElement(const Name& name, Int32 value)
1190{
1192 BLPAPI_CALL(blpapi_MessageFormatter_setValueInt32)(
1193 d_handle, name.impl(), value));
1194}
1195
1196inline void MessageFormatter::setElement(const Name& name, Int64 value)
1197{
1199 BLPAPI_CALL(blpapi_MessageFormatter_setValueInt64)(
1200 d_handle, name.impl(), value));
1201}
1202
1203inline void MessageFormatter::setElement(const Name& name, Float32 value)
1204{
1206 BLPAPI_CALL(blpapi_MessageFormatter_setValueFloat32)(
1207 d_handle, name.impl(), value));
1208}
1209
1210inline void MessageFormatter::setElement(const Name& name, Float64 value)
1211{
1213 BLPAPI_CALL(blpapi_MessageFormatter_setValueFloat64)(
1214 d_handle, name.impl(), value));
1215}
1216
1218 const Name& name, const Datetime& value)
1219{
1221 BLPAPI_CALL(blpapi_MessageFormatter_setValueDatetime)(
1222 d_handle, name.impl(), &value.rawValue()));
1223}
1224
1226 const Name& name, const Datetime::HighPrecision& value)
1227{
1229 BLPAPI_CALL(blpapi_MessageFormatter_setValueHighPrecisionDatetime)(
1230 d_handle, name.impl(), &value));
1231}
1232
1233inline void MessageFormatter::setElement(const Name& name, const char *value)
1234{
1236 BLPAPI_CALL(blpapi_MessageFormatter_setValueString)(
1237 d_handle, name.impl(), value));
1238}
1239
1241 const Name& name, const std::string& value)
1242{
1243 setElement(name, value.c_str());
1244}
1245
1246inline void MessageFormatter::setElement(const Name& name, const Name& value)
1247{
1249 BLPAPI_CALL(blpapi_MessageFormatter_setValueFromName)(
1250 d_handle, name.impl(), value.impl()));
1251}
1252
1254 const Name& name, const void *value, size_t length)
1255{
1257 BLPAPI_CALL(blpapi_MessageFormatter_setValueBytes)(d_handle,
1258 name.impl(),
1259 reinterpret_cast<const char *>(value),
1260 length));
1261}
1262
1263template <typename BYTES,
1264 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1265inline void MessageFormatter::setElement(const Name& name, const BYTES& value)
1266{
1267 setElement(name, value.data(), value.size());
1268}
1269
1271{
1272 ExceptionUtil::throwOnError(BLPAPI_CALL(
1273 blpapi_MessageFormatter_setValueNull)(d_handle, name.impl()));
1274}
1275
1276inline void MessageFormatter::pushElement(const Name& name)
1277{
1278 ExceptionUtil::throwOnError(BLPAPI_CALL(
1279 blpapi_MessageFormatter_pushElement)(d_handle, name.impl()));
1280}
1281
1283{
1285 BLPAPI_CALL(blpapi_MessageFormatter_popElement)(d_handle));
1286}
1287
1288inline void MessageFormatter::appendValue(bool value)
1289{
1290 ExceptionUtil::throwOnError(BLPAPI_CALL(
1291 blpapi_MessageFormatter_appendValueBool)(d_handle, value));
1292}
1293
1294inline void MessageFormatter::appendValue(char value)
1295{
1296 ExceptionUtil::throwOnError(BLPAPI_CALL(
1297 blpapi_MessageFormatter_appendValueChar)(d_handle, value));
1298}
1299
1301{
1302 ExceptionUtil::throwOnError(BLPAPI_CALL(
1303 blpapi_MessageFormatter_appendValueInt32)(d_handle, value));
1304}
1305
1307{
1308 ExceptionUtil::throwOnError(BLPAPI_CALL(
1309 blpapi_MessageFormatter_appendValueInt64)(d_handle, value));
1310}
1311
1313{
1314 ExceptionUtil::throwOnError(BLPAPI_CALL(
1315 blpapi_MessageFormatter_appendValueFloat32)(d_handle, value));
1316}
1317
1319{
1320 ExceptionUtil::throwOnError(BLPAPI_CALL(
1321 blpapi_MessageFormatter_appendValueFloat64)(d_handle, value));
1322}
1323
1325{
1327 BLPAPI_CALL(blpapi_MessageFormatter_appendValueDatetime)(
1328 d_handle, &value.rawValue()));
1329}
1330
1332{
1333 ExceptionUtil::throwOnError(BLPAPI_CALL(
1334 blpapi_MessageFormatter_appendValueHighPrecisionDatetime)(
1335 d_handle, &value));
1336}
1337
1338inline void MessageFormatter::appendValue(const char *value)
1339{
1340 ExceptionUtil::throwOnError(BLPAPI_CALL(
1341 blpapi_MessageFormatter_appendValueString)(d_handle, value));
1342}
1343
1344inline void MessageFormatter::appendValue(const std::string& value)
1345{
1346 appendValue(value.c_str());
1347}
1348
1349inline void MessageFormatter::appendValue(const Name& value)
1350{
1352 BLPAPI_CALL(blpapi_MessageFormatter_appendValueFromName)(
1353 d_handle, value.impl()));
1354}
1355
1357{
1359 BLPAPI_CALL(blpapi_MessageFormatter_appendElement)(d_handle));
1360}
1361
1363inline blpapi_MessageFormatter_t *MessageFormatter::impl() const
1364{
1365 return d_handle;
1366}
1368
1369inline void MessageFormatter::formatMessageJson(const char *message)
1370{
1371 ExceptionUtil::throwOnError(BLPAPI_CALL(
1372 blpapi_MessageFormatter_FormatMessageJson)(d_handle, message));
1373}
1374
1375inline void MessageFormatter::formatMessageXml(const char *message)
1376{
1377 ExceptionUtil::throwOnError(BLPAPI_CALL(
1378 blpapi_MessageFormatter_FormatMessageXml)(d_handle, message));
1379}
1380
1381} // close namespace test
1382
1383// *Deprecated*
1384// Following typedef is provided for backwards compatibility. It will be
1385// removed in a future release.
1387
1388} // close namespace blpapi
1389} // close namespace BloombergLP
1390
1391#endif // #ifdef __cplusplus
1392#endif // #ifndef INCLUDED_BLPAPI_MESSAGEFORMATTER
Provide functions for dispatchtbl.
Common definitions used by the library.
A component which defines events related operations.
Provide representation of a Topic.
Provide BLPAPI types.
Definition blpapi_datetime.h:312
blpapi_HighPrecisionDatetime_t HighPrecision
Definition blpapi_datetime.h:338
blpapi_Datetime_t & rawValue()
Definition blpapi_datetime.h:2018
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Definition blpapi_name.h:228
Definition blpapi_messageformatter.h:808
void formatMessageXml(const char *message)
Definition blpapi_messageformatter.h:1375
void appendValue(bool value)
Definition blpapi_messageformatter.h:1288
void setElementNull(const Name &name)
Definition blpapi_messageformatter.h:1270
void setElement(const Name &name, bool value)
Definition blpapi_messageformatter.h:1175
void formatMessageJson(const char *message)
Definition blpapi_messageformatter.h:1369
MessageFormatter(blpapi_MessageFormatter_t *handle)
Definition blpapi_messageformatter.h:1149
void appendElement()
Definition blpapi_messageformatter.h:1356
void popElement()
Definition blpapi_messageformatter.h:1282
~MessageFormatter()
Definition blpapi_messageformatter.h:1154
void pushElement(const Name &name)
Definition blpapi_messageformatter.h:1276
MessageFormatter & operator=(const MessageFormatter &rhs)
Definition blpapi_messageformatter.h:1167
test::MessageFormatter MessageFormatter
Definition blpapi_messageformatter.h:1386
Definition blpapi_messageformatter.h:791
Definition blpapi_abstractsession.h:452
blpapi_Float64_t Float64
64-bit IEEE 754 float type alias.
Definition blpapi_types.h:559
blpapi_Float32_t Float32
32-bit IEEE 754 float type alias.
Definition blpapi_types.h:558
blpapi_Int64_t Int64
64-bit signed integer type alias.
Definition blpapi_types.h:556
blpapi_Int32_t Int32
32-bit signed integer type alias.
Definition blpapi_types.h:554
Definition blpapi_abstractsession.h:451