BLPAPI C++ 3.26.4
Loading...
Searching...
No Matches
blpapi_element.h
Go to the documentation of this file.
1/* Copyright 2012. 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_ELEMENT
29#define INCLUDED_BLPAPI_ELEMENT
30
59#include <blpapi_call.h>
60#include <blpapi_datetime.h>
61#include <blpapi_defs.h>
62#include <blpapi_deprecate.h>
63#include <blpapi_name.h>
64#include <blpapi_schema.h>
65#include <blpapi_streamproxy.h>
66#include <blpapi_types.h>
67
68#include <stddef.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
75 const blpapi_Element_t *element);
76
78 const blpapi_Element_t *element);
79
81 const blpapi_Element_t *element);
82
84
86 const blpapi_Element_t *element);
87
89
91
93
95 const blpapi_Element_t *element);
96
98 const blpapi_Element_t *element, size_t position);
99
101
103 blpapi_StreamWriter_t streamWriter,
104 void *stream,
105 int level,
106 int spacesPerLevel);
107
109 blpapi_StreamWriter_t streamWriter,
110 void *stream);
111
113 const blpapi_Element_t *element, char const *json);
114
117 blpapi_Element_t **result,
118 size_t position);
119
122 blpapi_Element_t **result,
123 const char *nameString,
124 const blpapi_Name_t *name);
125
128 const char *nameString,
129 const blpapi_Name_t *name);
130
133 const char *nameString,
134 const blpapi_Name_t *name,
135 int excludeNullElements,
136 int reserved);
137
140 const blpapi_Element_t *element, blpapi_Bool_t *buffer, size_t index);
141
144 const blpapi_Element_t *element, blpapi_Char_t *buffer, size_t index);
145
148 const blpapi_Element_t *element, blpapi_Int32_t *buffer, size_t index);
149
152 const blpapi_Element_t *element, blpapi_Int64_t *buffer, size_t index);
153
156 blpapi_Float32_t *buffer,
157 size_t index);
158
161 blpapi_Float64_t *buffer,
162 size_t index);
163
166 const blpapi_Element_t *element, const char **buffer, size_t index);
167
170 blpapi_Datetime_t *buffer,
171 size_t index);
172
175 const blpapi_Element_t *element,
177 size_t index);
178
181 blpapi_Element_t **buffer,
182 size_t index);
183
186 const blpapi_Element_t *element, blpapi_Name_t **buffer, size_t index);
187
190 const char **buffer,
191 size_t *length,
192 size_t index);
193
196 const blpapi_Element_t *element, blpapi_Element_t **result);
197
200 blpapi_Element_t *element, blpapi_Bool_t value, size_t index);
201
204 blpapi_Element_t *element, blpapi_Char_t value, size_t index);
205
208 blpapi_Element_t *element, blpapi_Int32_t value, size_t index);
209
212 blpapi_Element_t *element, blpapi_Int64_t value, size_t index);
213
216 blpapi_Element_t *element, blpapi_Float32_t value, size_t index);
217
220 blpapi_Element_t *element, blpapi_Float64_t value, size_t index);
221
224 blpapi_Element_t *element, const char *value, size_t index);
225
228 const blpapi_Datetime_t *value,
229 size_t index);
230
234 size_t index);
235
238 const char *value,
239 size_t length,
240 size_t index);
241
244 blpapi_Element_t *element, blpapi_Element_t *value, size_t index);
245
248 blpapi_Element_t *element, const blpapi_Name_t *value, size_t index);
249
252 const char *nameString,
253 const blpapi_Name_t *name,
254 blpapi_Bool_t value);
255
258 const char *nameString,
259 const blpapi_Name_t *name,
260 blpapi_Char_t value);
261
264 const char *nameString,
265 const blpapi_Name_t *name,
266 blpapi_Int32_t value);
267
270 const char *nameString,
271 const blpapi_Name_t *name,
272 blpapi_Int64_t value);
273
276 const char *nameString,
277 const blpapi_Name_t *name,
278 blpapi_Float32_t value);
279
282 const char *nameString,
283 const blpapi_Name_t *name,
284 blpapi_Float64_t value);
285
288 const char *nameString,
289 const blpapi_Name_t *name,
290 const char *value);
291
294 const char *nameString,
295 const blpapi_Name_t *name,
296 const blpapi_Datetime_t *value);
297
300 const char *nameString,
301 const blpapi_Name_t *name,
302 const blpapi_HighPrecisionDatetime_t *value);
303
306 const char *nameString,
307 const blpapi_Name_t *name,
308 const char *value,
309 size_t length);
310
313 const char *nameString,
314 const blpapi_Name_t *name,
315 blpapi_Element_t *sourcebuffer);
316
319 const char *elementName,
320 const blpapi_Name_t *name,
321 const blpapi_Name_t *buffer);
322
325 blpapi_Element_t *element, blpapi_Element_t **appendedElement);
326
329 blpapi_Element_t **resultElement,
330 const char *nameCstr,
331 const blpapi_Name_t *name,
332 size_t index);
333
334#ifdef __cplusplus
335}
336
337#include <blpapi_exception.h>
338
339#include <cassert>
340#include <sstream>
341#include <string>
342#include <type_traits>
343
351namespace BloombergLP {
352namespace blpapi {
353
473class Element {
474
475 blpapi_Element_t *d_handle_p;
476
477 public:
478 Element();
485 explicit Element(blpapi_Element_t *element);
486
487 // MANIPULATORS
488
489 void rebind(blpapi_Element_t *element);
490
491 BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, bool value);
504 BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, char value);
517 BLPAPI_DEPRECATE_STRING_NAME void setElement(
518 const char *name, Int32 value);
531 BLPAPI_DEPRECATE_STRING_NAME void setElement(
532 const char *name, Int64 value);
545 BLPAPI_DEPRECATE_STRING_NAME void setElement(
546 const char *name, Float32 value);
559 BLPAPI_DEPRECATE_STRING_NAME void setElement(
560 const char *name, Float64 value);
573 BLPAPI_DEPRECATE_STRING_NAME void setElement(
574 const char *name, const Datetime& value);
587 BLPAPI_DEPRECATE_STRING_NAME void setElement(
588 const char *name, const char *value);
601 BLPAPI_DEPRECATE_STRING_NAME void setElement(
602 const char *name, const Name& value);
616 void setElement(const Name& name, bool value);
627 void setElement(const Name& name, char value);
638 void setElement(const Name& name, Int32 value);
649 void setElement(const Name& name, Int64 value);
660 void setElement(const Name& name, Float32 value);
671 void setElement(const Name& name, Float64 value);
682 void setElement(const Name& name, const Datetime& value);
693 void setElement(const Name& name, const char *value);
704 void setElement(const Name& name, const std::string& value);
716 void setElement(const Name& name, const Name& value);
727 void setElement(const Name& name, const void *value, size_t length);
738 template <typename BYTES,
739 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
740 = true>
741 void setElement(const Name& name, const BYTES& value);
757 void setValue(bool value, size_t index = 0);
766 void setValue(char value, size_t index = 0);
775 void setValue(Int32 value, size_t index = 0);
784 void setValue(Int64 value, size_t index = 0);
793 void setValue(Float32 value, size_t index = 0);
802 void setValue(Float64 value, size_t index = 0);
811 void setValue(const Datetime& value, size_t index = 0);
820 void setValue(const char *value, size_t index = 0);
829 void setValue(const std::string& value, size_t index = 0);
839 void setValue(const Name& valueName, size_t index = 0);
849 void setValue(const void *value, size_t length, size_t index);
858 template <typename BYTES,
859 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
860 = true>
861 void setValue(const BYTES& value, size_t index = 0);
875 void appendValue(bool value);
885 void appendValue(char value);
895 void appendValue(Int32 value);
905 void appendValue(Int64 value);
915 void appendValue(Float32 value);
925 void appendValue(Float64 value);
935 void appendValue(const Datetime& value);
945 void appendValue(const char *value);
955 void appendValue(const std::string& value);
967 void appendValue(const Name& value);
985 BLPAPI_DEPRECATE_STRING_NAME Element setChoice(const char *selectionName);
995 Element setChoice(const Name& selectionName);
1004
1005 // ACCESSORS
1006
1007 Name name() const;
1016 int datatype() const;
1024 bool isComplexType() const;
1030 bool isArray() const;
1037 bool isNull() const;
1042 bool isReadOnly() const;
1053 size_t numValues() const;
1063 size_t numElements() const;
1071 bool isValid() const;
1078 bool isNullValue(size_t position = 0) const;
1086 BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
1087 const char *name, bool excludeNullElements = false) const;
1096 bool hasElement(const Name& name, bool excludeNullElements = false) const;
1105 int getValueAs(bool *result, size_t index = 0) const;
1114 int getValueAs(char *result, size_t index = 0) const;
1123 int getValueAs(Int32 *result, size_t index = 0) const;
1132 int getValueAs(Int64 *result, size_t index = 0) const;
1141 int getValueAs(Float32 *result, size_t index = 0) const;
1150 int getValueAs(Float64 *result, size_t index = 0) const;
1159 int getValueAs(Datetime *result, size_t index = 0) const;
1171 int getValueAs(std::string *result, size_t index = 0) const;
1180 int getValueAs(Bytes *result, size_t index = 0) const;
1188 int getValueAs(Element *result, size_t index = 0) const;
1197 int getValueAs(Name *result, size_t index = 0) const;
1205 bool getValueAsBool(size_t index = 0) const;
1212 char getValueAsChar(size_t index = 0) const;
1219 Int32 getValueAsInt32(size_t index = 0) const;
1226 Int64 getValueAsInt64(size_t index = 0) const;
1233 Float32 getValueAsFloat32(size_t index = 0) const;
1240 Float64 getValueAsFloat64(size_t index = 0) const;
1247 Datetime getValueAsDatetime(size_t index = 0) const;
1258 const char *getValueAsString(size_t index = 0) const;
1267 Bytes getValueAsBytes(size_t index = 0) const;
1275 Element getValueAsElement(size_t index = 0) const;
1283 Name getValueAsName(size_t index = 0) const;
1290 BLPAPI_DEPRECATE_STRING_NAME int getElement(
1291 Element *result, const char *name) const;
1302 int getElement(Element *result, const Name& name) const;
1311 int getElement(Element *result, size_t position) const;
1320 Element getElement(size_t position) const;
1328 Element getElement(const Name& name) const;
1336 BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name) const;
1347 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
1358 bool getElementAsBool(const Name& name) const;
1367 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
1378 char getElementAsChar(const Name& name) const;
1387 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
1388 const char *name) const;
1399 Int32 getElementAsInt32(const Name& name) const;
1408 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
1409 const char *name) const;
1420 Int64 getElementAsInt64(const Name& name) const;
1429 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
1430 const char *name) const;
1441 Float32 getElementAsFloat32(const Name& name) const;
1450 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
1451 const char *name) const;
1462 Float64 getElementAsFloat64(const Name& name) const;
1471 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
1472 const char *name) const;
1487 Datetime getElementAsDatetime(const Name& name) const;
1499 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
1500 const char *name) const;
1512 const char *getElementAsString(const Name& name) const;
1522 Bytes getElementAsBytes(const Name& name) const;
1532 BLPAPI_DEPRECATE_STRING_NAME Name getElementAsName(const char *name) const;
1543 Name getElementAsName(const Name& name) const;
1552 Element getChoice() const;
1558 const blpapi_Element_t *handle() const;
1559
1560 std::ostream& print(
1561 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
1575 std::string toJson() const;
1582 void fromJson(const char *json);
1592 void fromJson(const std::string& json);
1602};
1603
1607// FREE OPERATORS
1608std::ostream& operator<<(std::ostream& stream, const Element& element);
1622// ============================================================================
1623// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
1624// ============================================================================
1625
1626// -------------
1627// class Element
1628// -------------
1629
1631 : d_handle_p(0)
1632{
1633}
1634
1636 : d_handle_p(newHandle)
1637{
1638}
1639
1641{
1642 d_handle_p = element;
1643}
1644
1645inline void Element::setElement(const char *elementName, bool value)
1646{
1648 d_handle_p, elementName, 0, value ? 1 : 0));
1649}
1650
1651inline void Element::setElement(const char *elementName, char value)
1652{
1654 blpapi_Element_setElementChar(d_handle_p, elementName, 0, value));
1655}
1656
1657inline void Element::setElement(const char *elementName, Int32 value)
1658{
1660 blpapi_Element_setElementInt32(d_handle_p, elementName, 0, value));
1661}
1662
1663inline void Element::setElement(const char *elementName, Int64 value)
1664{
1666 blpapi_Element_setElementInt64(d_handle_p, elementName, 0, value));
1667}
1668
1669inline void Element::setElement(const char *elementName, Float32 value)
1670{
1672 d_handle_p, elementName, 0, value));
1673}
1674
1675inline void Element::setElement(const char *elementName, Float64 value)
1676{
1678 d_handle_p, elementName, 0, value));
1679}
1680
1681inline void Element::setElement(const char *elementName, const Datetime& value)
1682{
1685 elementName,
1686 0,
1687 &value.rawHighPrecisionValue()));
1688}
1689
1690inline void Element::setElement(const char *elementName, const char *value)
1691{
1693 d_handle_p, elementName, 0, value));
1694}
1695
1696inline void Element::setElement(const char *elementName, const Name& value)
1697{
1699 d_handle_p, elementName, 0, value.impl()));
1700}
1701
1702inline void Element::setElement(const Name& elementName, bool value)
1703{
1705 d_handle_p, 0, elementName.impl(), value ? 1 : 0));
1706}
1707
1708inline void Element::setElement(const Name& elementName, char value)
1709{
1711 d_handle_p, 0, elementName.impl(), value));
1712}
1713
1714inline void Element::setElement(const Name& elementName, Int32 value)
1715{
1717 d_handle_p, 0, elementName.impl(), value));
1718}
1719
1720inline void Element::setElement(const Name& elementName, Int64 value)
1721{
1723 d_handle_p, 0, elementName.impl(), value));
1724}
1725
1726inline void Element::setElement(const Name& elementName, Float32 value)
1727{
1729 d_handle_p, 0, elementName.impl(), value));
1730}
1731
1732inline void Element::setElement(const Name& elementName, Float64 value)
1733{
1735 d_handle_p, 0, elementName.impl(), value));
1736}
1737
1738inline void Element::setElement(const Name& elementName, const Datetime& value)
1739{
1742 0,
1743 elementName.impl(),
1744 &value.rawHighPrecisionValue()));
1745}
1746
1747inline void Element::setElement(const Name& elementName, const char *value)
1748{
1750 d_handle_p, 0, elementName.impl(), value));
1751}
1752
1754 const Name& elementName, const std::string& value)
1755{
1756 setElement(elementName, value.c_str());
1757}
1758
1759inline void Element::setElement(const Name& elementName, const Name& value)
1760{
1762 d_handle_p, 0, elementName.impl(), value.impl()));
1763}
1764
1766 const Name& elementName, const void *value, size_t length)
1767{
1770 0,
1771 elementName.impl(),
1772 reinterpret_cast<const char *>(value),
1773 length));
1774}
1775
1776template <typename BYTES,
1777 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1778inline void Element::setElement(const Name& elementName, const BYTES& value)
1779{
1780 setElement(elementName, value.data(), value.size());
1781}
1782
1783inline void Element::setValue(bool value, size_t index)
1784{
1786 blpapi_Element_setValueBool(d_handle_p, value, index));
1787}
1788
1789inline void Element::setValue(char value, size_t index)
1790{
1792 blpapi_Element_setValueChar(d_handle_p, value, index));
1793}
1794
1795inline void Element::setValue(Int32 value, size_t index)
1796{
1798 blpapi_Element_setValueInt32(d_handle_p, value, index));
1799}
1800
1801inline void Element::setValue(Int64 value, size_t index)
1802{
1804 blpapi_Element_setValueInt64(d_handle_p, value, index));
1805}
1806
1807inline void Element::setValue(Float32 value, size_t index)
1808{
1810 blpapi_Element_setValueFloat32(d_handle_p, value, index));
1811}
1812
1813inline void Element::setValue(Float64 value, size_t index)
1814{
1816 blpapi_Element_setValueFloat64(d_handle_p, value, index));
1817}
1818
1819inline void Element::setValue(const Datetime& value, size_t index)
1820{
1823 d_handle_p, &value.rawHighPrecisionValue(), index));
1824}
1825
1826inline void Element::setValue(const char *value, size_t index)
1827{
1829 blpapi_Element_setValueString(d_handle_p, value, index));
1830}
1831
1832inline void Element::setValue(const std::string& value, size_t index)
1833{
1834 setValue(value.c_str(), index);
1835}
1836
1837inline void Element::setValue(const Name& valueName, size_t index)
1838{
1840 d_handle_p, valueName.impl(), index));
1841}
1842
1843inline void Element::setValue(const void *value, size_t length, size_t index)
1844{
1846 d_handle_p, reinterpret_cast<const char *>(value), length, index));
1847}
1848
1849template <typename BYTES,
1850 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1851inline void Element::setValue(const BYTES& value, size_t index)
1852{
1853 setValue(value.data(), value.size(), index);
1854}
1855
1856inline void Element::appendValue(bool value)
1857{
1859 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1860}
1861
1862inline void Element::appendValue(char value)
1863{
1865 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1866}
1867
1873
1879
1885
1891
1899
1900inline void Element::appendValue(const char *value)
1901{
1903 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1904}
1905
1906inline void Element::appendValue(const std::string& value)
1907{
1908 appendValue(value.c_str());
1909}
1910
1911inline void Element::appendValue(const Name& valueName)
1912{
1914 d_handle_p, valueName.impl(), BLPAPI_ELEMENT_INDEX_END));
1915}
1916
1918{
1919 blpapi_Element_t *appendedElement = 0;
1921 blpapi_Element_appendElement(d_handle_p, &appendedElement));
1922 return Element(appendedElement);
1923}
1924
1925inline Element Element::setChoice(const char *selectionName)
1926{
1927 blpapi_Element_t *resultElement = 0;
1929 d_handle_p, &resultElement, selectionName, 0, 0));
1930 return Element(resultElement);
1931}
1932
1933inline Element Element::setChoice(const Name& selectionName)
1934{
1935 blpapi_Element_t *resultElement = 0;
1937 d_handle_p, &resultElement, 0, selectionName.impl(), 0));
1938 return Element(resultElement);
1939}
1940
1941inline blpapi_Element_t *Element::handle() { return d_handle_p; }
1942
1943inline Name Element::name() const
1944{
1945 return Name(blpapi_Element_name(d_handle_p));
1946}
1947
1948inline int Element::getElement(Element *element, const char *nameString) const
1949{
1950 assert(element);
1951
1952 blpapi_Element_t *fldt = 0;
1953 int rc = blpapi_Element_getElement(d_handle_p, &fldt, nameString, 0);
1954 if (!rc) {
1955 element->rebind(fldt);
1956 }
1957
1958 return rc;
1959}
1960
1961inline int Element::getElement(Element *element, const Name& elementName) const
1962{
1963 assert(element);
1964
1965 blpapi_Element_t *fldt = 0;
1967 d_handle_p, &fldt, 0, elementName.impl());
1968 if (!rc) {
1969 element->rebind(fldt);
1970 }
1971
1972 return rc;
1973}
1974
1975inline int Element::getElement(Element *element, size_t position) const
1976{
1977 assert(element);
1978
1979 blpapi_Element_t *fldt = 0;
1980 int rc = blpapi_Element_getElementAt(d_handle_p, &fldt, position);
1981 if (!rc) {
1982 element->rebind(fldt);
1983 }
1984
1985 return rc;
1986}
1987
1988inline int Element::datatype() const
1989{
1990 return blpapi_Element_datatype(d_handle_p);
1991}
1992
1993inline bool Element::isComplexType() const
1994{
1995 return blpapi_Element_isComplexType(d_handle_p) ? true : false;
1996}
1997
1998inline bool Element::isArray() const
1999{
2000 return blpapi_Element_isArray(d_handle_p) ? true : false;
2001}
2002
2003inline bool Element::isNull() const
2004{
2005 return blpapi_Element_isNull(d_handle_p) ? true : false;
2006}
2007
2008inline bool Element::isReadOnly() const
2009{
2010 return blpapi_Element_isReadOnly(d_handle_p) ? true : false;
2011}
2012
2017
2018inline size_t Element::numValues() const
2019{
2020 return blpapi_Element_numValues(d_handle_p);
2021}
2022
2023inline size_t Element::numElements() const
2024{
2025 return blpapi_Element_numElements(d_handle_p);
2026}
2027
2028inline bool Element::isValid() const { return d_handle_p ? true : false; }
2029
2030inline bool Element::isNullValue(size_t position) const
2031{
2032 int rc = blpapi_Element_isNullValue(d_handle_p, position);
2033 if (rc != 0 && rc != 1) {
2035 }
2036 return rc ? true : false;
2037}
2038
2040 const char *nameString, bool excludeNullElements) const
2041{
2042 if (excludeNullElements) {
2044 d_handle_p, nameString, 0, excludeNullElements, 0)
2045 ? true
2046 : false);
2047 }
2048 return blpapi_Element_hasElement(d_handle_p, nameString, 0) ? true : false;
2049}
2050
2052 const Name& elementName, bool excludeNullElements) const
2053{
2054 if (excludeNullElements) {
2055 return (blpapi_Element_hasElementEx(d_handle_p,
2056 0,
2057 elementName.impl(),
2058 excludeNullElements,
2059 0)
2060 ? true
2061 : false);
2062 }
2063 return blpapi_Element_hasElement(d_handle_p, 0, elementName.impl())
2064 ? true
2065 : false;
2066}
2067
2068inline Element Element::getElement(const Name& elementName) const
2069{
2070 blpapi_Element_t *fldt = 0;
2072 d_handle_p, &fldt, 0, elementName.impl()));
2073 return Element(fldt);
2074}
2075
2076inline Element Element::getElement(const char *elementName) const
2077{
2078 blpapi_Element_t *fldt = 0;
2080 blpapi_Element_getElement(d_handle_p, &fldt, elementName, 0));
2081 return Element(fldt);
2082}
2083
2084inline Element Element::getElement(size_t position) const
2085{
2086 blpapi_Element_t *element = 0;
2088 blpapi_Element_getElementAt(d_handle_p, &element, position));
2089 return Element(element);
2090}
2091
2092inline int Element::getValueAs(bool *buffer, size_t index) const
2093{
2094 assert(buffer);
2095
2096 blpapi_Bool_t tmp = false;
2097
2098 int res = blpapi_Element_getValueAsBool(d_handle_p, &tmp, index);
2099 *buffer = tmp ? true : false;
2100 return res;
2101}
2102
2103inline int Element::getValueAs(char *buffer, size_t index) const
2104{
2105 return blpapi_Element_getValueAsChar(d_handle_p, buffer, index);
2106}
2107
2108inline int Element::getValueAs(Int32 *buffer, size_t index) const
2109{
2110 return blpapi_Element_getValueAsInt32(d_handle_p, buffer, index);
2111}
2112
2113inline int Element::getValueAs(Int64 *buffer, size_t index) const
2114{
2115 return blpapi_Element_getValueAsInt64(d_handle_p, buffer, index);
2116}
2117
2118inline int Element::getValueAs(Float32 *buffer, size_t index) const
2119{
2120 return blpapi_Element_getValueAsFloat32(d_handle_p, buffer, index);
2121}
2122
2123inline int Element::getValueAs(Float64 *buffer, size_t index) const
2124{
2125 return blpapi_Element_getValueAsFloat64(d_handle_p, buffer, index);
2126}
2127
2128inline int Element::getValueAs(Datetime *buffer, size_t index) const
2129{
2131 d_handle_p, buffer, index);
2132}
2133
2134inline int Element::getValueAs(std::string *result, size_t index) const
2135{
2136 assert(result);
2137
2138 const char *buffer = 0;
2139 int rc = blpapi_Element_getValueAsString(d_handle_p, &buffer, index);
2140 if (!rc) {
2141 *result = buffer;
2142 }
2143 return rc;
2144}
2145
2146inline int Element::getValueAs(Bytes *result, size_t index) const
2147{
2148 assert(result);
2149
2150 const char *buffer = 0;
2151 size_t length = 0;
2153 d_handle_p, &buffer, &length, index);
2154 if (!rc) {
2155 result->assign(buffer, length);
2156 }
2157 return rc;
2158}
2159
2160inline int Element::getValueAs(Element *buffer, size_t index) const
2161{
2162 assert(buffer);
2163
2165 d_handle_p, &buffer->d_handle_p, index);
2166}
2167
2168inline int Element::getValueAs(Name *buffer, size_t index) const
2169{
2170 assert(buffer);
2171
2172 blpapi_Name_t *tmpName = 0;
2173 int res = blpapi_Element_getValueAsName(d_handle_p, &tmpName, index);
2174 if (!res) {
2175 *buffer = Name(tmpName);
2176 }
2177 return res;
2178}
2179
2180inline bool Element::getValueAsBool(size_t index) const
2181{
2182 bool value = false;
2184 return value;
2185}
2186
2187inline char Element::getValueAsChar(size_t index) const
2188{
2189 char value = 0;
2191 return value;
2192}
2193
2194inline Int32 Element::getValueAsInt32(size_t index) const
2195{
2196 Int32 value = 0;
2198 return value;
2199}
2200
2201inline Int64 Element::getValueAsInt64(size_t index) const
2202{
2203 Int64 value = 0;
2205 return value;
2206}
2207
2208inline Float32 Element::getValueAsFloat32(size_t index) const
2209{
2210 Float32 value = 0.0;
2212 return value;
2213}
2214
2215inline Float64 Element::getValueAsFloat64(size_t index) const
2216{
2217 Float64 value = 0.0;
2219 return value;
2220}
2221
2222inline Datetime Element::getValueAsDatetime(size_t index) const
2223{
2224 Datetime value;
2226 return value;
2227}
2228
2229inline const char *Element::getValueAsString(size_t index) const
2230{
2231 const char *tmpStringBuffer = 0;
2233 d_handle_p, &tmpStringBuffer, index));
2234 return tmpStringBuffer;
2235}
2236
2237inline Bytes Element::getValueAsBytes(size_t index) const
2238{
2239 Bytes value;
2241 return value;
2242}
2243
2244inline Element Element::getValueAsElement(size_t index) const
2245{
2246 blpapi_Element_t *element = 0;
2248 blpapi_Element_getValueAsElement(d_handle_p, &element, index));
2249 return Element(element);
2250}
2251
2252inline Name Element::getValueAsName(size_t index) const
2253{
2254 blpapi_Name_t *nameValue = 0;
2256 blpapi_Element_getValueAsName(d_handle_p, &nameValue, index));
2257 return Name(nameValue);
2258}
2259
2261{
2262 blpapi_Element_t *element = 0;
2264 blpapi_Element_getChoice(d_handle_p, &element));
2265 return Element(element);
2266}
2267
2268inline bool Element::getElementAsBool(const char *elementName) const
2269{
2270 return getElement(Name(elementName)).getValueAsBool();
2271}
2272
2273inline bool Element::getElementAsBool(const Name& elementName) const
2274{
2275 return getElement(elementName).getValueAsBool();
2276}
2277
2278inline char Element::getElementAsChar(const char *elementName) const
2279{
2280 return getElement(Name(elementName)).getValueAsChar();
2281}
2282
2283inline char Element::getElementAsChar(const Name& elementName) const
2284{
2285 return getElement(elementName).getValueAsChar();
2286}
2287
2288inline Int32 Element::getElementAsInt32(const char *elementName) const
2289{
2290 return getElement(Name(elementName)).getValueAsInt32();
2291}
2292
2293inline Int32 Element::getElementAsInt32(const Name& elementName) const
2294{
2295 return getElement(elementName).getValueAsInt32();
2296}
2297
2298inline Int64 Element::getElementAsInt64(const char *elementName) const
2299{
2300 return getElement(Name(elementName)).getValueAsInt64();
2301}
2302
2303inline Int64 Element::getElementAsInt64(const Name& elementName) const
2304{
2305 return getElement(elementName).getValueAsInt64();
2306}
2307
2308inline Float32 Element::getElementAsFloat32(const char *elementName) const
2309{
2310 return getElement(Name(elementName)).getValueAsFloat32();
2311}
2312
2313inline Float32 Element::getElementAsFloat32(const Name& elementName) const
2314{
2315 return getElement(elementName).getValueAsFloat32();
2316}
2317
2318inline Float64 Element::getElementAsFloat64(const char *elementName) const
2319{
2320 return getElement(Name(elementName)).getValueAsFloat64();
2321}
2322
2323inline Float64 Element::getElementAsFloat64(const Name& elementName) const
2324{
2325 return getElement(elementName).getValueAsFloat64();
2326}
2327
2328inline Datetime Element::getElementAsDatetime(const char *elementName) const
2329{
2330 return getElement(Name(elementName)).getValueAsDatetime();
2331}
2332
2333inline Datetime Element::getElementAsDatetime(const Name& elementName) const
2334{
2335 return getElement(elementName).getValueAsDatetime();
2336}
2337
2338inline const char *Element::getElementAsString(const char *elementName) const
2339{
2340 return getElement(Name(elementName)).getValueAsString();
2341}
2342
2343inline const char *Element::getElementAsString(const Name& elementName) const
2344{
2345 return getElement(elementName).getValueAsString();
2346}
2347
2348inline Bytes Element::getElementAsBytes(const Name& elementName) const
2349{
2350 return getElement(elementName).getValueAsBytes();
2351}
2352
2353inline Name Element::getElementAsName(const char *elementName) const
2354{
2355 return getElement(Name(elementName)).getValueAsName();
2356}
2357
2358inline Name Element::getElementAsName(const Name& elementName) const
2359{
2360 return getElement(elementName).getValueAsName();
2361}
2362
2363inline const blpapi_Element_t *Element::handle() const { return d_handle_p; }
2364
2365inline std::ostream& Element::print(
2366 std::ostream& stream, int level, int spacesPerLevel) const
2367{
2368 blpapi_Element_print(d_handle_p,
2370 &stream,
2371 level,
2372 spacesPerLevel);
2373 return stream;
2374}
2375
2376inline std::string Element::toJson() const
2377{
2378 std::ostringstream stream;
2380 d_handle_p, StreamProxyOstream::writeToStream, &stream));
2381 return stream.str();
2382}
2383
2384inline void Element::fromJson(const char *json)
2385{
2387}
2388
2389inline void Element::fromJson(const std::string& json)
2390{
2391 fromJson(json.c_str());
2392}
2393
2394inline std::ostream& operator<<(std::ostream& stream, const Element& element)
2395{
2396 element.print(stream, 0, -1);
2397 return stream;
2398}
2399
2400} // close namespace blpapi
2401} // close namespace BloombergLP
2402
2403#endif // #ifdef __cplusplus
2404#endif // #ifndef INCLUDED_BLPAPI_ELEMENT
Provide functions for dispatchtbl.
#define BLPAPI_CALL_ELEMENT_GETVALUEASHIGHPRECISIONDATETIME(a1, a2, a3)
Definition blpapi_call.h:403
#define BLPAPI_CALL_ELEMENT_SETELEMENTHIGHPRECISIONDATETIME(a1, a2, a3, a4)
Definition blpapi_call.h:401
#define BLPAPI_CALL_ELEMENT_SETVALUEHIGHPRECISIONDATETIME(a1, a2, a3)
Definition blpapi_call.h:399
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:353
Represents a date and/or time.
Common definitions used by the library.
#define BLPAPI_EXPORT
Definition blpapi_defs.h:172
#define BLPAPI_ELEMENT_INDEX_END
Definition blpapi_defs.h:97
BLPAPI_EXPORT int blpapi_Element_setValueHighPrecisionDatetime(blpapi_Element_t *element, const blpapi_HighPrecisionDatetime_t *value, size_t index)
BLPAPI_EXPORT int blpapi_Element_getValueAsInt32(const blpapi_Element_t *element, blpapi_Int32_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_setValueFromName(blpapi_Element_t *element, const blpapi_Name_t *value, size_t index)
BLPAPI_EXPORT int blpapi_Element_datatype(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_setElementHighPrecisionDatetime(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const blpapi_HighPrecisionDatetime_t *value)
BLPAPI_EXPORT blpapi_Name_t * blpapi_Element_name(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_setValueFromElement(blpapi_Element_t *element, blpapi_Element_t *value, size_t index)
BLPAPI_EXPORT int blpapi_Element_setElementFromField(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Element_t *sourcebuffer)
BLPAPI_EXPORT int blpapi_Element_setElementFromName(blpapi_Element_t *element, const char *elementName, const blpapi_Name_t *name, const blpapi_Name_t *buffer)
BLPAPI_EXPORT int blpapi_Element_appendElement(blpapi_Element_t *element, blpapi_Element_t **appendedElement)
BLPAPI_EXPORT size_t blpapi_Element_numValues(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_getValueAsFloat64(const blpapi_Element_t *element, blpapi_Float64_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_setValueString(blpapi_Element_t *element, const char *value, size_t index)
BLPAPI_EXPORT int blpapi_Element_isReadOnly(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_setElementInt32(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Int32_t value)
BLPAPI_EXPORT size_t blpapi_Element_numElements(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_setValueInt32(blpapi_Element_t *element, blpapi_Int32_t value, size_t index)
BLPAPI_EXPORT const char * blpapi_Element_nameString(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_setElementChar(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Char_t value)
BLPAPI_EXPORT int blpapi_Element_getElement(const blpapi_Element_t *element, blpapi_Element_t **result, const char *nameString, const blpapi_Name_t *name)
BLPAPI_EXPORT int blpapi_Element_setValueFloat32(blpapi_Element_t *element, blpapi_Float32_t value, size_t index)
BLPAPI_EXPORT int blpapi_Element_setValueBytes(blpapi_Element_t *element, const char *value, size_t length, size_t index)
BLPAPI_EXPORT int blpapi_Element_isNull(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_setElementBytes(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const char *value, size_t length)
BLPAPI_EXPORT int blpapi_Element_isComplexType(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_getValueAsString(const blpapi_Element_t *element, const char **buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_setValueChar(blpapi_Element_t *element, blpapi_Char_t value, size_t index)
BLPAPI_EXPORT int blpapi_Element_getValueAsDatetime(const blpapi_Element_t *element, blpapi_Datetime_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_setElementString(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const char *value)
BLPAPI_EXPORT int blpapi_Element_setValueBool(blpapi_Element_t *element, blpapi_Bool_t value, size_t index)
BLPAPI_EXPORT int blpapi_Element_getValueAsChar(const blpapi_Element_t *element, blpapi_Char_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_getElementAt(const blpapi_Element_t *element, blpapi_Element_t **result, size_t position)
BLPAPI_EXPORT int blpapi_Element_getValueAsBool(const blpapi_Element_t *element, blpapi_Bool_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_setElementInt64(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Int64_t value)
BLPAPI_EXPORT int blpapi_Element_getValueAsFloat32(const blpapi_Element_t *element, blpapi_Float32_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_hasElementEx(const blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, int excludeNullElements, int reserved)
BLPAPI_EXPORT int blpapi_Element_setElementBool(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Bool_t value)
BLPAPI_EXPORT int blpapi_Element_setValueInt64(blpapi_Element_t *element, blpapi_Int64_t value, size_t index)
BLPAPI_EXPORT int blpapi_Element_isArray(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_getChoice(const blpapi_Element_t *element, blpapi_Element_t **result)
BLPAPI_EXPORT int blpapi_Element_setElementFloat64(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Float64_t value)
BLPAPI_EXPORT int blpapi_Element_print(const blpapi_Element_t *element, blpapi_StreamWriter_t streamWriter, void *stream, int level, int spacesPerLevel)
BLPAPI_EXPORT int blpapi_Element_setElementDatetime(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const blpapi_Datetime_t *value)
BLPAPI_EXPORT int blpapi_Element_getValueAsElement(const blpapi_Element_t *element, blpapi_Element_t **buffer, size_t index)
BLPAPI_EXPORT blpapi_SchemaElementDefinition_t * blpapi_Element_definition(const blpapi_Element_t *element)
BLPAPI_EXPORT int blpapi_Element_hasElement(const blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name)
BLPAPI_EXPORT int blpapi_Element_getValueAsHighPrecisionDatetime(const blpapi_Element_t *element, blpapi_HighPrecisionDatetime_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_getValueAsName(const blpapi_Element_t *element, blpapi_Name_t **buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_getValueAsInt64(const blpapi_Element_t *element, blpapi_Int64_t *buffer, size_t index)
BLPAPI_EXPORT int blpapi_Element_setChoice(blpapi_Element_t *element, blpapi_Element_t **resultElement, const char *nameCstr, const blpapi_Name_t *name, size_t index)
BLPAPI_EXPORT int blpapi_Element_setValueFloat64(blpapi_Element_t *element, blpapi_Float64_t value, size_t index)
BLPAPI_EXPORT int blpapi_Element_setElementFloat32(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Float32_t value)
BLPAPI_EXPORT int blpapi_Element_getValueAsBytes(const blpapi_Element_t *element, const char **buffer, size_t *length, size_t index)
BLPAPI_EXPORT int blpapi_Element_fromJson(const blpapi_Element_t *element, char const *json)
BLPAPI_EXPORT int blpapi_Element_isNullValue(const blpapi_Element_t *element, size_t position)
BLPAPI_EXPORT int blpapi_Element_setValueDatetime(blpapi_Element_t *element, const blpapi_Datetime_t *value, size_t index)
BLPAPI_EXPORT int blpapi_Element_toJson(const blpapi_Element_t *element, blpapi_StreamWriter_t streamWriter, void *stream)
Defines Exceptions that can be thrown by the blpapi library.
Provide a representation of strings for use as container keys.
Provide a representation of a schema describing structured messages.
A signature for callback on print and default C++ implementation.
int(* blpapi_StreamWriter_t)(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:53
Provide BLPAPI types.
int blpapi_Bool_t
Definition blpapi_types.h:62
char blpapi_Char_t
Definition blpapi_types.h:63
float blpapi_Float32_t
Definition blpapi_types.h:71
long long blpapi_Int64_t
Definition blpapi_types.h:69
int blpapi_Int32_t
Definition blpapi_types.h:67
double blpapi_Float64_t
Definition blpapi_types.h:72
Definition blpapi_types.h:312
void assign(pointer ptr, size_type length) noexcept
Definition blpapi_types.h:496
Definition blpapi_datetime.h:245
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition blpapi_datetime.h:1954
Definition blpapi_element.h:473
BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(const char *name) const
Definition blpapi_element.h:2328
Name name() const
Definition blpapi_element.h:1943
void rebind(blpapi_Element_t *element)
Definition blpapi_element.h:1640
int getValueAs(bool *result, size_t index=0) const
Definition blpapi_element.h:2092
BLPAPI_DEPRECATE_STRING_NAME Element setChoice(const char *selectionName)
Definition blpapi_element.h:1925
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_element.h:2348
bool isNullValue(size_t position=0) const
Definition blpapi_element.h:2030
BLPAPI_DEPRECATE_STRING_NAME int getElement(Element *result, const char *name) const
Definition blpapi_element.h:1948
Float64 getValueAsFloat64(size_t index=0) const
Definition blpapi_element.h:2215
Element getValueAsElement(size_t index=0) const
Definition blpapi_element.h:2244
Name getValueAsName(size_t index=0) const
Definition blpapi_element.h:2252
int datatype() const
Definition blpapi_element.h:1988
BLPAPI_DEPRECATE_STRING_NAME Name getElementAsName(const char *name) const
Definition blpapi_element.h:2353
Int64 getValueAsInt64(size_t index=0) const
Definition blpapi_element.h:2201
Bytes getValueAsBytes(size_t index=0) const
Definition blpapi_element.h:2237
blpapi_Element_t * handle()
Definition blpapi_element.h:1941
BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(const char *name) const
Definition blpapi_element.h:2318
size_t numValues() const
Definition blpapi_element.h:2018
bool isReadOnly() const
Definition blpapi_element.h:2008
BLPAPI_DEPRECATE_STRING_NAME bool hasElement(const char *name, bool excludeNullElements=false) const
Definition blpapi_element.h:2039
void appendValue(bool value)
Definition blpapi_element.h:1856
bool isValid() const
Definition blpapi_element.h:2028
BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const
Definition blpapi_element.h:2268
bool getValueAsBool(size_t index=0) const
Definition blpapi_element.h:2180
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_element.h:2365
void setValue(bool value, size_t index=0)
Definition blpapi_element.h:1783
BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const
Definition blpapi_element.h:2278
Element appendElement()
Definition blpapi_element.h:1917
const char * getValueAsString(size_t index=0) const
Definition blpapi_element.h:2229
bool isComplexType() const
Definition blpapi_element.h:1993
char getValueAsChar(size_t index=0) const
Definition blpapi_element.h:2187
BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, bool value)
Definition blpapi_element.h:1645
std::string toJson() const
Definition blpapi_element.h:2376
void fromJson(const char *json)
Definition blpapi_element.h:2384
Element()
Definition blpapi_element.h:1630
Datetime getValueAsDatetime(size_t index=0) const
Definition blpapi_element.h:2222
bool isNull() const
Definition blpapi_element.h:2003
SchemaElementDefinition elementDefinition() const
Definition blpapi_element.h:2013
BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(const char *name) const
Definition blpapi_element.h:2298
BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(const char *name) const
Definition blpapi_element.h:2288
Element getChoice() const
Definition blpapi_element.h:2260
Float32 getValueAsFloat32(size_t index=0) const
Definition blpapi_element.h:2208
bool isArray() const
Definition blpapi_element.h:1998
Int32 getValueAsInt32(size_t index=0) const
Definition blpapi_element.h:2194
BLPAPI_DEPRECATE_STRING_NAME const char * getElementAsString(const char *name) const
Definition blpapi_element.h:2338
BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(const char *name) const
Definition blpapi_element.h:2308
size_t numElements() const
Definition blpapi_element.h:2023
static void throwOnError(int errorCode)
Definition blpapi_exception.h:526
Definition blpapi_name.h:150
blpapi_Name_t * impl() const
Definition blpapi_name.h:403
Definition blpapi_schema.h:327
struct blpapi_Name blpapi_Name_t
Definition blpapi_types.h:154
struct blpapi_SchemaElementDefinition blpapi_SchemaElementDefinition_t
Definition blpapi_types.h:191
struct blpapi_Element blpapi_Element_t
Definition blpapi_types.h:136
blpapi_Float64_t Float64
Definition blpapi_types.h:474
blpapi_Float32_t Float32
Definition blpapi_types.h:473
blpapi_Int64_t Int64
Definition blpapi_types.h:471
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:649
blpapi_Int32_t Int32
Definition blpapi_types.h:469
Definition blpapi_abstractsession.h:195
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:93
Definition blpapi_datetime.h:102
Definition blpapi_datetime.h:115