BLPAPI C++ 3.25.12
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;
1103 int getValueAs(bool *result, size_t index = 0) const;
1112 int getValueAs(char *result, size_t index = 0) const;
1121 int getValueAs(Int32 *result, size_t index = 0) const;
1130 int getValueAs(Int64 *result, size_t index = 0) const;
1139 int getValueAs(Float32 *result, size_t index = 0) const;
1148 int getValueAs(Float64 *result, size_t index = 0) const;
1157 int getValueAs(Datetime *result, size_t index = 0) const;
1169 int getValueAs(std::string *result, size_t index = 0) const;
1178 int getValueAs(Bytes *result, size_t index = 0) const;
1186 int getValueAs(Element *result, size_t index = 0) const;
1195 int getValueAs(Name *result, size_t index = 0) const;
1203 bool getValueAsBool(size_t index = 0) const;
1210 char getValueAsChar(size_t index = 0) const;
1217 Int32 getValueAsInt32(size_t index = 0) const;
1224 Int64 getValueAsInt64(size_t index = 0) const;
1231 Float32 getValueAsFloat32(size_t index = 0) const;
1238 Float64 getValueAsFloat64(size_t index = 0) const;
1245 Datetime getValueAsDatetime(size_t index = 0) const;
1256 const char *getValueAsString(size_t index = 0) const;
1265 Bytes getValueAsBytes(size_t index = 0) const;
1273 Element getValueAsElement(size_t index = 0) const;
1281 Name getValueAsName(size_t index = 0) const;
1288 BLPAPI_DEPRECATE_STRING_NAME int getElement(
1289 Element *result, const char *name) const;
1300 int getElement(Element *result, const Name& name) const;
1309 int getElement(Element *result, size_t position) const;
1318 Element getElement(size_t position) const;
1326 Element getElement(const Name& name) const;
1334 BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name) const;
1345 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
1356 bool getElementAsBool(const Name& name) const;
1365 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
1376 char getElementAsChar(const Name& name) const;
1385 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
1386 const char *name) const;
1397 Int32 getElementAsInt32(const Name& name) const;
1406 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
1407 const char *name) const;
1418 Int64 getElementAsInt64(const Name& name) const;
1427 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
1428 const char *name) const;
1439 Float32 getElementAsFloat32(const Name& name) const;
1448 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
1449 const char *name) const;
1460 Float64 getElementAsFloat64(const Name& name) const;
1469 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
1470 const char *name) const;
1485 Datetime getElementAsDatetime(const Name& name) const;
1497 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
1498 const char *name) const;
1510 const char *getElementAsString(const Name& name) const;
1520 Bytes getElementAsBytes(const Name& name) const;
1530 BLPAPI_DEPRECATE_STRING_NAME Name getElementAsName(const char *name) const;
1541 Name getElementAsName(const Name& name) const;
1550 Element getChoice() const;
1556 const blpapi_Element_t *handle() const;
1557
1558 std::ostream& print(
1559 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
1573 std::string toJson() const;
1580 void fromJson(const char *json);
1590 void fromJson(const std::string& json);
1600};
1601
1605// FREE OPERATORS
1606std::ostream& operator<<(std::ostream& stream, const Element& element);
1620// ============================================================================
1621// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
1622// ============================================================================
1623
1624// -------------
1625// class Element
1626// -------------
1627
1629 : d_handle_p(0)
1630{
1631}
1632
1634 : d_handle_p(newHandle)
1635{
1636}
1637
1639{
1640 d_handle_p = element;
1641}
1642
1643inline void Element::setElement(const char *elementName, bool value)
1644{
1646 d_handle_p, elementName, 0, value ? 1 : 0));
1647}
1648
1649inline void Element::setElement(const char *elementName, char value)
1650{
1652 blpapi_Element_setElementChar(d_handle_p, elementName, 0, value));
1653}
1654
1655inline void Element::setElement(const char *elementName, Int32 value)
1656{
1658 blpapi_Element_setElementInt32(d_handle_p, elementName, 0, value));
1659}
1660
1661inline void Element::setElement(const char *elementName, Int64 value)
1662{
1664 blpapi_Element_setElementInt64(d_handle_p, elementName, 0, value));
1665}
1666
1667inline void Element::setElement(const char *elementName, Float32 value)
1668{
1670 d_handle_p, elementName, 0, value));
1671}
1672
1673inline void Element::setElement(const char *elementName, Float64 value)
1674{
1676 d_handle_p, elementName, 0, value));
1677}
1678
1679inline void Element::setElement(const char *elementName, const Datetime& value)
1680{
1683 elementName,
1684 0,
1685 &value.rawHighPrecisionValue()));
1686}
1687
1688inline void Element::setElement(const char *elementName, const char *value)
1689{
1691 d_handle_p, elementName, 0, value));
1692}
1693
1694inline void Element::setElement(const char *elementName, const Name& value)
1695{
1697 d_handle_p, elementName, 0, value.impl()));
1698}
1699
1700inline void Element::setElement(const Name& elementName, bool value)
1701{
1703 d_handle_p, 0, elementName.impl(), value ? 1 : 0));
1704}
1705
1706inline void Element::setElement(const Name& elementName, char value)
1707{
1709 d_handle_p, 0, elementName.impl(), value));
1710}
1711
1712inline void Element::setElement(const Name& elementName, Int32 value)
1713{
1715 d_handle_p, 0, elementName.impl(), value));
1716}
1717
1718inline void Element::setElement(const Name& elementName, Int64 value)
1719{
1721 d_handle_p, 0, elementName.impl(), value));
1722}
1723
1724inline void Element::setElement(const Name& elementName, Float32 value)
1725{
1727 d_handle_p, 0, elementName.impl(), value));
1728}
1729
1730inline void Element::setElement(const Name& elementName, Float64 value)
1731{
1733 d_handle_p, 0, elementName.impl(), value));
1734}
1735
1736inline void Element::setElement(const Name& elementName, const Datetime& value)
1737{
1740 0,
1741 elementName.impl(),
1742 &value.rawHighPrecisionValue()));
1743}
1744
1745inline void Element::setElement(const Name& elementName, const char *value)
1746{
1748 d_handle_p, 0, elementName.impl(), value));
1749}
1750
1752 const Name& elementName, const std::string& value)
1753{
1754 setElement(elementName, value.c_str());
1755}
1756
1757inline void Element::setElement(const Name& elementName, const Name& value)
1758{
1760 d_handle_p, 0, elementName.impl(), value.impl()));
1761}
1762
1764 const Name& elementName, const void *value, size_t length)
1765{
1768 0,
1769 elementName.impl(),
1770 reinterpret_cast<const char *>(value),
1771 length));
1772}
1773
1774template <typename BYTES,
1775 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1776inline void Element::setElement(const Name& elementName, const BYTES& value)
1777{
1778 setElement(elementName, value.data(), value.size());
1779}
1780
1781inline void Element::setValue(bool value, size_t index)
1782{
1784 blpapi_Element_setValueBool(d_handle_p, value, index));
1785}
1786
1787inline void Element::setValue(char value, size_t index)
1788{
1790 blpapi_Element_setValueChar(d_handle_p, value, index));
1791}
1792
1793inline void Element::setValue(Int32 value, size_t index)
1794{
1796 blpapi_Element_setValueInt32(d_handle_p, value, index));
1797}
1798
1799inline void Element::setValue(Int64 value, size_t index)
1800{
1802 blpapi_Element_setValueInt64(d_handle_p, value, index));
1803}
1804
1805inline void Element::setValue(Float32 value, size_t index)
1806{
1808 blpapi_Element_setValueFloat32(d_handle_p, value, index));
1809}
1810
1811inline void Element::setValue(Float64 value, size_t index)
1812{
1814 blpapi_Element_setValueFloat64(d_handle_p, value, index));
1815}
1816
1817inline void Element::setValue(const Datetime& value, size_t index)
1818{
1821 d_handle_p, &value.rawHighPrecisionValue(), index));
1822}
1823
1824inline void Element::setValue(const char *value, size_t index)
1825{
1827 blpapi_Element_setValueString(d_handle_p, value, index));
1828}
1829
1830inline void Element::setValue(const std::string& value, size_t index)
1831{
1832 setValue(value.c_str(), index);
1833}
1834
1835inline void Element::setValue(const Name& valueName, size_t index)
1836{
1838 d_handle_p, valueName.impl(), index));
1839}
1840
1841inline void Element::setValue(const void *value, size_t length, size_t index)
1842{
1844 d_handle_p, reinterpret_cast<const char *>(value), length, index));
1845}
1846
1847template <typename BYTES,
1848 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1849inline void Element::setValue(const BYTES& value, size_t index)
1850{
1851 setValue(value.data(), value.size(), index);
1852}
1853
1854inline void Element::appendValue(bool value)
1855{
1857 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1858}
1859
1860inline void Element::appendValue(char value)
1861{
1863 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1864}
1865
1871
1877
1883
1889
1897
1898inline void Element::appendValue(const char *value)
1899{
1901 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1902}
1903
1904inline void Element::appendValue(const std::string& value)
1905{
1906 appendValue(value.c_str());
1907}
1908
1909inline void Element::appendValue(const Name& valueName)
1910{
1912 d_handle_p, valueName.impl(), BLPAPI_ELEMENT_INDEX_END));
1913}
1914
1916{
1917 blpapi_Element_t *appendedElement = 0;
1919 blpapi_Element_appendElement(d_handle_p, &appendedElement));
1920 return Element(appendedElement);
1921}
1922
1923inline Element Element::setChoice(const char *selectionName)
1924{
1925 blpapi_Element_t *resultElement = 0;
1927 d_handle_p, &resultElement, selectionName, 0, 0));
1928 return Element(resultElement);
1929}
1930
1931inline Element Element::setChoice(const Name& selectionName)
1932{
1933 blpapi_Element_t *resultElement = 0;
1935 d_handle_p, &resultElement, 0, selectionName.impl(), 0));
1936 return Element(resultElement);
1937}
1938
1939inline blpapi_Element_t *Element::handle() { return d_handle_p; }
1940
1941inline Name Element::name() const
1942{
1943 return Name(blpapi_Element_name(d_handle_p));
1944}
1945
1946inline int Element::getElement(Element *element, const char *nameString) const
1947{
1948 assert(element);
1949
1950 blpapi_Element_t *fldt = 0;
1951 int rc = blpapi_Element_getElement(d_handle_p, &fldt, nameString, 0);
1952 if (!rc) {
1953 element->rebind(fldt);
1954 }
1955
1956 return rc;
1957}
1958
1959inline int Element::getElement(Element *element, const Name& elementName) const
1960{
1961 assert(element);
1962
1963 blpapi_Element_t *fldt = 0;
1965 d_handle_p, &fldt, 0, elementName.impl());
1966 if (!rc) {
1967 element->rebind(fldt);
1968 }
1969
1970 return rc;
1971}
1972
1973inline int Element::getElement(Element *element, size_t position) const
1974{
1975 assert(element);
1976
1977 blpapi_Element_t *fldt = 0;
1978 int rc = blpapi_Element_getElementAt(d_handle_p, &fldt, position);
1979 if (!rc) {
1980 element->rebind(fldt);
1981 }
1982
1983 return rc;
1984}
1985
1986inline int Element::datatype() const
1987{
1988 return blpapi_Element_datatype(d_handle_p);
1989}
1990
1991inline bool Element::isComplexType() const
1992{
1993 return blpapi_Element_isComplexType(d_handle_p) ? true : false;
1994}
1995
1996inline bool Element::isArray() const
1997{
1998 return blpapi_Element_isArray(d_handle_p) ? true : false;
1999}
2000
2001inline bool Element::isNull() const
2002{
2003 return blpapi_Element_isNull(d_handle_p) ? true : false;
2004}
2005
2006inline bool Element::isReadOnly() const
2007{
2008 return blpapi_Element_isReadOnly(d_handle_p) ? true : false;
2009}
2010
2015
2016inline size_t Element::numValues() const
2017{
2018 return blpapi_Element_numValues(d_handle_p);
2019}
2020
2021inline size_t Element::numElements() const
2022{
2023 return blpapi_Element_numElements(d_handle_p);
2024}
2025
2026inline bool Element::isValid() const { return d_handle_p ? true : false; }
2027
2028inline bool Element::isNullValue(size_t position) const
2029{
2030 int rc = blpapi_Element_isNullValue(d_handle_p, position);
2031 if (rc != 0 && rc != 1) {
2033 }
2034 return rc ? true : false;
2035}
2036
2038 const char *nameString, bool excludeNullElements) const
2039{
2040 if (excludeNullElements) {
2042 d_handle_p, nameString, 0, excludeNullElements, 0)
2043 ? true
2044 : false);
2045 }
2046 return blpapi_Element_hasElement(d_handle_p, nameString, 0) ? true : false;
2047}
2048
2050 const Name& elementName, bool excludeNullElements) const
2051{
2052 if (excludeNullElements) {
2053 return (blpapi_Element_hasElementEx(d_handle_p,
2054 0,
2055 elementName.impl(),
2056 excludeNullElements,
2057 0)
2058 ? true
2059 : false);
2060 }
2061 return blpapi_Element_hasElement(d_handle_p, 0, elementName.impl())
2062 ? true
2063 : false;
2064}
2065
2066inline Element Element::getElement(const Name& elementName) const
2067{
2068 blpapi_Element_t *fldt = 0;
2070 d_handle_p, &fldt, 0, elementName.impl()));
2071 return Element(fldt);
2072}
2073
2074inline Element Element::getElement(const char *elementName) const
2075{
2076 blpapi_Element_t *fldt = 0;
2078 blpapi_Element_getElement(d_handle_p, &fldt, elementName, 0));
2079 return Element(fldt);
2080}
2081
2082inline Element Element::getElement(size_t position) const
2083{
2084 blpapi_Element_t *element = 0;
2086 blpapi_Element_getElementAt(d_handle_p, &element, position));
2087 return Element(element);
2088}
2089
2090inline int Element::getValueAs(bool *buffer, size_t index) const
2091{
2092 assert(buffer);
2093
2094 blpapi_Bool_t tmp = false;
2095
2096 int res = blpapi_Element_getValueAsBool(d_handle_p, &tmp, index);
2097 *buffer = tmp ? true : false;
2098 return res;
2099}
2100
2101inline int Element::getValueAs(char *buffer, size_t index) const
2102{
2103 return blpapi_Element_getValueAsChar(d_handle_p, buffer, index);
2104}
2105
2106inline int Element::getValueAs(Int32 *buffer, size_t index) const
2107{
2108 return blpapi_Element_getValueAsInt32(d_handle_p, buffer, index);
2109}
2110
2111inline int Element::getValueAs(Int64 *buffer, size_t index) const
2112{
2113 return blpapi_Element_getValueAsInt64(d_handle_p, buffer, index);
2114}
2115
2116inline int Element::getValueAs(Float32 *buffer, size_t index) const
2117{
2118 return blpapi_Element_getValueAsFloat32(d_handle_p, buffer, index);
2119}
2120
2121inline int Element::getValueAs(Float64 *buffer, size_t index) const
2122{
2123 return blpapi_Element_getValueAsFloat64(d_handle_p, buffer, index);
2124}
2125
2126inline int Element::getValueAs(Datetime *buffer, size_t index) const
2127{
2129 d_handle_p, buffer, index);
2130}
2131
2132inline int Element::getValueAs(std::string *result, size_t index) const
2133{
2134 assert(result);
2135
2136 const char *buffer = 0;
2137 int rc = blpapi_Element_getValueAsString(d_handle_p, &buffer, index);
2138 if (!rc) {
2139 *result = buffer;
2140 }
2141 return rc;
2142}
2143
2144inline int Element::getValueAs(Bytes *result, size_t index) const
2145{
2146 assert(result);
2147
2148 const char *buffer = 0;
2149 size_t length = 0;
2151 d_handle_p, &buffer, &length, index);
2152 if (!rc) {
2153 result->assign(buffer, length);
2154 }
2155 return rc;
2156}
2157
2158inline int Element::getValueAs(Element *buffer, size_t index) const
2159{
2160 assert(buffer);
2161
2163 d_handle_p, &buffer->d_handle_p, index);
2164}
2165
2166inline int Element::getValueAs(Name *buffer, size_t index) const
2167{
2168 assert(buffer);
2169
2170 blpapi_Name_t *tmpName = 0;
2171 int res = blpapi_Element_getValueAsName(d_handle_p, &tmpName, index);
2172 if (!res) {
2173 *buffer = Name(tmpName);
2174 }
2175 return res;
2176}
2177
2178inline bool Element::getValueAsBool(size_t index) const
2179{
2180 bool value = false;
2182 return value;
2183}
2184
2185inline char Element::getValueAsChar(size_t index) const
2186{
2187 char value = 0;
2189 return value;
2190}
2191
2192inline Int32 Element::getValueAsInt32(size_t index) const
2193{
2194 Int32 value = 0;
2196 return value;
2197}
2198
2199inline Int64 Element::getValueAsInt64(size_t index) const
2200{
2201 Int64 value = 0;
2203 return value;
2204}
2205
2206inline Float32 Element::getValueAsFloat32(size_t index) const
2207{
2208 Float32 value = 0.0;
2210 return value;
2211}
2212
2213inline Float64 Element::getValueAsFloat64(size_t index) const
2214{
2215 Float64 value = 0.0;
2217 return value;
2218}
2219
2220inline Datetime Element::getValueAsDatetime(size_t index) const
2221{
2222 Datetime value;
2224 return value;
2225}
2226
2227inline const char *Element::getValueAsString(size_t index) const
2228{
2229 const char *tmpStringBuffer = 0;
2231 d_handle_p, &tmpStringBuffer, index));
2232 return tmpStringBuffer;
2233}
2234
2235inline Bytes Element::getValueAsBytes(size_t index) const
2236{
2237 Bytes value;
2239 return value;
2240}
2241
2242inline Element Element::getValueAsElement(size_t index) const
2243{
2244 blpapi_Element_t *element = 0;
2246 blpapi_Element_getValueAsElement(d_handle_p, &element, index));
2247 return Element(element);
2248}
2249
2250inline Name Element::getValueAsName(size_t index) const
2251{
2252 blpapi_Name_t *nameValue = 0;
2254 blpapi_Element_getValueAsName(d_handle_p, &nameValue, index));
2255 return Name(nameValue);
2256}
2257
2259{
2260 blpapi_Element_t *element = 0;
2262 blpapi_Element_getChoice(d_handle_p, &element));
2263 return Element(element);
2264}
2265
2266inline bool Element::getElementAsBool(const char *elementName) const
2267{
2268 return getElement(Name(elementName)).getValueAsBool();
2269}
2270
2271inline bool Element::getElementAsBool(const Name& elementName) const
2272{
2273 return getElement(elementName).getValueAsBool();
2274}
2275
2276inline char Element::getElementAsChar(const char *elementName) const
2277{
2278 return getElement(Name(elementName)).getValueAsChar();
2279}
2280
2281inline char Element::getElementAsChar(const Name& elementName) const
2282{
2283 return getElement(elementName).getValueAsChar();
2284}
2285
2286inline Int32 Element::getElementAsInt32(const char *elementName) const
2287{
2288 return getElement(Name(elementName)).getValueAsInt32();
2289}
2290
2291inline Int32 Element::getElementAsInt32(const Name& elementName) const
2292{
2293 return getElement(elementName).getValueAsInt32();
2294}
2295
2296inline Int64 Element::getElementAsInt64(const char *elementName) const
2297{
2298 return getElement(Name(elementName)).getValueAsInt64();
2299}
2300
2301inline Int64 Element::getElementAsInt64(const Name& elementName) const
2302{
2303 return getElement(elementName).getValueAsInt64();
2304}
2305
2306inline Float32 Element::getElementAsFloat32(const char *elementName) const
2307{
2308 return getElement(Name(elementName)).getValueAsFloat32();
2309}
2310
2311inline Float32 Element::getElementAsFloat32(const Name& elementName) const
2312{
2313 return getElement(elementName).getValueAsFloat32();
2314}
2315
2316inline Float64 Element::getElementAsFloat64(const char *elementName) const
2317{
2318 return getElement(Name(elementName)).getValueAsFloat64();
2319}
2320
2321inline Float64 Element::getElementAsFloat64(const Name& elementName) const
2322{
2323 return getElement(elementName).getValueAsFloat64();
2324}
2325
2326inline Datetime Element::getElementAsDatetime(const char *elementName) const
2327{
2328 return getElement(Name(elementName)).getValueAsDatetime();
2329}
2330
2331inline Datetime Element::getElementAsDatetime(const Name& elementName) const
2332{
2333 return getElement(elementName).getValueAsDatetime();
2334}
2335
2336inline const char *Element::getElementAsString(const char *elementName) const
2337{
2338 return getElement(Name(elementName)).getValueAsString();
2339}
2340
2341inline const char *Element::getElementAsString(const Name& elementName) const
2342{
2343 return getElement(elementName).getValueAsString();
2344}
2345
2346inline Bytes Element::getElementAsBytes(const Name& elementName) const
2347{
2348 return getElement(elementName).getValueAsBytes();
2349}
2350
2351inline Name Element::getElementAsName(const char *elementName) const
2352{
2353 return getElement(Name(elementName)).getValueAsName();
2354}
2355
2356inline Name Element::getElementAsName(const Name& elementName) const
2357{
2358 return getElement(elementName).getValueAsName();
2359}
2360
2361inline const blpapi_Element_t *Element::handle() const { return d_handle_p; }
2362
2363inline std::ostream& Element::print(
2364 std::ostream& stream, int level, int spacesPerLevel) const
2365{
2366 blpapi_Element_print(d_handle_p,
2368 &stream,
2369 level,
2370 spacesPerLevel);
2371 return stream;
2372}
2373
2374inline std::string Element::toJson() const
2375{
2376 std::ostringstream stream;
2378 d_handle_p, StreamProxyOstream::writeToStream, &stream));
2379 return stream.str();
2380}
2381
2382inline void Element::fromJson(const char *json)
2383{
2385}
2386
2387inline void Element::fromJson(const std::string& json)
2388{
2389 fromJson(json.c_str());
2390}
2391
2392inline std::ostream& operator<<(std::ostream& stream, const Element& element)
2393{
2394 element.print(stream, 0, -1);
2395 return stream;
2396}
2397
2398} // close namespace blpapi
2399} // close namespace BloombergLP
2400
2401#endif // #ifdef __cplusplus
2402#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:2326
Name name() const
Definition blpapi_element.h:1941
void rebind(blpapi_Element_t *element)
Definition blpapi_element.h:1638
int getValueAs(bool *result, size_t index=0) const
Definition blpapi_element.h:2090
BLPAPI_DEPRECATE_STRING_NAME Element setChoice(const char *selectionName)
Definition blpapi_element.h:1923
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_element.h:2346
bool isNullValue(size_t position=0) const
Definition blpapi_element.h:2028
BLPAPI_DEPRECATE_STRING_NAME int getElement(Element *result, const char *name) const
Definition blpapi_element.h:1946
Float64 getValueAsFloat64(size_t index=0) const
Definition blpapi_element.h:2213
Element getValueAsElement(size_t index=0) const
Definition blpapi_element.h:2242
Name getValueAsName(size_t index=0) const
Definition blpapi_element.h:2250
int datatype() const
Definition blpapi_element.h:1986
BLPAPI_DEPRECATE_STRING_NAME Name getElementAsName(const char *name) const
Definition blpapi_element.h:2351
Int64 getValueAsInt64(size_t index=0) const
Definition blpapi_element.h:2199
Bytes getValueAsBytes(size_t index=0) const
Definition blpapi_element.h:2235
blpapi_Element_t * handle()
Definition blpapi_element.h:1939
BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(const char *name) const
Definition blpapi_element.h:2316
size_t numValues() const
Definition blpapi_element.h:2016
bool isReadOnly() const
Definition blpapi_element.h:2006
BLPAPI_DEPRECATE_STRING_NAME bool hasElement(const char *name, bool excludeNullElements=false) const
Definition blpapi_element.h:2037
void appendValue(bool value)
Definition blpapi_element.h:1854
bool isValid() const
Definition blpapi_element.h:2026
BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const
Definition blpapi_element.h:2266
bool getValueAsBool(size_t index=0) const
Definition blpapi_element.h:2178
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_element.h:2363
void setValue(bool value, size_t index=0)
Definition blpapi_element.h:1781
BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const
Definition blpapi_element.h:2276
Element appendElement()
Definition blpapi_element.h:1915
const char * getValueAsString(size_t index=0) const
Definition blpapi_element.h:2227
bool isComplexType() const
Definition blpapi_element.h:1991
char getValueAsChar(size_t index=0) const
Definition blpapi_element.h:2185
BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, bool value)
Definition blpapi_element.h:1643
std::string toJson() const
Definition blpapi_element.h:2374
void fromJson(const char *json)
Definition blpapi_element.h:2382
Element()
Definition blpapi_element.h:1628
Datetime getValueAsDatetime(size_t index=0) const
Definition blpapi_element.h:2220
bool isNull() const
Definition blpapi_element.h:2001
SchemaElementDefinition elementDefinition() const
Definition blpapi_element.h:2011
BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(const char *name) const
Definition blpapi_element.h:2296
BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(const char *name) const
Definition blpapi_element.h:2286
Element getChoice() const
Definition blpapi_element.h:2258
Float32 getValueAsFloat32(size_t index=0) const
Definition blpapi_element.h:2206
bool isArray() const
Definition blpapi_element.h:1996
Int32 getValueAsInt32(size_t index=0) const
Definition blpapi_element.h:2192
BLPAPI_DEPRECATE_STRING_NAME const char * getElementAsString(const char *name) const
Definition blpapi_element.h:2336
BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(const char *name) const
Definition blpapi_element.h:2306
size_t numElements() const
Definition blpapi_element.h:2021
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:647
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