BLPAPI C++  3.23.2
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 
28 #ifndef INCLUDED_BLPAPI_MESSAGEFORMATTER
29 #define INCLUDED_BLPAPI_MESSAGEFORMATTER
30 
72 #include <blpapi_call.h>
73 #include <blpapi_defs.h>
74 #include <blpapi_event.h>
75 #include <blpapi_topic.h>
76 #include <blpapi_types.h>
77 
78 #include <stddef.h>
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
86  const blpapi_Name_t *typeName,
87  blpapi_Bool_t value);
88 
91  const blpapi_Name_t *typeName,
92  char value);
93 
96  const blpapi_Name_t *typeName,
97  blpapi_Int32_t value);
98 
101  const blpapi_Name_t *typeName,
102  blpapi_Int64_t value);
103 
106  blpapi_MessageFormatter_t *formatter,
107  const blpapi_Name_t *typeName,
108  blpapi_Float32_t value);
109 
112  blpapi_MessageFormatter_t *formatter,
113  const blpapi_Name_t *typeName,
114  blpapi_Float64_t value);
115 
118  blpapi_MessageFormatter_t *formatter,
119  const blpapi_Name_t *typeName,
120  const blpapi_Datetime_t *value);
121 
124  blpapi_MessageFormatter_t *formatter,
125  const blpapi_Name_t *typeName,
126  const blpapi_HighPrecisionDatetime_t *value);
127 
130  blpapi_MessageFormatter_t *formatter,
131  const blpapi_Name_t *typeName,
132  const char *value);
133 
136  blpapi_MessageFormatter_t *formatter,
137  const blpapi_Name_t *typeName,
138  const blpapi_Name_t *value);
139 
142  const blpapi_Name_t *typeName,
143  const char *value,
144  size_t length);
145 
148  blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName);
149 
152  blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName);
153 
156 
159  blpapi_MessageFormatter_t *formatter, blpapi_Bool_t value);
160 
163  blpapi_MessageFormatter_t *formatter, char value);
164 
167  blpapi_MessageFormatter_t *formatter, blpapi_Int32_t value);
168 
171  blpapi_MessageFormatter_t *formatter, blpapi_Int64_t value);
172 
175  blpapi_MessageFormatter_t *formatter, blpapi_Float32_t value);
176 
179  blpapi_MessageFormatter_t *formatter, blpapi_Float64_t value);
180 
183  blpapi_MessageFormatter_t *formatter, const blpapi_Datetime_t *value);
184 
187  blpapi_MessageFormatter_t *formatter,
188  const blpapi_HighPrecisionDatetime_t *value);
189 
192  blpapi_MessageFormatter_t *formatter, const char *value);
193 
196  blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *value);
197 
200  blpapi_MessageFormatter_t *formatter);
201 
204  blpapi_MessageFormatter_t *formatter, const char *message);
205 
208  blpapi_MessageFormatter_t *formatter, const char *message);
209 
212  const blpapi_MessageFormatter_t *original);
213 
217 
220 
221 #ifdef __cplusplus
222 } // extern "C"
223 
224 #include <string>
225 #include <type_traits>
226 
234 namespace BloombergLP {
235 namespace blpapi {
236 namespace test {
237 
254 
255  private:
256  blpapi_MessageFormatter_t *d_handle;
257 
258  public:
259  // CREATORS
266  MessageFormatter(const MessageFormatter& original);
278  // MANIPULATORS
284  void setElement(const Name& name, bool value);
293  void setElement(const Name& name, char value);
302  void setElement(const Name& name, Int32 value);
311  void setElement(const Name& name, Int64 value);
320  void setElement(const Name& name, Float32 value);
329  void setElement(const Name& name, Float64 value);
338  void setElement(const Name& name, const Datetime& value);
347  void setElement(const Name& name, const Datetime::HighPrecision& value);
356  void setElement(const Name& name, const char *value);
368  void setElement(const Name& name, const std::string& value);
378  void setElement(const Name& name, const Name& value);
387  void setElement(const Name& name, const void *value, size_t length);
400  template <typename BYTES,
401  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
402  = true>
403  void setElement(const Name& name, const BYTES& value);
418  void setElementNull(const Name& name);
428  void pushElement(const Name& name);
450  void popElement();
460  void appendValue(bool value);
468  void appendValue(char value);
476  void appendValue(Int32 value);
484  void appendValue(Int64 value);
492  void appendValue(Float32 value);
500  void appendValue(Float64 value);
508  void appendValue(const Datetime& value);
516  void appendValue(const Datetime::HighPrecision& value);
524  void appendValue(const char *value);
532  void appendValue(const std::string& value);
542  void appendValue(const Name& value);
550  void appendElement();
558  void formatMessageJson(const char *message);
566  void formatMessageXml(const char *message);
574  // ACCESSORS
580 };
581 
585 // ============================================================================
586 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
587 // ============================================================================
588 
589 // ----------------------
590 // class MessageFormatter
591 // ----------------------
592 
594  : d_handle(handle)
595 {
596 }
597 
599 {
600  if (d_handle) {
602  }
603 }
604 
606 {
608  &d_handle, original.impl()));
609 }
610 
612  const MessageFormatter& rhs)
613 {
615  &d_handle, rhs.impl()));
616  return *this;
617 }
618 
619 inline void MessageFormatter::setElement(const Name& name, bool value)
620 {
623  d_handle, name.impl(), value));
624 }
625 
626 inline void MessageFormatter::setElement(const Name& name, char value)
627 {
630  d_handle, name.impl(), value));
631 }
632 
633 inline void MessageFormatter::setElement(const Name& name, Int32 value)
634 {
637  d_handle, name.impl(), value));
638 }
639 
640 inline void MessageFormatter::setElement(const Name& name, Int64 value)
641 {
644  d_handle, name.impl(), value));
645 }
646 
647 inline void MessageFormatter::setElement(const Name& name, Float32 value)
648 {
651  d_handle, name.impl(), value));
652 }
653 
654 inline void MessageFormatter::setElement(const Name& name, Float64 value)
655 {
658  d_handle, name.impl(), value));
659 }
660 
662  const Name& name, const Datetime& value)
663 {
666  d_handle, name.impl(), &value.rawValue()));
667 }
668 
670  const Name& name, const Datetime::HighPrecision& value)
671 {
674  d_handle, name.impl(), &value));
675 }
676 
677 inline void MessageFormatter::setElement(const Name& name, const char *value)
678 {
681  d_handle, name.impl(), value));
682 }
683 
685  const Name& name, const std::string& value)
686 {
687  setElement(name, value.c_str());
688 }
689 
690 inline void MessageFormatter::setElement(const Name& name, const Name& value)
691 {
694  d_handle, name.impl(), value.impl()));
695 }
696 
698  const Name& name, const void *value, size_t length)
699 {
702  name.impl(),
703  reinterpret_cast<const char *>(value),
704  length));
705 }
706 
707 template <typename BYTES,
708  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
709 inline void MessageFormatter::setElement(const Name& name, const BYTES& value)
710 {
711  setElement(name, value.data(), value.size());
712 }
713 
714 inline void MessageFormatter::setElementNull(const Name& name)
715 {
717  blpapi_MessageFormatter_setValueNull)(d_handle, name.impl()));
718 }
719 
720 inline void MessageFormatter::pushElement(const Name& name)
721 {
723  blpapi_MessageFormatter_pushElement)(d_handle, name.impl()));
724 }
725 
727 {
730 }
731 
732 inline void MessageFormatter::appendValue(bool value)
733 {
735  blpapi_MessageFormatter_appendValueBool)(d_handle, value));
736 }
737 
738 inline void MessageFormatter::appendValue(char value)
739 {
741  blpapi_MessageFormatter_appendValueChar)(d_handle, value));
742 }
743 
745 {
747  blpapi_MessageFormatter_appendValueInt32)(d_handle, value));
748 }
749 
751 {
753  blpapi_MessageFormatter_appendValueInt64)(d_handle, value));
754 }
755 
757 {
760 }
761 
763 {
766 }
767 
768 inline void MessageFormatter::appendValue(const Datetime& value)
769 {
772  d_handle, &value.rawValue()));
773 }
774 
776 {
779  d_handle, &value));
780 }
781 
782 inline void MessageFormatter::appendValue(const char *value)
783 {
786 }
787 
788 inline void MessageFormatter::appendValue(const std::string& value)
789 {
790  appendValue(value.c_str());
791 }
792 
793 inline void MessageFormatter::appendValue(const Name& value)
794 {
797  d_handle, value.impl()));
798 }
799 
801 {
804 }
805 
807 {
808  return d_handle;
809 }
810 
811 inline void MessageFormatter::formatMessageJson(const char *message)
812 {
814  blpapi_MessageFormatter_FormatMessageJson)(d_handle, message));
815 }
816 
817 inline void MessageFormatter::formatMessageXml(const char *message)
818 {
820  blpapi_MessageFormatter_FormatMessageXml)(d_handle, message));
821 }
822 
823 } // close namespace test
824 
825 // *Deprecated*
826 // Following typedef is provided for backwards compatibility. It will be
827 // removed in a future release.
829 
830 } // close namespace blpapi
831 } // close namespace BloombergLP
832 
833 #endif // #ifdef __cplusplus
834 #endif // #ifndef INCLUDED_BLPAPI_MESSAGEFORMATTER
int blpapi_MessageFormatter_setValueString(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, const char *value)
int blpapi_MessageFormatter_FormatMessageXml(blpapi_MessageFormatter_t *formatter, const char *message)
int blpapi_MessageFormatter_appendValueBool(blpapi_MessageFormatter_t *formatter, blpapi_Bool_t value)
int blpapi_MessageFormatter_appendValueInt32(blpapi_MessageFormatter_t *formatter, blpapi_Int32_t value)
int blpapi_MessageFormatter_setValueNull(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName)
int blpapi_MessageFormatter_appendValueDatetime(blpapi_MessageFormatter_t *formatter, const blpapi_Datetime_t *value)
void formatMessageJson(const char *message)
Definition: blpapi_messageformatter.h:811
Common definitions used by the library.
void setElement(const Name &name, bool value)
Definition: blpapi_messageformatter.h:619
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
Definition: blpapi_abstractsession.h:220
void pushElement(const Name &name)
Definition: blpapi_messageformatter.h:720
int blpapi_MessageFormatter_setValueFloat64(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, blpapi_Float64_t value)
int blpapi_MessageFormatter_pushElement(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName)
Definition: blpapi_name.h:150
#define BLPAPI_CALL(FUNCNAME)
Definition: blpapi_call.h:353
blpapi_Float64_t Float64
Definition: blpapi_types.h:474
int blpapi_MessageFormatter_setValueChar(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, char value)
Definition: blpapi_messageformatter.h:253
MessageFormatter & operator=(const MessageFormatter &rhs)
Definition: blpapi_messageformatter.h:611
int blpapi_MessageFormatter_setValueHighPrecisionDatetime(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, const blpapi_HighPrecisionDatetime_t *value)
blpapi_Name_t * impl() const
Definition: blpapi_name.h:403
int blpapi_MessageFormatter_appendValueFromName(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *value)
int blpapi_Int32_t
Definition: blpapi_types.h:67
struct blpapi_Name blpapi_Name_t
Definition: blpapi_types.h:154
int blpapi_MessageFormatter_FormatMessageJson(blpapi_MessageFormatter_t *formatter, const char *message)
int blpapi_MessageFormatter_appendValueString(blpapi_MessageFormatter_t *formatter, const char *value)
void formatMessageXml(const char *message)
Definition: blpapi_messageformatter.h:817
int blpapi_Bool_t
Definition: blpapi_types.h:62
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
A component which defines events related operations.
int blpapi_MessageFormatter_assign(blpapi_MessageFormatter_t **lhs, const blpapi_MessageFormatter_t *rhs)
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
test::MessageFormatter MessageFormatter
Definition: blpapi_messageformatter.h:828
blpapi_MessageFormatter_t * impl() const
Definition: blpapi_messageformatter.h:806
void appendElement()
Definition: blpapi_messageformatter.h:800
void setElementNull(const Name &name)
Definition: blpapi_messageformatter.h:714
int blpapi_MessageFormatter_setValueDatetime(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, const blpapi_Datetime_t *value)
int blpapi_MessageFormatter_appendValueInt64(blpapi_MessageFormatter_t *formatter, blpapi_Int64_t value)
void appendValue(bool value)
Definition: blpapi_messageformatter.h:732
blpapi_Datetime_t & rawValue()
Definition: blpapi_datetime.h:1952
int blpapi_MessageFormatter_appendValueFloat32(blpapi_MessageFormatter_t *formatter, blpapi_Float32_t value)
Provide representation of a Topic.
blpapi_Int64_t Int64
Definition: blpapi_types.h:471
int blpapi_MessageFormatter_appendElement(blpapi_MessageFormatter_t *formatter)
void popElement()
Definition: blpapi_messageformatter.h:726
Definition: blpapi_datetime.h:102
int blpapi_MessageFormatter_setValueFloat32(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, blpapi_Float32_t value)
int blpapi_MessageFormatter_destroy(blpapi_MessageFormatter_t *formatter)
int blpapi_MessageFormatter_appendValueHighPrecisionDatetime(blpapi_MessageFormatter_t *formatter, const blpapi_HighPrecisionDatetime_t *value)
double blpapi_Float64_t
Definition: blpapi_types.h:72
MessageFormatter(blpapi_MessageFormatter_t *handle)
Definition: blpapi_messageformatter.h:593
~MessageFormatter()
Definition: blpapi_messageformatter.h:598
int blpapi_MessageFormatter_setValueBool(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, blpapi_Bool_t value)
long long blpapi_Int64_t
Definition: blpapi_types.h:69
int blpapi_MessageFormatter_copy(blpapi_MessageFormatter_t **formatter, const blpapi_MessageFormatter_t *original)
int blpapi_MessageFormatter_setValueBytes(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, const char *value, size_t length)
#define BLPAPI_CALL_UNCHECKED(FUNCNAME)
Definition: blpapi_call.h:354
float blpapi_Float32_t
Definition: blpapi_types.h:71
int blpapi_MessageFormatter_setValueInt64(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, blpapi_Int64_t value)
struct blpapi_MessageFormatter blpapi_MessageFormatter_t
Definition: blpapi_types.h:197
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
int blpapi_MessageFormatter_appendValueChar(blpapi_MessageFormatter_t *formatter, char value)
Definition: blpapi_datetime.h:245
Provide functions for dispatchtbl.
int blpapi_MessageFormatter_appendValueFloat64(blpapi_MessageFormatter_t *formatter, blpapi_Float64_t value)
int blpapi_MessageFormatter_setValueFromName(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, const blpapi_Name_t *value)
Provide BLPAPI types.
int blpapi_MessageFormatter_setValueInt32(blpapi_MessageFormatter_t *formatter, const blpapi_Name_t *typeName, blpapi_Int32_t value)
int blpapi_MessageFormatter_popElement(blpapi_MessageFormatter_t *formatter)
Definition: blpapi_datetime.h:115