BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_MESSAGEFORMATTER
37#define INCLUDED_BLPAPI_MESSAGEFORMATTER
38
79
80#include <blpapi_call.h>
81#include <blpapi_defs.h>
82#include <blpapi_event.h>
83#include <blpapi_topic.h>
84#include <blpapi_types.h>
85
86#include <stddef.h>
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
93
96
97BLPAPI_EXPORT
98int blpapi_MessageFormatter_setValueBool(blpapi_MessageFormatter_t *formatter,
99 const blpapi_Name_t *typeName,
100 blpapi_Bool_t value);
101
102BLPAPI_EXPORT
103int blpapi_MessageFormatter_setValueChar(blpapi_MessageFormatter_t *formatter,
104 const blpapi_Name_t *typeName,
105 char value);
106
107BLPAPI_EXPORT
108int blpapi_MessageFormatter_setValueInt32(blpapi_MessageFormatter_t *formatter,
109 const blpapi_Name_t *typeName,
110 blpapi_Int32_t value);
111
112BLPAPI_EXPORT
113int blpapi_MessageFormatter_setValueInt64(blpapi_MessageFormatter_t *formatter,
114 const blpapi_Name_t *typeName,
115 blpapi_Int64_t value);
116
117BLPAPI_EXPORT
118int blpapi_MessageFormatter_setValueFloat32(
119 blpapi_MessageFormatter_t *formatter,
120 const blpapi_Name_t *typeName,
121 blpapi_Float32_t value);
122
123BLPAPI_EXPORT
124int blpapi_MessageFormatter_setValueFloat64(
125 blpapi_MessageFormatter_t *formatter,
126 const blpapi_Name_t *typeName,
127 blpapi_Float64_t value);
128
129BLPAPI_EXPORT
130int blpapi_MessageFormatter_setValueDatetime(
131 blpapi_MessageFormatter_t *formatter,
132 const blpapi_Name_t *typeName,
133 const blpapi_Datetime_t *value);
134
135BLPAPI_EXPORT
136int blpapi_MessageFormatter_setValueHighPrecisionDatetime(
137 blpapi_MessageFormatter_t *formatter,
138 const blpapi_Name_t *typeName,
139 const blpapi_HighPrecisionDatetime_t *value);
140
141BLPAPI_EXPORT
142int blpapi_MessageFormatter_setValueString(
143 blpapi_MessageFormatter_t *formatter,
144 const blpapi_Name_t *typeName,
145 const char *value);
146
147BLPAPI_EXPORT
148int blpapi_MessageFormatter_setValueFromName(
149 blpapi_MessageFormatter_t *formatter,
150 const blpapi_Name_t *typeName,
151 const blpapi_Name_t *value);
152
153BLPAPI_EXPORT
154int blpapi_MessageFormatter_setValueBytes(blpapi_MessageFormatter_t *formatter,
155 const blpapi_Name_t *typeName,
156 const char *value,
157 size_t length);
158
159BLPAPI_EXPORT
160int blpapi_MessageFormatter_setValueNull(
161 blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName);
162
163BLPAPI_EXPORT
164int blpapi_MessageFormatter_pushElement(
165 blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName);
166
167BLPAPI_EXPORT
168int blpapi_MessageFormatter_popElement(blpapi_MessageFormatter_t *formatter);
169
170BLPAPI_EXPORT
171int blpapi_MessageFormatter_appendValueBool(
172 blpapi_MessageFormatter_t *formatter, blpapi_Bool_t value);
173
174BLPAPI_EXPORT
175int blpapi_MessageFormatter_appendValueChar(
176 blpapi_MessageFormatter_t *formatter, char value);
177
178BLPAPI_EXPORT
179int blpapi_MessageFormatter_appendValueInt32(
180 blpapi_MessageFormatter_t *formatter, blpapi_Int32_t value);
181
182BLPAPI_EXPORT
183int blpapi_MessageFormatter_appendValueInt64(
184 blpapi_MessageFormatter_t *formatter, blpapi_Int64_t value);
185
186BLPAPI_EXPORT
187int blpapi_MessageFormatter_appendValueFloat32(
188 blpapi_MessageFormatter_t *formatter, blpapi_Float32_t value);
189
190BLPAPI_EXPORT
191int blpapi_MessageFormatter_appendValueFloat64(
192 blpapi_MessageFormatter_t *formatter, blpapi_Float64_t value);
193
194BLPAPI_EXPORT
195int blpapi_MessageFormatter_appendValueDatetime(
196 blpapi_MessageFormatter_t *formatter, const blpapi_Datetime_t *value);
197
198BLPAPI_EXPORT
199int blpapi_MessageFormatter_appendValueHighPrecisionDatetime(
200 blpapi_MessageFormatter_t *formatter,
201 const blpapi_HighPrecisionDatetime_t *value);
202
203BLPAPI_EXPORT
204int blpapi_MessageFormatter_appendValueString(
205 blpapi_MessageFormatter_t *formatter, const char *value);
206
207BLPAPI_EXPORT
208int blpapi_MessageFormatter_appendValueFromName(
209 blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *value);
210
211BLPAPI_EXPORT
212int blpapi_MessageFormatter_appendElement(
213 blpapi_MessageFormatter_t *formatter);
214
215BLPAPI_EXPORT
216int blpapi_MessageFormatter_FormatMessageJson(
217 blpapi_MessageFormatter_t *formatter, const char *message);
218
219BLPAPI_EXPORT
220int blpapi_MessageFormatter_FormatMessageXml(
221 blpapi_MessageFormatter_t *formatter, const char *message);
222
223BLPAPI_EXPORT
224int blpapi_MessageFormatter_copy(blpapi_MessageFormatter_t **formatter,
225 const blpapi_MessageFormatter_t *original);
226
227BLPAPI_EXPORT
228int blpapi_MessageFormatter_assign(
229 blpapi_MessageFormatter_t **lhs, const blpapi_MessageFormatter_t *rhs);
230
231BLPAPI_EXPORT
232int blpapi_MessageFormatter_destroy(blpapi_MessageFormatter_t *formatter);
233
234BLPAPI_EXPORT
235int blpapi_MessageFormatter_getElementDefinition(
236 blpapi_MessageFormatter_t *formatter,
237 blpapi_SchemaElementDefinition_t **definition);
238
239BLPAPI_EXPORT
240int blpapi_MessageFormatter_getElement(
241 blpapi_MessageFormatter_t *formatter, blpapi_Element_t **element);
242
245
246#ifdef __cplusplus
247} // extern "C"
248
249#include <string>
250#include <type_traits>
251
258
259namespace BloombergLP {
260namespace blpapi {
261namespace test {
262
279
280 private:
281 blpapi_MessageFormatter_t *d_handle;
282
283 public:
284 // CREATORS
285 explicit MessageFormatter(blpapi_MessageFormatter_t *handle);
290
291 MessageFormatter(const MessageFormatter& original);
296
302
303 // MANIPULATORS
308
309 void setElement(const Name& name, bool value);
317
318 void setElement(const Name& name, char value);
326
327 void setElement(const Name& name, Int32 value);
335
336 void setElement(const Name& name, Int64 value);
344
345 void setElement(const Name& name, Float32 value);
353
354 void setElement(const Name& name, Float64 value);
362
363 void setElement(const Name& name, const Datetime& value);
371
372 void setElement(const Name& name, const Datetime::HighPrecision& value);
380
381 void setElement(const Name& name, const char *value);
392
393 void setElement(const Name& name, const std::string& value);
402
403 void setElement(const Name& name, const Name& value);
411
412 void setElement(const Name& name, const void *value, size_t length);
424
425 template <typename BYTES,
426 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
427 = true>
428 void setElement(const Name& name, const BYTES& value);
442
443 void setElementNull(const Name& name);
452
453 void pushElement(const Name& name);
474
475 void popElement();
484
485 void appendValue(bool value);
492
493 void appendValue(char value);
500
501 void appendValue(Int32 value);
508
509 void appendValue(Int64 value);
516
517 void appendValue(Float32 value);
524
525 void appendValue(Float64 value);
532
533 void appendValue(const Datetime& value);
540
541 void appendValue(const Datetime::HighPrecision& value);
548
549 void appendValue(const char *value);
556
557 void appendValue(const std::string& value);
566
567 void appendValue(const Name& value);
574
575 void appendElement();
582
583 void formatMessageJson(const char *message);
590
591 void formatMessageXml(const char *message);
598
599 // ACCESSORS
600 blpapi_MessageFormatter_t *impl() const;
605};
606
609
610// ============================================================================
611// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
612// ============================================================================
613
614// ----------------------
615// class MessageFormatter
616// ----------------------
617
618inline MessageFormatter::MessageFormatter(blpapi_MessageFormatter_t *handle)
619 : d_handle(handle)
620{
621}
622
624{
625 if (d_handle) {
626 BLPAPI_CALL_UNCHECKED(blpapi_MessageFormatter_destroy)(d_handle);
627 }
628}
629
631{
632 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageFormatter_copy)(
633 &d_handle, original.impl()));
634}
635
637 const MessageFormatter& rhs)
638{
639 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageFormatter_assign)(
640 &d_handle, rhs.impl()));
641 return *this;
642}
643
644inline void MessageFormatter::setElement(const Name& name, bool value)
645{
647 BLPAPI_CALL(blpapi_MessageFormatter_setValueBool)(
648 d_handle, name.impl(), value));
649}
650
651inline void MessageFormatter::setElement(const Name& name, char value)
652{
654 BLPAPI_CALL(blpapi_MessageFormatter_setValueChar)(
655 d_handle, name.impl(), value));
656}
657
658inline void MessageFormatter::setElement(const Name& name, Int32 value)
659{
661 BLPAPI_CALL(blpapi_MessageFormatter_setValueInt32)(
662 d_handle, name.impl(), value));
663}
664
665inline void MessageFormatter::setElement(const Name& name, Int64 value)
666{
668 BLPAPI_CALL(blpapi_MessageFormatter_setValueInt64)(
669 d_handle, name.impl(), value));
670}
671
672inline void MessageFormatter::setElement(const Name& name, Float32 value)
673{
675 BLPAPI_CALL(blpapi_MessageFormatter_setValueFloat32)(
676 d_handle, name.impl(), value));
677}
678
679inline void MessageFormatter::setElement(const Name& name, Float64 value)
680{
682 BLPAPI_CALL(blpapi_MessageFormatter_setValueFloat64)(
683 d_handle, name.impl(), value));
684}
685
687 const Name& name, const Datetime& value)
688{
690 BLPAPI_CALL(blpapi_MessageFormatter_setValueDatetime)(
691 d_handle, name.impl(), &value.rawValue()));
692}
693
695 const Name& name, const Datetime::HighPrecision& value)
696{
698 BLPAPI_CALL(blpapi_MessageFormatter_setValueHighPrecisionDatetime)(
699 d_handle, name.impl(), &value));
700}
701
702inline void MessageFormatter::setElement(const Name& name, const char *value)
703{
705 BLPAPI_CALL(blpapi_MessageFormatter_setValueString)(
706 d_handle, name.impl(), value));
707}
708
710 const Name& name, const std::string& value)
711{
712 setElement(name, value.c_str());
713}
714
715inline void MessageFormatter::setElement(const Name& name, const Name& value)
716{
718 BLPAPI_CALL(blpapi_MessageFormatter_setValueFromName)(
719 d_handle, name.impl(), value.impl()));
720}
721
723 const Name& name, const void *value, size_t length)
724{
726 BLPAPI_CALL(blpapi_MessageFormatter_setValueBytes)(d_handle,
727 name.impl(),
728 reinterpret_cast<const char *>(value),
729 length));
730}
731
732template <typename BYTES,
733 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
734inline void MessageFormatter::setElement(const Name& name, const BYTES& value)
735{
736 setElement(name, value.data(), value.size());
737}
738
740{
742 blpapi_MessageFormatter_setValueNull)(d_handle, name.impl()));
743}
744
745inline void MessageFormatter::pushElement(const Name& name)
746{
748 blpapi_MessageFormatter_pushElement)(d_handle, name.impl()));
749}
750
752{
754 BLPAPI_CALL(blpapi_MessageFormatter_popElement)(d_handle));
755}
756
757inline void MessageFormatter::appendValue(bool value)
758{
760 blpapi_MessageFormatter_appendValueBool)(d_handle, value));
761}
762
763inline void MessageFormatter::appendValue(char value)
764{
766 blpapi_MessageFormatter_appendValueChar)(d_handle, value));
767}
768
770{
772 blpapi_MessageFormatter_appendValueInt32)(d_handle, value));
773}
774
776{
778 blpapi_MessageFormatter_appendValueInt64)(d_handle, value));
779}
780
782{
784 blpapi_MessageFormatter_appendValueFloat32)(d_handle, value));
785}
786
788{
790 blpapi_MessageFormatter_appendValueFloat64)(d_handle, value));
791}
792
794{
796 BLPAPI_CALL(blpapi_MessageFormatter_appendValueDatetime)(
797 d_handle, &value.rawValue()));
798}
799
801{
803 blpapi_MessageFormatter_appendValueHighPrecisionDatetime)(
804 d_handle, &value));
805}
806
807inline void MessageFormatter::appendValue(const char *value)
808{
810 blpapi_MessageFormatter_appendValueString)(d_handle, value));
811}
812
813inline void MessageFormatter::appendValue(const std::string& value)
814{
815 appendValue(value.c_str());
816}
817
818inline void MessageFormatter::appendValue(const Name& value)
819{
821 BLPAPI_CALL(blpapi_MessageFormatter_appendValueFromName)(
822 d_handle, value.impl()));
823}
824
826{
828 BLPAPI_CALL(blpapi_MessageFormatter_appendElement)(d_handle));
829}
830
831inline blpapi_MessageFormatter_t *MessageFormatter::impl() const
832{
833 return d_handle;
834}
835
836inline void MessageFormatter::formatMessageJson(const char *message)
837{
839 blpapi_MessageFormatter_FormatMessageJson)(d_handle, message));
840}
841
842inline void MessageFormatter::formatMessageXml(const char *message)
843{
845 blpapi_MessageFormatter_FormatMessageXml)(d_handle, message));
846}
847
848} // close namespace test
849
850// *Deprecated*
851// Following typedef is provided for backwards compatibility. It will be
852// removed in a future release.
854
855} // close namespace blpapi
856} // close namespace BloombergLP
857
858#endif // #ifdef __cplusplus
859#endif // #ifndef INCLUDED_BLPAPI_MESSAGEFORMATTER
Provide functions for dispatchtbl.
#define BLPAPI_CALL_UNCHECKED(FUNCNAME)
Definition blpapi_call.h:362
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
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:273
blpapi_HighPrecisionDatetime_t HighPrecision
Definition blpapi_datetime.h:299
blpapi_Datetime_t & rawValue()
Definition blpapi_datetime.h:1980
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
Definition blpapi_name.h:242
blpapi_Name_t * impl() const
Definition blpapi_name.h:495
Definition blpapi_messageformatter.h:278
void formatMessageXml(const char *message)
Definition blpapi_messageformatter.h:842
void appendValue(bool value)
Definition blpapi_messageformatter.h:757
void setElementNull(const Name &name)
Definition blpapi_messageformatter.h:739
void setElement(const Name &name, bool value)
Definition blpapi_messageformatter.h:644
void formatMessageJson(const char *message)
Definition blpapi_messageformatter.h:836
MessageFormatter(blpapi_MessageFormatter_t *handle)
Definition blpapi_messageformatter.h:618
blpapi_MessageFormatter_t * impl() const
Definition blpapi_messageformatter.h:831
void appendElement()
Definition blpapi_messageformatter.h:825
void popElement()
Definition blpapi_messageformatter.h:751
~MessageFormatter()
Definition blpapi_messageformatter.h:623
void pushElement(const Name &name)
Definition blpapi_messageformatter.h:745
MessageFormatter & operator=(const MessageFormatter &rhs)
Definition blpapi_messageformatter.h:636
test::MessageFormatter MessageFormatter
Definition blpapi_messageformatter.h:853
Definition blpapi_messageformatter.h:261
Definition blpapi_abstractsession.h:212
blpapi_Float64_t Float64
Definition blpapi_types.h:485
blpapi_Float32_t Float32
Definition blpapi_types.h:484
blpapi_Int64_t Int64
Definition blpapi_types.h:482
blpapi_Int32_t Int32
Definition blpapi_types.h:480
Definition blpapi_abstractsession.h:211