BLPAPI C++  3.24.11
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 
223  blpapi_MessageFormatter_t *formatter,
224  blpapi_SchemaElementDefinition_t **definition);
225 
226 #ifdef __cplusplus
227 } // extern "C"
228 
229 #include <string>
230 #include <type_traits>
231 
239 namespace BloombergLP {
240 namespace blpapi {
241 namespace test {
242 
259 
260  private:
261  blpapi_MessageFormatter_t *d_handle;
262 
263  public:
264  // CREATORS
271  MessageFormatter(const MessageFormatter& original);
283  // MANIPULATORS
289  void setElement(const Name& name, bool value);
298  void setElement(const Name& name, char value);
307  void setElement(const Name& name, Int32 value);
316  void setElement(const Name& name, Int64 value);
325  void setElement(const Name& name, Float32 value);
334  void setElement(const Name& name, Float64 value);
343  void setElement(const Name& name, const Datetime& value);
352  void setElement(const Name& name, const Datetime::HighPrecision& value);
361  void setElement(const Name& name, const char *value);
373  void setElement(const Name& name, const std::string& value);
383  void setElement(const Name& name, const Name& value);
392  void setElement(const Name& name, const void *value, size_t length);
405  template <typename BYTES,
406  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
407  = true>
408  void setElement(const Name& name, const BYTES& value);
423  void setElementNull(const Name& name);
433  void pushElement(const Name& name);
455  void popElement();
465  void appendValue(bool value);
473  void appendValue(char value);
481  void appendValue(Int32 value);
489  void appendValue(Int64 value);
497  void appendValue(Float32 value);
505  void appendValue(Float64 value);
513  void appendValue(const Datetime& value);
521  void appendValue(const Datetime::HighPrecision& value);
529  void appendValue(const char *value);
537  void appendValue(const std::string& value);
547  void appendValue(const Name& value);
555  void appendElement();
563  void formatMessageJson(const char *message);
571  void formatMessageXml(const char *message);
579  // ACCESSORS
585 };
586 
590 // ============================================================================
591 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
592 // ============================================================================
593 
594 // ----------------------
595 // class MessageFormatter
596 // ----------------------
597 
599  : d_handle(handle)
600 {
601 }
602 
604 {
605  if (d_handle) {
607  }
608 }
609 
611 {
613  &d_handle, original.impl()));
614 }
615 
617  const MessageFormatter& rhs)
618 {
620  &d_handle, rhs.impl()));
621  return *this;
622 }
623 
624 inline void MessageFormatter::setElement(const Name& name, bool value)
625 {
628  d_handle, name.impl(), value));
629 }
630 
631 inline void MessageFormatter::setElement(const Name& name, char value)
632 {
635  d_handle, name.impl(), value));
636 }
637 
638 inline void MessageFormatter::setElement(const Name& name, Int32 value)
639 {
642  d_handle, name.impl(), value));
643 }
644 
645 inline void MessageFormatter::setElement(const Name& name, Int64 value)
646 {
649  d_handle, name.impl(), value));
650 }
651 
652 inline void MessageFormatter::setElement(const Name& name, Float32 value)
653 {
656  d_handle, name.impl(), value));
657 }
658 
659 inline void MessageFormatter::setElement(const Name& name, Float64 value)
660 {
663  d_handle, name.impl(), value));
664 }
665 
667  const Name& name, const Datetime& value)
668 {
671  d_handle, name.impl(), &value.rawValue()));
672 }
673 
675  const Name& name, const Datetime::HighPrecision& value)
676 {
679  d_handle, name.impl(), &value));
680 }
681 
682 inline void MessageFormatter::setElement(const Name& name, const char *value)
683 {
686  d_handle, name.impl(), value));
687 }
688 
690  const Name& name, const std::string& value)
691 {
692  setElement(name, value.c_str());
693 }
694 
695 inline void MessageFormatter::setElement(const Name& name, const Name& value)
696 {
699  d_handle, name.impl(), value.impl()));
700 }
701 
703  const Name& name, const void *value, size_t length)
704 {
707  name.impl(),
708  reinterpret_cast<const char *>(value),
709  length));
710 }
711 
712 template <typename BYTES,
713  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
714 inline void MessageFormatter::setElement(const Name& name, const BYTES& value)
715 {
716  setElement(name, value.data(), value.size());
717 }
718 
719 inline void MessageFormatter::setElementNull(const Name& name)
720 {
722  blpapi_MessageFormatter_setValueNull)(d_handle, name.impl()));
723 }
724 
725 inline void MessageFormatter::pushElement(const Name& name)
726 {
728  blpapi_MessageFormatter_pushElement)(d_handle, name.impl()));
729 }
730 
732 {
735 }
736 
737 inline void MessageFormatter::appendValue(bool value)
738 {
740  blpapi_MessageFormatter_appendValueBool)(d_handle, value));
741 }
742 
743 inline void MessageFormatter::appendValue(char value)
744 {
746  blpapi_MessageFormatter_appendValueChar)(d_handle, value));
747 }
748 
750 {
752  blpapi_MessageFormatter_appendValueInt32)(d_handle, value));
753 }
754 
756 {
758  blpapi_MessageFormatter_appendValueInt64)(d_handle, value));
759 }
760 
762 {
765 }
766 
768 {
771 }
772 
773 inline void MessageFormatter::appendValue(const Datetime& value)
774 {
777  d_handle, &value.rawValue()));
778 }
779 
781 {
784  d_handle, &value));
785 }
786 
787 inline void MessageFormatter::appendValue(const char *value)
788 {
791 }
792 
793 inline void MessageFormatter::appendValue(const std::string& value)
794 {
795  appendValue(value.c_str());
796 }
797 
798 inline void MessageFormatter::appendValue(const Name& value)
799 {
802  d_handle, value.impl()));
803 }
804 
806 {
809 }
810 
812 {
813  return d_handle;
814 }
815 
816 inline void MessageFormatter::formatMessageJson(const char *message)
817 {
819  blpapi_MessageFormatter_FormatMessageJson)(d_handle, message));
820 }
821 
822 inline void MessageFormatter::formatMessageXml(const char *message)
823 {
825  blpapi_MessageFormatter_FormatMessageXml)(d_handle, message));
826 }
827 
828 } // close namespace test
829 
830 // *Deprecated*
831 // Following typedef is provided for backwards compatibility. It will be
832 // removed in a future release.
834 
835 } // close namespace blpapi
836 } // close namespace BloombergLP
837 
838 #endif // #ifdef __cplusplus
839 #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:816
Common definitions used by the library.
void setElement(const Name &name, bool value)
Definition: blpapi_messageformatter.h:624
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
Definition: blpapi_abstractsession.h:187
void pushElement(const Name &name)
Definition: blpapi_messageformatter.h:725
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:258
MessageFormatter & operator=(const MessageFormatter &rhs)
Definition: blpapi_messageformatter.h:616
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:822
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)
struct blpapi_SchemaElementDefinition blpapi_SchemaElementDefinition_t
Definition: blpapi_types.h:191
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
test::MessageFormatter MessageFormatter
Definition: blpapi_messageformatter.h:833
blpapi_MessageFormatter_t * impl() const
Definition: blpapi_messageformatter.h:811
void appendElement()
Definition: blpapi_messageformatter.h:805
void setElementNull(const Name &name)
Definition: blpapi_messageformatter.h:719
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:737
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:731
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:598
~MessageFormatter()
Definition: blpapi_messageformatter.h:603
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)
int blpapi_MessageFormatter_getElementDefinition(blpapi_MessageFormatter_t *formatter, blpapi_SchemaElementDefinition_t **definition)
Definition: blpapi_datetime.h:115