BLPAPI C++  3.24.4
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_name.h>
63 #include <blpapi_schema.h>
64 #include <blpapi_streamproxy.h>
65 #include <blpapi_types.h>
66 
67 #include <stddef.h>
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
74  const blpapi_Element_t *element);
75 
77  const blpapi_Element_t *element);
78 
80  const blpapi_Element_t *element);
81 
83 
85  const blpapi_Element_t *element);
86 
88 
90 
92 
94  const blpapi_Element_t *element);
95 
97  const blpapi_Element_t *element, size_t position);
98 
100 
102  blpapi_StreamWriter_t streamWriter,
103  void *stream,
104  int level,
105  int spacesPerLevel);
106 
109  blpapi_Element_t **result,
110  size_t position);
111 
114  blpapi_Element_t **result,
115  const char *nameString,
116  const blpapi_Name_t *name);
117 
120  const char *nameString,
121  const blpapi_Name_t *name);
122 
125  const char *nameString,
126  const blpapi_Name_t *name,
127  int excludeNullElements,
128  int reserved);
129 
132  const blpapi_Element_t *element, blpapi_Bool_t *buffer, size_t index);
133 
136  const blpapi_Element_t *element, blpapi_Char_t *buffer, size_t index);
137 
140  const blpapi_Element_t *element, blpapi_Int32_t *buffer, size_t index);
141 
144  const blpapi_Element_t *element, blpapi_Int64_t *buffer, size_t index);
145 
148  blpapi_Float32_t *buffer,
149  size_t index);
150 
153  blpapi_Float64_t *buffer,
154  size_t index);
155 
158  const blpapi_Element_t *element, const char **buffer, size_t index);
159 
162  blpapi_Datetime_t *buffer,
163  size_t index);
164 
167  const blpapi_Element_t *element,
169  size_t index);
170 
173  blpapi_Element_t **buffer,
174  size_t index);
175 
178  const blpapi_Element_t *element, blpapi_Name_t **buffer, size_t index);
179 
182  const char **buffer,
183  size_t *length,
184  size_t index);
185 
188  const blpapi_Element_t *element, blpapi_Element_t **result);
189 
192  blpapi_Element_t *element, blpapi_Bool_t value, size_t index);
193 
196  blpapi_Element_t *element, blpapi_Char_t value, size_t index);
197 
200  blpapi_Element_t *element, blpapi_Int32_t value, size_t index);
201 
204  blpapi_Element_t *element, blpapi_Int64_t value, size_t index);
205 
208  blpapi_Element_t *element, blpapi_Float32_t value, size_t index);
209 
212  blpapi_Element_t *element, blpapi_Float64_t value, size_t index);
213 
216  blpapi_Element_t *element, const char *value, size_t index);
217 
220  const blpapi_Datetime_t *value,
221  size_t index);
222 
225  const blpapi_HighPrecisionDatetime_t *value,
226  size_t index);
227 
230  const char *value,
231  size_t length,
232  size_t index);
233 
236  blpapi_Element_t *element, blpapi_Element_t *value, size_t index);
237 
240  blpapi_Element_t *element, const blpapi_Name_t *value, size_t index);
241 
244  const char *nameString,
245  const blpapi_Name_t *name,
246  blpapi_Bool_t value);
247 
250  const char *nameString,
251  const blpapi_Name_t *name,
252  blpapi_Char_t value);
253 
256  const char *nameString,
257  const blpapi_Name_t *name,
258  blpapi_Int32_t value);
259 
262  const char *nameString,
263  const blpapi_Name_t *name,
264  blpapi_Int64_t value);
265 
268  const char *nameString,
269  const blpapi_Name_t *name,
270  blpapi_Float32_t value);
271 
274  const char *nameString,
275  const blpapi_Name_t *name,
276  blpapi_Float64_t value);
277 
280  const char *nameString,
281  const blpapi_Name_t *name,
282  const char *value);
283 
286  const char *nameString,
287  const blpapi_Name_t *name,
288  const blpapi_Datetime_t *value);
289 
292  const char *nameString,
293  const blpapi_Name_t *name,
294  const blpapi_HighPrecisionDatetime_t *value);
295 
298  const char *nameString,
299  const blpapi_Name_t *name,
300  const char *value,
301  size_t length);
302 
305  const char *nameString,
306  const blpapi_Name_t *name,
307  blpapi_Element_t *sourcebuffer);
308 
311  const char *elementName,
312  const blpapi_Name_t *name,
313  const blpapi_Name_t *buffer);
314 
317  blpapi_Element_t *element, blpapi_Element_t **appendedElement);
318 
321  blpapi_Element_t **resultElement,
322  const char *nameCstr,
323  const blpapi_Name_t *name,
324  size_t index);
325 
326 #ifdef __cplusplus
327 }
328 
329 #include <blpapi_exception.h>
330 
331 #include <cassert>
332 #include <string>
333 #include <type_traits>
334 
342 namespace BloombergLP {
343 namespace blpapi {
344 
464 class Element {
465 
466  blpapi_Element_t *d_handle_p;
467 
468  public:
469  Element();
476  explicit Element(blpapi_Element_t *element);
477 
478  // MANIPULATORS
479 
480  void rebind(blpapi_Element_t *element);
481 
482  [[deprecated("Use the form that takes Name instead of const char*")]] void
483  setElement(const char *name, bool value);
496  [[deprecated("Use the form that takes Name instead of const char*")]] void
497  setElement(const char *name, char value);
510  [[deprecated("Use the form that takes Name instead of const char*")]] void
511  setElement(const char *name, Int32 value);
524  [[deprecated("Use the form that takes Name instead of const char*")]] void
525  setElement(const char *name, Int64 value);
538  [[deprecated("Use the form that takes Name instead of const char*")]] void
539  setElement(const char *name, Float32 value);
552  [[deprecated("Use the form that takes Name instead of const char*")]] void
553  setElement(const char *name, Float64 value);
566  [[deprecated("Use the form that takes Name instead of const char*")]] void
567  setElement(const char *name, const Datetime& value);
580  [[deprecated("Use the form that takes Name instead of const char*")]] void
581  setElement(const char *name, const char *value);
594  [[deprecated("Use the form that takes Name instead of const char*")]] void
595  setElement(const char *name, const Name& value);
609  void setElement(const Name& name, bool value);
620  void setElement(const Name& name, char value);
631  void setElement(const Name& name, Int32 value);
642  void setElement(const Name& name, Int64 value);
653  void setElement(const Name& name, Float32 value);
664  void setElement(const Name& name, Float64 value);
675  void setElement(const Name& name, const Datetime& value);
686  void setElement(const Name& name, const char *value);
697  void setElement(const Name& name, const std::string& value);
709  void setElement(const Name& name, const Name& value);
720  void setElement(const Name& name, const void *value, size_t length);
731  template <typename BYTES,
732  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
733  = true>
734  void setElement(const Name& name, const BYTES& value);
750  void setValue(bool value, size_t index = 0);
759  void setValue(char value, size_t index = 0);
768  void setValue(Int32 value, size_t index = 0);
777  void setValue(Int64 value, size_t index = 0);
786  void setValue(Float32 value, size_t index = 0);
795  void setValue(Float64 value, size_t index = 0);
804  void setValue(const Datetime& value, size_t index = 0);
813  void setValue(const char *value, size_t index = 0);
822  void setValue(const std::string& value, size_t index = 0);
832  void setValue(const Name& valueName, size_t index = 0);
842  void setValue(const void *value, size_t length, size_t index);
851  template <typename BYTES,
852  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
853  = true>
854  void setValue(const BYTES& value, size_t index = 0);
868  void appendValue(bool value);
878  void appendValue(char value);
888  void appendValue(Int32 value);
898  void appendValue(Int64 value);
908  void appendValue(Float32 value);
918  void appendValue(Float64 value);
928  void appendValue(const Datetime& value);
938  void appendValue(const char *value);
948  void appendValue(const std::string& value);
960  void appendValue(const Name& value);
978  [[deprecated(
979  "Use the form that takes Name instead of const char*")]] Element
980  setChoice(const char *selectionName);
990  Element setChoice(const Name& selectionName);
999 
1000  // ACCESSORS
1001 
1002  Name name() const;
1011  int datatype() const;
1019  bool isComplexType() const;
1025  bool isArray() const;
1032  bool isNull() const;
1037  bool isReadOnly() const;
1048  size_t numValues() const;
1058  size_t numElements() const;
1066  bool isValid() const;
1073  bool isNullValue(size_t position = 0) const;
1081  [[deprecated("Use the form that takes Name instead of const char*")]] bool
1082  hasElement(const char *name, bool excludeNullElements = false) const;
1091  bool hasElement(const Name& name, bool excludeNullElements = false) const;
1098  int getValueAs(bool *result, size_t index = 0) const;
1107  int getValueAs(char *result, size_t index = 0) const;
1116  int getValueAs(Int32 *result, size_t index = 0) const;
1125  int getValueAs(Int64 *result, size_t index = 0) const;
1134  int getValueAs(Float32 *result, size_t index = 0) const;
1143  int getValueAs(Float64 *result, size_t index = 0) const;
1152  int getValueAs(Datetime *result, size_t index = 0) const;
1164  int getValueAs(std::string *result, size_t index = 0) const;
1173  int getValueAs(Bytes *result, size_t index = 0) const;
1181  int getValueAs(Element *result, size_t index = 0) const;
1190  int getValueAs(Name *result, size_t index = 0) const;
1198  bool getValueAsBool(size_t index = 0) const;
1205  char getValueAsChar(size_t index = 0) const;
1212  Int32 getValueAsInt32(size_t index = 0) const;
1219  Int64 getValueAsInt64(size_t index = 0) const;
1226  Float32 getValueAsFloat32(size_t index = 0) const;
1233  Float64 getValueAsFloat64(size_t index = 0) const;
1240  Datetime getValueAsDatetime(size_t index = 0) const;
1251  const char *getValueAsString(size_t index = 0) const;
1260  Bytes getValueAsBytes(size_t index = 0) const;
1268  Element getValueAsElement(size_t index = 0) const;
1276  Name getValueAsName(size_t index = 0) const;
1283  [[deprecated("Use the form that takes Name instead of const char*")]] int
1284  getElement(Element *result, const char *name) const;
1295  int getElement(Element *result, const Name& name) const;
1304  int getElement(Element *result, size_t position) const;
1313  Element getElement(size_t position) const;
1321  Element getElement(const Name& name) const;
1329  [[deprecated(
1330  "Use the form that takes Name instead of const char*")]] Element
1331  getElement(const char *name) const;
1342  [[deprecated("Use the form that takes Name instead of const char*")]] bool
1343  getElementAsBool(const char *name) const;
1354  bool getElementAsBool(const Name& name) const;
1363  [[deprecated("Use the form that takes Name instead of const char*")]] char
1364  getElementAsChar(const char *name) const;
1375  char getElementAsChar(const Name& name) const;
1384  [[deprecated("Use the form that takes Name instead of const char*")]] Int32
1385  getElementAsInt32(const char *name) const;
1396  Int32 getElementAsInt32(const Name& name) const;
1405  [[deprecated("Use the form that takes Name instead of const char*")]] Int64
1406  getElementAsInt64(const char *name) const;
1417  Int64 getElementAsInt64(const Name& name) const;
1426  [[deprecated(
1427  "Use the form that takes Name instead of const char*")]] Float32
1428  getElementAsFloat32(const char *name) const;
1439  Float32 getElementAsFloat32(const Name& name) const;
1448  [[deprecated(
1449  "Use the form that takes Name instead of const char*")]] Float64
1450  getElementAsFloat64(const char *name) const;
1461  Float64 getElementAsFloat64(const Name& name) const;
1470  [[deprecated(
1471  "Use the form that takes Name instead of const char*")]] Datetime
1472  getElementAsDatetime(const char *name) const;
1487  Datetime getElementAsDatetime(const Name& name) const;
1499  [[deprecated("Use the form that takes Name instead of const "
1500  "char*")]] const char *
1501  getElementAsString(const char *name) const;
1513  const char *getElementAsString(const Name& name) const;
1523  Bytes getElementAsBytes(const Name& name) const;
1533  [[deprecated("Use the form that takes Name instead of const char*")]] Name
1534  getElementAsName(const char *name) const;
1545  Name getElementAsName(const Name& name) const;
1554  Element getChoice() const;
1560  const blpapi_Element_t *handle() const;
1561 
1562  std::ostream& print(
1563  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
1576 };
1577 
1581 // FREE OPERATORS
1582 std::ostream& operator<<(std::ostream& stream, const Element& element);
1596 // ============================================================================
1597 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
1598 // ============================================================================
1599 
1600 // -------------
1601 // class Element
1602 // -------------
1603 
1605  : d_handle_p(0)
1606 {
1607 }
1608 
1610  : d_handle_p(newHandle)
1611 {
1612 }
1613 
1614 inline void Element::rebind(blpapi_Element_t *element)
1615 {
1616  d_handle_p = element;
1617 }
1618 
1619 inline void Element::setElement(const char *elementName, bool value)
1620 {
1622  d_handle_p, elementName, 0, value ? 1 : 0));
1623 }
1624 
1625 inline void Element::setElement(const char *elementName, char value)
1626 {
1628  blpapi_Element_setElementChar(d_handle_p, elementName, 0, value));
1629 }
1630 
1631 inline void Element::setElement(const char *elementName, Int32 value)
1632 {
1634  blpapi_Element_setElementInt32(d_handle_p, elementName, 0, value));
1635 }
1636 
1637 inline void Element::setElement(const char *elementName, Int64 value)
1638 {
1640  blpapi_Element_setElementInt64(d_handle_p, elementName, 0, value));
1641 }
1642 
1643 inline void Element::setElement(const char *elementName, Float32 value)
1644 {
1646  d_handle_p, elementName, 0, value));
1647 }
1648 
1649 inline void Element::setElement(const char *elementName, Float64 value)
1650 {
1652  d_handle_p, elementName, 0, value));
1653 }
1654 
1655 inline void Element::setElement(const char *elementName, const Datetime& value)
1656 {
1659  elementName,
1660  0,
1661  &value.rawHighPrecisionValue()));
1662 }
1663 
1664 inline void Element::setElement(const char *elementName, const char *value)
1665 {
1667  d_handle_p, elementName, 0, value));
1668 }
1669 
1670 inline void Element::setElement(const char *elementName, const Name& value)
1671 {
1673  d_handle_p, elementName, 0, value.impl()));
1674 }
1675 
1676 inline void Element::setElement(const Name& elementName, bool value)
1677 {
1679  d_handle_p, 0, elementName.impl(), value ? 1 : 0));
1680 }
1681 
1682 inline void Element::setElement(const Name& elementName, char value)
1683 {
1685  d_handle_p, 0, elementName.impl(), value));
1686 }
1687 
1688 inline void Element::setElement(const Name& elementName, Int32 value)
1689 {
1691  d_handle_p, 0, elementName.impl(), value));
1692 }
1693 
1694 inline void Element::setElement(const Name& elementName, Int64 value)
1695 {
1697  d_handle_p, 0, elementName.impl(), value));
1698 }
1699 
1700 inline void Element::setElement(const Name& elementName, Float32 value)
1701 {
1703  d_handle_p, 0, elementName.impl(), value));
1704 }
1705 
1706 inline void Element::setElement(const Name& elementName, Float64 value)
1707 {
1709  d_handle_p, 0, elementName.impl(), value));
1710 }
1711 
1712 inline void Element::setElement(const Name& elementName, const Datetime& value)
1713 {
1716  0,
1717  elementName.impl(),
1718  &value.rawHighPrecisionValue()));
1719 }
1720 
1721 inline void Element::setElement(const Name& elementName, const char *value)
1722 {
1724  d_handle_p, 0, elementName.impl(), value));
1725 }
1726 
1728  const Name& elementName, const std::string& value)
1729 {
1730  setElement(elementName, value.c_str());
1731 }
1732 
1733 inline void Element::setElement(const Name& elementName, const Name& value)
1734 {
1736  d_handle_p, 0, elementName.impl(), value.impl()));
1737 }
1738 
1740  const Name& elementName, const void *value, size_t length)
1741 {
1744  0,
1745  elementName.impl(),
1746  reinterpret_cast<const char *>(value),
1747  length));
1748 }
1749 
1750 template <typename BYTES,
1751  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1752 inline void Element::setElement(const Name& elementName, const BYTES& value)
1753 {
1754  setElement(elementName, value.data(), value.size());
1755 }
1756 
1757 inline void Element::setValue(bool value, size_t index)
1758 {
1760  blpapi_Element_setValueBool(d_handle_p, value, index));
1761 }
1762 
1763 inline void Element::setValue(char value, size_t index)
1764 {
1766  blpapi_Element_setValueChar(d_handle_p, value, index));
1767 }
1768 
1769 inline void Element::setValue(Int32 value, size_t index)
1770 {
1772  blpapi_Element_setValueInt32(d_handle_p, value, index));
1773 }
1774 
1775 inline void Element::setValue(Int64 value, size_t index)
1776 {
1778  blpapi_Element_setValueInt64(d_handle_p, value, index));
1779 }
1780 
1781 inline void Element::setValue(Float32 value, size_t index)
1782 {
1784  blpapi_Element_setValueFloat32(d_handle_p, value, index));
1785 }
1786 
1787 inline void Element::setValue(Float64 value, size_t index)
1788 {
1790  blpapi_Element_setValueFloat64(d_handle_p, value, index));
1791 }
1792 
1793 inline void Element::setValue(const Datetime& value, size_t index)
1794 {
1797  d_handle_p, &value.rawHighPrecisionValue(), index));
1798 }
1799 
1800 inline void Element::setValue(const char *value, size_t index)
1801 {
1803  blpapi_Element_setValueString(d_handle_p, value, index));
1804 }
1805 
1806 inline void Element::setValue(const std::string& value, size_t index)
1807 {
1808  setValue(value.c_str(), index);
1809 }
1810 
1811 inline void Element::setValue(const Name& valueName, size_t index)
1812 {
1814  d_handle_p, valueName.impl(), index));
1815 }
1816 
1817 inline void Element::setValue(const void *value, size_t length, size_t index)
1818 {
1820  d_handle_p, reinterpret_cast<const char *>(value), length, index));
1821 }
1822 
1823 template <typename BYTES,
1824  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1825 inline void Element::setValue(const BYTES& value, size_t index)
1826 {
1827  setValue(value.data(), value.size(), index);
1828 }
1829 
1830 inline void Element::appendValue(bool value)
1831 {
1833  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1834 }
1835 
1836 inline void Element::appendValue(char value)
1837 {
1839  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1840 }
1841 
1842 inline void Element::appendValue(Int32 value)
1843 {
1845  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1846 }
1847 
1848 inline void Element::appendValue(Int64 value)
1849 {
1851  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1852 }
1853 
1854 inline void Element::appendValue(Float32 value)
1855 {
1857  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1858 }
1859 
1860 inline void Element::appendValue(Float64 value)
1861 {
1863  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1864 }
1865 
1866 inline void Element::appendValue(const Datetime& value)
1867 {
1870  &value.rawHighPrecisionValue(),
1872 }
1873 
1874 inline void Element::appendValue(const char *value)
1875 {
1877  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1878 }
1879 
1880 inline void Element::appendValue(const std::string& value)
1881 {
1882  appendValue(value.c_str());
1883 }
1884 
1885 inline void Element::appendValue(const Name& valueName)
1886 {
1888  d_handle_p, valueName.impl(), BLPAPI_ELEMENT_INDEX_END));
1889 }
1890 
1892 {
1893  blpapi_Element_t *appendedElement = 0;
1895  blpapi_Element_appendElement(d_handle_p, &appendedElement));
1896  return Element(appendedElement);
1897 }
1898 
1899 inline Element Element::setChoice(const char *selectionName)
1900 {
1901  blpapi_Element_t *resultElement = 0;
1903  d_handle_p, &resultElement, selectionName, 0, 0));
1904  return Element(resultElement);
1905 }
1906 
1907 inline Element Element::setChoice(const Name& selectionName)
1908 {
1909  blpapi_Element_t *resultElement = 0;
1911  d_handle_p, &resultElement, 0, selectionName.impl(), 0));
1912  return Element(resultElement);
1913 }
1914 
1915 inline blpapi_Element_t *Element::handle() { return d_handle_p; }
1916 
1917 inline Name Element::name() const
1918 {
1919  return Name(blpapi_Element_name(d_handle_p));
1920 }
1921 
1922 inline int Element::getElement(Element *element, const char *nameString) const
1923 {
1924  assert(element);
1925 
1926  blpapi_Element_t *fldt = 0;
1927  int rc = blpapi_Element_getElement(d_handle_p, &fldt, nameString, 0);
1928  if (!rc) {
1929  element->rebind(fldt);
1930  }
1931 
1932  return rc;
1933 }
1934 
1935 inline int Element::getElement(Element *element, const Name& elementName) const
1936 {
1937  assert(element);
1938 
1939  blpapi_Element_t *fldt = 0;
1940  int rc = blpapi_Element_getElement(
1941  d_handle_p, &fldt, 0, elementName.impl());
1942  if (!rc) {
1943  element->rebind(fldt);
1944  }
1945 
1946  return rc;
1947 }
1948 
1949 inline int Element::getElement(Element *element, size_t position) const
1950 {
1951  assert(element);
1952 
1953  blpapi_Element_t *fldt = 0;
1954  int rc = blpapi_Element_getElementAt(d_handle_p, &fldt, position);
1955  if (!rc) {
1956  element->rebind(fldt);
1957  }
1958 
1959  return rc;
1960 }
1961 
1962 inline int Element::datatype() const
1963 {
1964  return blpapi_Element_datatype(d_handle_p);
1965 }
1966 
1967 inline bool Element::isComplexType() const
1968 {
1969  return blpapi_Element_isComplexType(d_handle_p) ? true : false;
1970 }
1971 
1972 inline bool Element::isArray() const
1973 {
1974  return blpapi_Element_isArray(d_handle_p) ? true : false;
1975 }
1976 
1977 inline bool Element::isNull() const
1978 {
1979  return blpapi_Element_isNull(d_handle_p) ? true : false;
1980 }
1981 
1982 inline bool Element::isReadOnly() const
1983 {
1984  return blpapi_Element_isReadOnly(d_handle_p) ? true : false;
1985 }
1986 
1988 {
1990 }
1991 
1992 inline size_t Element::numValues() const
1993 {
1994  return blpapi_Element_numValues(d_handle_p);
1995 }
1996 
1997 inline size_t Element::numElements() const
1998 {
1999  return blpapi_Element_numElements(d_handle_p);
2000 }
2001 
2002 inline bool Element::isValid() const { return d_handle_p ? true : false; }
2003 
2004 inline bool Element::isNullValue(size_t position) const
2005 {
2006  int rc = blpapi_Element_isNullValue(d_handle_p, position);
2007  if (rc != 0 && rc != 1) {
2009  }
2010  return rc ? true : false;
2011 }
2012 
2014  const char *nameString, bool excludeNullElements) const
2015 {
2016  if (excludeNullElements) {
2018  d_handle_p, nameString, 0, excludeNullElements, 0)
2019  ? true
2020  : false);
2021  }
2022  return blpapi_Element_hasElement(d_handle_p, nameString, 0) ? true : false;
2023 }
2024 
2026  const Name& elementName, bool excludeNullElements) const
2027 {
2028  if (excludeNullElements) {
2029  return (blpapi_Element_hasElementEx(d_handle_p,
2030  0,
2031  elementName.impl(),
2032  excludeNullElements,
2033  0)
2034  ? true
2035  : false);
2036  }
2037  return blpapi_Element_hasElement(d_handle_p, 0, elementName.impl())
2038  ? true
2039  : false;
2040 }
2041 
2042 inline Element Element::getElement(const Name& elementName) const
2043 {
2044  blpapi_Element_t *fldt = 0;
2046  d_handle_p, &fldt, 0, elementName.impl()));
2047  return Element(fldt);
2048 }
2049 
2050 inline Element Element::getElement(const char *elementName) const
2051 {
2052  blpapi_Element_t *fldt = 0;
2054  blpapi_Element_getElement(d_handle_p, &fldt, elementName, 0));
2055  return Element(fldt);
2056 }
2057 
2058 inline Element Element::getElement(size_t position) const
2059 {
2060  blpapi_Element_t *element = 0;
2062  blpapi_Element_getElementAt(d_handle_p, &element, position));
2063  return Element(element);
2064 }
2065 
2066 inline int Element::getValueAs(bool *buffer, size_t index) const
2067 {
2068  assert(buffer);
2069 
2070  blpapi_Bool_t tmp = false;
2071 
2072  int res = blpapi_Element_getValueAsBool(d_handle_p, &tmp, index);
2073  *buffer = tmp ? true : false;
2074  return res;
2075 }
2076 
2077 inline int Element::getValueAs(char *buffer, size_t index) const
2078 {
2079  return blpapi_Element_getValueAsChar(d_handle_p, buffer, index);
2080 }
2081 
2082 inline int Element::getValueAs(Int32 *buffer, size_t index) const
2083 {
2084  return blpapi_Element_getValueAsInt32(d_handle_p, buffer, index);
2085 }
2086 
2087 inline int Element::getValueAs(Int64 *buffer, size_t index) const
2088 {
2089  return blpapi_Element_getValueAsInt64(d_handle_p, buffer, index);
2090 }
2091 
2092 inline int Element::getValueAs(Float32 *buffer, size_t index) const
2093 {
2094  return blpapi_Element_getValueAsFloat32(d_handle_p, buffer, index);
2095 }
2096 
2097 inline int Element::getValueAs(Float64 *buffer, size_t index) const
2098 {
2099  return blpapi_Element_getValueAsFloat64(d_handle_p, buffer, index);
2100 }
2101 
2102 inline int Element::getValueAs(Datetime *buffer, size_t index) const
2103 {
2105  d_handle_p, buffer, index);
2106 }
2107 
2108 inline int Element::getValueAs(std::string *result, size_t index) const
2109 {
2110  assert(result);
2111 
2112  const char *buffer = 0;
2113  int rc = blpapi_Element_getValueAsString(d_handle_p, &buffer, index);
2114  if (!rc) {
2115  *result = buffer;
2116  }
2117  return rc;
2118 }
2119 
2120 inline int Element::getValueAs(Bytes *result, size_t index) const
2121 {
2122  assert(result);
2123 
2124  const char *buffer = 0;
2125  size_t length = 0;
2127  d_handle_p, &buffer, &length, index);
2128  if (!rc) {
2129  result->assign(buffer, length);
2130  }
2131  return rc;
2132 }
2133 
2134 inline int Element::getValueAs(Element *buffer, size_t index) const
2135 {
2136  assert(buffer);
2137 
2139  d_handle_p, &buffer->d_handle_p, index);
2140 }
2141 
2142 inline int Element::getValueAs(Name *buffer, size_t index) const
2143 {
2144  assert(buffer);
2145 
2146  blpapi_Name_t *tmpName = 0;
2147  int res = blpapi_Element_getValueAsName(d_handle_p, &tmpName, index);
2148  if (!res) {
2149  *buffer = Name(tmpName);
2150  }
2151  return res;
2152 }
2153 
2154 inline bool Element::getValueAsBool(size_t index) const
2155 {
2156  bool value = false;
2157  ExceptionUtil::throwOnError(getValueAs(&value, index));
2158  return value;
2159 }
2160 
2161 inline char Element::getValueAsChar(size_t index) const
2162 {
2163  char value = 0;
2164  ExceptionUtil::throwOnError(getValueAs(&value, index));
2165  return value;
2166 }
2167 
2168 inline Int32 Element::getValueAsInt32(size_t index) const
2169 {
2170  Int32 value = 0;
2171  ExceptionUtil::throwOnError(getValueAs(&value, index));
2172  return value;
2173 }
2174 
2175 inline Int64 Element::getValueAsInt64(size_t index) const
2176 {
2177  Int64 value = 0;
2178  ExceptionUtil::throwOnError(getValueAs(&value, index));
2179  return value;
2180 }
2181 
2182 inline Float32 Element::getValueAsFloat32(size_t index) const
2183 {
2184  Float32 value = 0.0;
2185  ExceptionUtil::throwOnError(getValueAs(&value, index));
2186  return value;
2187 }
2188 
2189 inline Float64 Element::getValueAsFloat64(size_t index) const
2190 {
2191  Float64 value = 0.0;
2192  ExceptionUtil::throwOnError(getValueAs(&value, index));
2193  return value;
2194 }
2195 
2196 inline Datetime Element::getValueAsDatetime(size_t index) const
2197 {
2198  Datetime value;
2199  ExceptionUtil::throwOnError(getValueAs(&value, index));
2200  return value;
2201 }
2202 
2203 inline const char *Element::getValueAsString(size_t index) const
2204 {
2205  const char *tmpStringBuffer = 0;
2207  d_handle_p, &tmpStringBuffer, index));
2208  return tmpStringBuffer;
2209 }
2210 
2211 inline Bytes Element::getValueAsBytes(size_t index) const
2212 {
2213  Bytes value;
2214  ExceptionUtil::throwOnError(getValueAs(&value, index));
2215  return value;
2216 }
2217 
2218 inline Element Element::getValueAsElement(size_t index) const
2219 {
2220  blpapi_Element_t *element = 0;
2222  blpapi_Element_getValueAsElement(d_handle_p, &element, index));
2223  return Element(element);
2224 }
2225 
2226 inline Name Element::getValueAsName(size_t index) const
2227 {
2228  blpapi_Name_t *nameValue = 0;
2230  blpapi_Element_getValueAsName(d_handle_p, &nameValue, index));
2231  return Name(nameValue);
2232 }
2233 
2235 {
2236  blpapi_Element_t *element = 0;
2238  blpapi_Element_getChoice(d_handle_p, &element));
2239  return Element(element);
2240 }
2241 
2242 inline bool Element::getElementAsBool(const char *elementName) const
2243 {
2244  return getElement(Name(elementName)).getValueAsBool();
2245 }
2246 
2247 inline bool Element::getElementAsBool(const Name& elementName) const
2248 {
2249  return getElement(elementName).getValueAsBool();
2250 }
2251 
2252 inline char Element::getElementAsChar(const char *elementName) const
2253 {
2254  return getElement(Name(elementName)).getValueAsChar();
2255 }
2256 
2257 inline char Element::getElementAsChar(const Name& elementName) const
2258 {
2259  return getElement(elementName).getValueAsChar();
2260 }
2261 
2262 inline Int32 Element::getElementAsInt32(const char *elementName) const
2263 {
2264  return getElement(Name(elementName)).getValueAsInt32();
2265 }
2266 
2267 inline Int32 Element::getElementAsInt32(const Name& elementName) const
2268 {
2269  return getElement(elementName).getValueAsInt32();
2270 }
2271 
2272 inline Int64 Element::getElementAsInt64(const char *elementName) const
2273 {
2274  return getElement(Name(elementName)).getValueAsInt64();
2275 }
2276 
2277 inline Int64 Element::getElementAsInt64(const Name& elementName) const
2278 {
2279  return getElement(elementName).getValueAsInt64();
2280 }
2281 
2282 inline Float32 Element::getElementAsFloat32(const char *elementName) const
2283 {
2284  return getElement(Name(elementName)).getValueAsFloat32();
2285 }
2286 
2287 inline Float32 Element::getElementAsFloat32(const Name& elementName) const
2288 {
2289  return getElement(elementName).getValueAsFloat32();
2290 }
2291 
2292 inline Float64 Element::getElementAsFloat64(const char *elementName) const
2293 {
2294  return getElement(Name(elementName)).getValueAsFloat64();
2295 }
2296 
2297 inline Float64 Element::getElementAsFloat64(const Name& elementName) const
2298 {
2299  return getElement(elementName).getValueAsFloat64();
2300 }
2301 
2302 inline Datetime Element::getElementAsDatetime(const char *elementName) const
2303 {
2304  return getElement(Name(elementName)).getValueAsDatetime();
2305 }
2306 
2307 inline Datetime Element::getElementAsDatetime(const Name& elementName) const
2308 {
2309  return getElement(elementName).getValueAsDatetime();
2310 }
2311 
2312 inline const char *Element::getElementAsString(const char *elementName) const
2313 {
2314  return getElement(Name(elementName)).getValueAsString();
2315 }
2316 
2317 inline const char *Element::getElementAsString(const Name& elementName) const
2318 {
2319  return getElement(elementName).getValueAsString();
2320 }
2321 
2322 inline Bytes Element::getElementAsBytes(const Name& elementName) const
2323 {
2324  return getElement(elementName).getValueAsBytes();
2325 }
2326 
2327 inline Name Element::getElementAsName(const char *elementName) const
2328 {
2329  return getElement(Name(elementName)).getValueAsName();
2330 }
2331 
2332 inline Name Element::getElementAsName(const Name& elementName) const
2333 {
2334  return getElement(elementName).getValueAsName();
2335 }
2336 
2337 inline const blpapi_Element_t *Element::handle() const { return d_handle_p; }
2338 
2339 inline std::ostream& Element::print(
2340  std::ostream& stream, int level, int spacesPerLevel) const
2341 {
2342  blpapi_Element_print(d_handle_p,
2344  &stream,
2345  level,
2346  spacesPerLevel);
2347  return stream;
2348 }
2349 
2350 inline std::ostream& operator<<(std::ostream& stream, const Element& element)
2351 {
2352  element.print(stream, 0, -1);
2353  return stream;
2354 }
2355 
2356 } // close namespace blpapi
2357 } // close namespace BloombergLP
2358 
2359 #endif // #ifdef __cplusplus
2360 #endif // #ifndef INCLUDED_BLPAPI_ELEMENT
blpapi_SchemaElementDefinition_t * blpapi_Element_definition(const blpapi_Element_t *element)
int blpapi_Element_setElementHighPrecisionDatetime(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const blpapi_HighPrecisionDatetime_t *value)
int blpapi_Element_getChoice(const blpapi_Element_t *element, blpapi_Element_t **result)
blpapi_Element_t * handle()
Definition: blpapi_element.h:1915
int blpapi_Element_setChoice(blpapi_Element_t *element, blpapi_Element_t **resultElement, const char *nameCstr, const blpapi_Name_t *name, size_t index)
bool getElementAsBool(const char *name) const
Definition: blpapi_element.h:2242
Datetime getValueAsDatetime(size_t index=0) const
Definition: blpapi_element.h:2196
Float64 getValueAsFloat64(size_t index=0) const
Definition: blpapi_element.h:2189
#define BLPAPI_CALL_ELEMENT_SETELEMENTHIGHPRECISIONDATETIME(a1, a2, a3, a4)
Definition: blpapi_call.h:401
int blpapi_Element_setValueBytes(blpapi_Element_t *element, const char *value, size_t length, size_t index)
int blpapi_Element_getValueAsString(const blpapi_Element_t *element, const char **buffer, size_t index)
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
int blpapi_Element_getValueAsInt32(const blpapi_Element_t *element, blpapi_Int32_t *buffer, size_t index)
int blpapi_Element_isReadOnly(const blpapi_Element_t *element)
int blpapi_Element_isNull(const blpapi_Element_t *element)
Common definitions used by the library.
bool isValid() const
Definition: blpapi_element.h:2002
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
int blpapi_Element_hasElement(const blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name)
Represents a date and/or time.
Float32 getElementAsFloat32(const char *name) const
Definition: blpapi_element.h:2282
Float64 getElementAsFloat64(const char *name) const
Definition: blpapi_element.h:2292
Definition: blpapi_abstractsession.h:220
Definition: blpapi_name.h:150
#define BLPAPI_CALL(FUNCNAME)
Definition: blpapi_call.h:353
blpapi_Float64_t Float64
Definition: blpapi_types.h:474
Element getChoice() const
Definition: blpapi_element.h:2234
bool getValueAsBool(size_t index=0) const
Definition: blpapi_element.h:2154
int blpapi_Element_isComplexType(const blpapi_Element_t *element)
int blpapi_Element_getValueAsChar(const blpapi_Element_t *element, blpapi_Char_t *buffer, size_t index)
int blpapi_Element_getValueAsName(const blpapi_Element_t *element, blpapi_Name_t **buffer, size_t index)
bool isNullValue(size_t position=0) const
Definition: blpapi_element.h:2004
int blpapi_Element_setElementChar(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Char_t value)
int blpapi_Element_getValueAsDatetime(const blpapi_Element_t *element, blpapi_Datetime_t *buffer, size_t index)
blpapi_Name_t * impl() const
Definition: blpapi_name.h:403
bool isArray() const
Definition: blpapi_element.h:1972
int blpapi_Int32_t
Definition: blpapi_types.h:67
int blpapi_Element_setElementFloat64(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Float64_t value)
struct blpapi_Name blpapi_Name_t
Definition: blpapi_types.h:154
Name getElementAsName(const char *name) const
Definition: blpapi_element.h:2327
char getValueAsChar(size_t index=0) const
Definition: blpapi_element.h:2161
int blpapi_Element_setValueInt64(blpapi_Element_t *element, blpapi_Int64_t value, size_t index)
int blpapi_Element_isArray(const blpapi_Element_t *element)
bool isComplexType() const
Definition: blpapi_element.h:1967
void appendValue(bool value)
Definition: blpapi_element.h:1830
Definition: blpapi_schema.h:327
int(* blpapi_StreamWriter_t)(const char *data, int length, void *stream)
Definition: blpapi_streamproxy.h:53
int blpapi_Element_setValueFloat64(blpapi_Element_t *element, blpapi_Float64_t value, size_t index)
int blpapi_Bool_t
Definition: blpapi_types.h:62
int blpapi_Element_getValueAsFloat32(const blpapi_Element_t *element, blpapi_Float32_t *buffer, size_t index)
int blpapi_Element_getValueAsBool(const blpapi_Element_t *element, blpapi_Bool_t *buffer, size_t index)
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
size_t blpapi_Element_numElements(const blpapi_Element_t *element)
Element()
Definition: blpapi_element.h:1604
int blpapi_Element_getElementAt(const blpapi_Element_t *element, blpapi_Element_t **result, size_t position)
Name getValueAsName(size_t index=0) const
Definition: blpapi_element.h:2226
#define BLPAPI_ELEMENT_INDEX_END
Definition: blpapi_defs.h:96
struct blpapi_SchemaElementDefinition blpapi_SchemaElementDefinition_t
Definition: blpapi_types.h:191
Datetime getElementAsDatetime(const char *name) const
Definition: blpapi_element.h:2302
int blpapi_Element_setValueChar(blpapi_Element_t *element, blpapi_Char_t value, size_t index)
int blpapi_Element_setValueBool(blpapi_Element_t *element, blpapi_Bool_t value, size_t index)
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
Provide a representation of a schema describing structured messages.
Definition: blpapi_element.h:464
Float32 getValueAsFloat32(size_t index=0) const
Definition: blpapi_element.h:2182
Int32 getValueAsInt32(size_t index=0) const
Definition: blpapi_element.h:2168
Int64 getValueAsInt64(size_t index=0) const
Definition: blpapi_element.h:2175
bool isNull() const
Definition: blpapi_element.h:1977
Bytes getValueAsBytes(size_t index=0) const
Definition: blpapi_element.h:2211
int blpapi_Element_getValueAsHighPrecisionDatetime(const blpapi_Element_t *element, blpapi_HighPrecisionDatetime_t *buffer, size_t index)
Int32 getElementAsInt32(const char *name) const
Definition: blpapi_element.h:2262
size_t numValues() const
Definition: blpapi_element.h:1992
int blpapi_Element_setElementInt32(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Int32_t value)
int blpapi_Element_getElement(const blpapi_Element_t *element, blpapi_Element_t **result, const char *nameString, const blpapi_Name_t *name)
void setValue(bool value, size_t index=0)
Definition: blpapi_element.h:1757
int blpapi_Element_print(const blpapi_Element_t *element, blpapi_StreamWriter_t streamWriter, void *stream, int level, int spacesPerLevel)
int blpapi_Element_datatype(const blpapi_Element_t *element)
int getValueAs(bool *result, size_t index=0) const
Definition: blpapi_element.h:2066
int blpapi_Element_setElementString(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const char *value)
int datatype() const
Definition: blpapi_element.h:1962
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition: blpapi_correlationid.h:592
#define BLPAPI_CALL_ELEMENT_SETVALUEHIGHPRECISIONDATETIME(a1, a2, a3)
Definition: blpapi_call.h:399
size_t blpapi_Element_numValues(const blpapi_Element_t *element)
int blpapi_Element_setValueFloat32(blpapi_Element_t *element, blpapi_Float32_t value, size_t index)
blpapi_Int64_t Int64
Definition: blpapi_types.h:471
int blpapi_Element_setValueFromName(blpapi_Element_t *element, const blpapi_Name_t *value, size_t index)
int blpapi_Element_setValueFromElement(blpapi_Element_t *element, blpapi_Element_t *value, size_t index)
Definition: blpapi_datetime.h:102
int getElement(Element *result, const char *name) const
Definition: blpapi_element.h:1922
#define BLPAPI_CALL_ELEMENT_GETVALUEASHIGHPRECISIONDATETIME(a1, a2, a3)
Definition: blpapi_call.h:403
Int64 getElementAsInt64(const char *name) const
Definition: blpapi_element.h:2272
Element appendElement()
Definition: blpapi_element.h:1891
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition: blpapi_datetime.h:1954
size_t numElements() const
Definition: blpapi_element.h:1997
int blpapi_Element_getValueAsFloat64(const blpapi_Element_t *element, blpapi_Float64_t *buffer, size_t index)
A signature for callback on print and default C++ implementation.
double blpapi_Float64_t
Definition: blpapi_types.h:72
void assign(pointer ptr, size_type length) noexcept
Definition: blpapi_types.h:496
void setElement(const char *name, bool value)
Definition: blpapi_element.h:1619
int blpapi_Element_hasElementEx(const blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, int excludeNullElements, int reserved)
int blpapi_Element_getValueAsInt64(const blpapi_Element_t *element, blpapi_Int64_t *buffer, size_t index)
int blpapi_Element_getValueAsElement(const blpapi_Element_t *element, blpapi_Element_t **buffer, size_t index)
int blpapi_Element_setElementFromField(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Element_t *sourcebuffer)
int blpapi_Element_setElementFloat32(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Float32_t value)
char getElementAsChar(const char *name) const
Definition: blpapi_element.h:2252
char blpapi_Char_t
Definition: blpapi_types.h:63
int blpapi_Element_getValueAsBytes(const blpapi_Element_t *element, const char **buffer, size_t *length, size_t index)
int blpapi_Element_setValueInt32(blpapi_Element_t *element, blpapi_Int32_t value, size_t index)
long long blpapi_Int64_t
Definition: blpapi_types.h:69
const char * blpapi_Element_nameString(const blpapi_Element_t *element)
int blpapi_Element_setValueDatetime(blpapi_Element_t *element, const blpapi_Datetime_t *value, size_t index)
Defines Exceptions that can be thrown by the blpapi library.
int blpapi_Element_setValueHighPrecisionDatetime(blpapi_Element_t *element, const blpapi_HighPrecisionDatetime_t *value, size_t index)
int blpapi_Element_setElementDatetime(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const blpapi_Datetime_t *value)
int blpapi_Element_setValueString(blpapi_Element_t *element, const char *value, size_t index)
bool hasElement(const char *name, bool excludeNullElements=false) const
Definition: blpapi_element.h:2013
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_element.h:2322
Element setChoice(const char *selectionName)
Definition: blpapi_element.h:1899
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2339
float blpapi_Float32_t
Definition: blpapi_types.h:71
static int writeToStream(const char *data, int length, void *stream)
Definition: blpapi_streamproxy.h:93
blpapi_Name_t * blpapi_Element_name(const blpapi_Element_t *element)
Name name() const
Definition: blpapi_element.h:1917
SchemaElementDefinition elementDefinition() const
Definition: blpapi_element.h:1987
int blpapi_Element_setElementBytes(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, const char *value, size_t length)
int blpapi_Element_setElementFromName(blpapi_Element_t *element, const char *elementName, const blpapi_Name_t *name, const blpapi_Name_t *buffer)
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
Definition: blpapi_datetime.h:245
Provide functions for dispatchtbl.
int blpapi_Element_isNullValue(const blpapi_Element_t *element, size_t position)
Provide BLPAPI types.
Element getValueAsElement(size_t index=0) const
Definition: blpapi_element.h:2218
int blpapi_Element_setElementInt64(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Int64_t value)
const char * getElementAsString(const char *name) const
Definition: blpapi_element.h:2312
Provide a representation of strings for use as container keys.
Definition: blpapi_types.h:312
int blpapi_Element_appendElement(blpapi_Element_t *element, blpapi_Element_t **appendedElement)
void rebind(blpapi_Element_t *element)
Definition: blpapi_element.h:1614
Definition: blpapi_datetime.h:115
int blpapi_Element_setElementBool(blpapi_Element_t *element, const char *nameString, const blpapi_Name_t *name, blpapi_Bool_t value)
bool isReadOnly() const
Definition: blpapi_element.h:1982
const char * getValueAsString(size_t index=0) const
Definition: blpapi_element.h:2203