BLPAPI C++  3.21.0
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  Element(blpapi_Element_t *element);
477 
478  // MANIPULATORS
479 
480  void rebind(blpapi_Element_t *element);
481 
482  void setElement(const char *name, bool value);
495  void setElement(const char *name, char value);
508  void setElement(const char *name, Int32 value);
521  void setElement(const char *name, Int64 value);
534  void setElement(const char *name, Float32 value);
547  void setElement(const char *name, Float64 value);
560  void setElement(const char *name, const Datetime& value);
573  void setElement(const char *name, const char *value);
586  void setElement(const char *name, const Name& value);
600  void setElement(const Name& name, bool value);
611  void setElement(const Name& name, char value);
622  void setElement(const Name& name, Int32 value);
633  void setElement(const Name& name, Int64 value);
644  void setElement(const Name& name, Float32 value);
655  void setElement(const Name& name, Float64 value);
666  void setElement(const Name& name, const Datetime& value);
677  void setElement(const Name& name, const char *value);
688  void setElement(const Name& name, const std::string& value);
700  void setElement(const Name& name, const Name& value);
711  void setElement(const Name& name, const void *value, size_t length);
722  template <typename BYTES,
723  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
724  = true>
725  void setElement(const Name& name, const BYTES& value);
741  void setValue(bool value, size_t index = 0);
750  void setValue(char value, size_t index = 0);
759  void setValue(Int32 value, size_t index = 0);
768  void setValue(Int64 value, size_t index = 0);
777  void setValue(Float32 value, size_t index = 0);
786  void setValue(Float64 value, size_t index = 0);
795  void setValue(const Datetime& value, size_t index = 0);
804  void setValue(const char *value, size_t index = 0);
813  void setValue(const std::string& value, size_t index = 0);
823  void setValue(const Name& valueName, size_t index = 0);
833  void setValue(const void *value, size_t length, size_t index);
842  template <typename BYTES,
843  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
844  = true>
845  void setValue(const BYTES& value, size_t index = 0);
859  void appendValue(bool value);
869  void appendValue(char value);
879  void appendValue(Int32 value);
889  void appendValue(Int64 value);
899  void appendValue(Float32 value);
909  void appendValue(Float64 value);
919  void appendValue(const Datetime& value);
929  void appendValue(const char *value);
939  void appendValue(const std::string& value);
951  void appendValue(const Name& value);
969  Element setChoice(const char *selectionName);
979  Element setChoice(const Name& selectionName);
988 
989  // ACCESSORS
990 
991  Name name() const;
1000  int datatype() const;
1008  bool isComplexType() const;
1014  bool isArray() const;
1021  bool isNull() const;
1026  bool isReadOnly() const;
1037  size_t numValues() const;
1047  size_t numElements() const;
1055  bool isValid() const;
1062  bool isNullValue(size_t position = 0) const;
1070  bool hasElement(const char *name, bool excludeNullElements = false) const;
1079  bool hasElement(const Name& name, bool excludeNullElements = false) const;
1086  int getValueAs(bool *result, size_t index = 0) const;
1095  int getValueAs(char *result, size_t index = 0) const;
1104  int getValueAs(Int32 *result, size_t index = 0) const;
1113  int getValueAs(Int64 *result, size_t index = 0) const;
1122  int getValueAs(Float32 *result, size_t index = 0) const;
1131  int getValueAs(Float64 *result, size_t index = 0) const;
1140  int getValueAs(Datetime *result, size_t index = 0) const;
1152  int getValueAs(std::string *result, size_t index = 0) const;
1161  int getValueAs(Bytes *result, size_t index = 0) const;
1169  int getValueAs(Element *result, size_t index = 0) const;
1178  int getValueAs(Name *result, size_t index = 0) const;
1186  bool getValueAsBool(size_t index = 0) const;
1193  char getValueAsChar(size_t index = 0) const;
1200  Int32 getValueAsInt32(size_t index = 0) const;
1207  Int64 getValueAsInt64(size_t index = 0) const;
1214  Float32 getValueAsFloat32(size_t index = 0) const;
1221  Float64 getValueAsFloat64(size_t index = 0) const;
1228  Datetime getValueAsDatetime(size_t index = 0) const;
1239  const char *getValueAsString(size_t index = 0) const;
1248  Bytes getValueAsBytes(size_t index = 0) const;
1256  Element getValueAsElement(size_t index = 0) const;
1264  Name getValueAsName(size_t index = 0) const;
1271  int getElement(Element *result, const char *name) const;
1282  int getElement(Element *result, const Name& name) const;
1291  int getElement(Element *result, size_t position) const;
1300  Element getElement(size_t position) const;
1308  Element getElement(const Name& name) const;
1316  Element getElement(const char *name) const;
1327  bool getElementAsBool(const char *name) const;
1338  bool getElementAsBool(const Name& name) const;
1347  char getElementAsChar(const char *name) const;
1358  char getElementAsChar(const Name& name) const;
1367  Int32 getElementAsInt32(const char *name) const;
1378  Int32 getElementAsInt32(const Name& name) const;
1387  Int64 getElementAsInt64(const char *name) const;
1398  Int64 getElementAsInt64(const Name& name) const;
1407  Float32 getElementAsFloat32(const char *name) const;
1418  Float32 getElementAsFloat32(const Name& name) const;
1427  Float64 getElementAsFloat64(const char *name) const;
1438  Float64 getElementAsFloat64(const Name& name) const;
1447  Datetime getElementAsDatetime(const char *name) const;
1462  Datetime getElementAsDatetime(const Name& name) const;
1474  const char *getElementAsString(const char *name) const;
1486  const char *getElementAsString(const Name& name) const;
1496  Bytes getElementAsBytes(const Name& name) const;
1506  Name getElementAsName(const char *name) const;
1517  Name getElementAsName(const Name& name) const;
1526  Element getChoice() const;
1532  const blpapi_Element_t *handle() const;
1533 
1534  std::ostream& print(
1535  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
1548 };
1549 
1553 // FREE OPERATORS
1554 std::ostream& operator<<(std::ostream& stream, const Element& element);
1568 // ============================================================================
1569 // INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
1570 // ============================================================================
1571 
1572 // -------------
1573 // class Element
1574 // -------------
1575 
1577  : d_handle_p(0)
1578 {
1579 }
1580 
1582  : d_handle_p(newHandle)
1583 {
1584 }
1585 
1586 inline void Element::rebind(blpapi_Element_t *element)
1587 {
1588  d_handle_p = element;
1589 }
1590 
1591 inline void Element::setElement(const char *elementName, bool value)
1592 {
1594  d_handle_p, elementName, 0, value ? 1 : 0));
1595 }
1596 
1597 inline void Element::setElement(const char *elementName, char value)
1598 {
1600  blpapi_Element_setElementChar(d_handle_p, elementName, 0, value));
1601 }
1602 
1603 inline void Element::setElement(const char *elementName, Int32 value)
1604 {
1606  blpapi_Element_setElementInt32(d_handle_p, elementName, 0, value));
1607 }
1608 
1609 inline void Element::setElement(const char *elementName, Int64 value)
1610 {
1612  blpapi_Element_setElementInt64(d_handle_p, elementName, 0, value));
1613 }
1614 
1615 inline void Element::setElement(const char *elementName, Float32 value)
1616 {
1618  d_handle_p, elementName, 0, value));
1619 }
1620 
1621 inline void Element::setElement(const char *elementName, Float64 value)
1622 {
1624  d_handle_p, elementName, 0, value));
1625 }
1626 
1627 inline void Element::setElement(const char *elementName, const Datetime& value)
1628 {
1631  elementName,
1632  0,
1633  &value.rawHighPrecisionValue()));
1634 }
1635 
1636 inline void Element::setElement(const char *elementName, const char *value)
1637 {
1639  d_handle_p, elementName, 0, value));
1640 }
1641 
1642 inline void Element::setElement(const char *elementName, const Name& value)
1643 {
1645  d_handle_p, elementName, 0, value.impl()));
1646 }
1647 
1648 inline void Element::setElement(const Name& elementName, bool value)
1649 {
1651  d_handle_p, 0, elementName.impl(), value ? 1 : 0));
1652 }
1653 
1654 inline void Element::setElement(const Name& elementName, char value)
1655 {
1657  d_handle_p, 0, elementName.impl(), value));
1658 }
1659 
1660 inline void Element::setElement(const Name& elementName, Int32 value)
1661 {
1663  d_handle_p, 0, elementName.impl(), value));
1664 }
1665 
1666 inline void Element::setElement(const Name& elementName, Int64 value)
1667 {
1669  d_handle_p, 0, elementName.impl(), value));
1670 }
1671 
1672 inline void Element::setElement(const Name& elementName, Float32 value)
1673 {
1675  d_handle_p, 0, elementName.impl(), value));
1676 }
1677 
1678 inline void Element::setElement(const Name& elementName, Float64 value)
1679 {
1681  d_handle_p, 0, elementName.impl(), value));
1682 }
1683 
1684 inline void Element::setElement(const Name& elementName, const Datetime& value)
1685 {
1688  0,
1689  elementName.impl(),
1690  &value.rawHighPrecisionValue()));
1691 }
1692 
1693 inline void Element::setElement(const Name& elementName, const char *value)
1694 {
1696  d_handle_p, 0, elementName.impl(), value));
1697 }
1698 
1700  const Name& elementName, const std::string& value)
1701 {
1702  setElement(elementName, value.c_str());
1703 }
1704 
1705 inline void Element::setElement(const Name& elementName, const Name& value)
1706 {
1708  d_handle_p, 0, elementName.impl(), value.impl()));
1709 }
1710 
1712  const Name& elementName, const void *value, size_t length)
1713 {
1716  0,
1717  elementName.impl(),
1718  reinterpret_cast<const char *>(value),
1719  length));
1720 }
1721 
1722 template <typename BYTES,
1723  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1724 inline void Element::setElement(const Name& elementName, const BYTES& value)
1725 {
1726  setElement(elementName, value.data(), value.size());
1727 }
1728 
1729 inline void Element::setValue(bool value, size_t index)
1730 {
1732  blpapi_Element_setValueBool(d_handle_p, value, index));
1733 }
1734 
1735 inline void Element::setValue(char value, size_t index)
1736 {
1738  blpapi_Element_setValueChar(d_handle_p, value, index));
1739 }
1740 
1741 inline void Element::setValue(Int32 value, size_t index)
1742 {
1744  blpapi_Element_setValueInt32(d_handle_p, value, index));
1745 }
1746 
1747 inline void Element::setValue(Int64 value, size_t index)
1748 {
1750  blpapi_Element_setValueInt64(d_handle_p, value, index));
1751 }
1752 
1753 inline void Element::setValue(Float32 value, size_t index)
1754 {
1756  blpapi_Element_setValueFloat32(d_handle_p, value, index));
1757 }
1758 
1759 inline void Element::setValue(Float64 value, size_t index)
1760 {
1762  blpapi_Element_setValueFloat64(d_handle_p, value, index));
1763 }
1764 
1765 inline void Element::setValue(const Datetime& value, size_t index)
1766 {
1769  d_handle_p, &value.rawHighPrecisionValue(), index));
1770 }
1771 
1772 inline void Element::setValue(const char *value, size_t index)
1773 {
1775  blpapi_Element_setValueString(d_handle_p, value, index));
1776 }
1777 
1778 inline void Element::setValue(const std::string& value, size_t index)
1779 {
1780  setValue(value.c_str(), index);
1781 }
1782 
1783 inline void Element::setValue(const Name& valueName, size_t index)
1784 {
1786  d_handle_p, valueName.impl(), index));
1787 }
1788 
1789 inline void Element::setValue(const void *value, size_t length, size_t index)
1790 {
1792  d_handle_p, reinterpret_cast<const char *>(value), length, index));
1793 }
1794 
1795 template <typename BYTES,
1796  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
1797 inline void Element::setValue(const BYTES& value, size_t index)
1798 {
1799  setValue(value.data(), value.size(), index);
1800 }
1801 
1802 inline void Element::appendValue(bool value)
1803 {
1805  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1806 }
1807 
1808 inline void Element::appendValue(char value)
1809 {
1811  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1812 }
1813 
1814 inline void Element::appendValue(Int32 value)
1815 {
1817  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1818 }
1819 
1820 inline void Element::appendValue(Int64 value)
1821 {
1823  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1824 }
1825 
1826 inline void Element::appendValue(Float32 value)
1827 {
1829  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1830 }
1831 
1832 inline void Element::appendValue(Float64 value)
1833 {
1835  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1836 }
1837 
1838 inline void Element::appendValue(const Datetime& value)
1839 {
1842  &value.rawHighPrecisionValue(),
1844 }
1845 
1846 inline void Element::appendValue(const char *value)
1847 {
1849  d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
1850 }
1851 
1852 inline void Element::appendValue(const std::string& value)
1853 {
1854  appendValue(value.c_str());
1855 }
1856 
1857 inline void Element::appendValue(const Name& valueName)
1858 {
1860  d_handle_p, valueName.impl(), BLPAPI_ELEMENT_INDEX_END));
1861 }
1862 
1864 {
1865  blpapi_Element_t *appendedElement = 0;
1867  blpapi_Element_appendElement(d_handle_p, &appendedElement));
1868  return Element(appendedElement);
1869 }
1870 
1871 inline Element Element::setChoice(const char *selectionName)
1872 {
1873  blpapi_Element_t *resultElement = 0;
1875  d_handle_p, &resultElement, selectionName, 0, 0));
1876  return Element(resultElement);
1877 }
1878 
1879 inline Element Element::setChoice(const Name& selectionName)
1880 {
1881  blpapi_Element_t *resultElement = 0;
1883  d_handle_p, &resultElement, 0, selectionName.impl(), 0));
1884  return Element(resultElement);
1885 }
1886 
1887 inline blpapi_Element_t *Element::handle() { return d_handle_p; }
1888 
1889 inline Name Element::name() const { return blpapi_Element_name(d_handle_p); }
1890 
1891 inline int Element::getElement(Element *element, const char *nameString) const
1892 {
1893  assert(element);
1894 
1895  blpapi_Element_t *fldt = 0;
1896  int rc = blpapi_Element_getElement(d_handle_p, &fldt, nameString, 0);
1897  if (!rc) {
1898  element->rebind(fldt);
1899  }
1900 
1901  return rc;
1902 }
1903 
1904 inline int Element::getElement(Element *element, const Name& elementName) const
1905 {
1906  assert(element);
1907 
1908  blpapi_Element_t *fldt = 0;
1909  int rc = blpapi_Element_getElement(
1910  d_handle_p, &fldt, 0, elementName.impl());
1911  if (!rc) {
1912  element->rebind(fldt);
1913  }
1914 
1915  return rc;
1916 }
1917 
1918 inline int Element::getElement(Element *element, size_t position) const
1919 {
1920  assert(element);
1921 
1922  blpapi_Element_t *fldt = 0;
1923  int rc = blpapi_Element_getElementAt(d_handle_p, &fldt, position);
1924  if (!rc) {
1925  element->rebind(fldt);
1926  }
1927 
1928  return rc;
1929 }
1930 
1931 inline int Element::datatype() const
1932 {
1933  return blpapi_Element_datatype(d_handle_p);
1934 }
1935 
1936 inline bool Element::isComplexType() const
1937 {
1938  return blpapi_Element_isComplexType(d_handle_p) ? true : false;
1939 }
1940 
1941 inline bool Element::isArray() const
1942 {
1943  return blpapi_Element_isArray(d_handle_p) ? true : false;
1944 }
1945 
1946 inline bool Element::isNull() const
1947 {
1948  return blpapi_Element_isNull(d_handle_p) ? true : false;
1949 }
1950 
1951 inline bool Element::isReadOnly() const
1952 {
1953  return blpapi_Element_isReadOnly(d_handle_p) ? true : false;
1954 }
1955 
1957 {
1958  return blpapi_Element_definition(d_handle_p);
1959 }
1960 
1961 inline size_t Element::numValues() const
1962 {
1963  return blpapi_Element_numValues(d_handle_p);
1964 }
1965 
1966 inline size_t Element::numElements() const
1967 {
1968  return blpapi_Element_numElements(d_handle_p);
1969 }
1970 
1971 inline bool Element::isValid() const { return d_handle_p ? true : false; }
1972 
1973 inline bool Element::isNullValue(size_t position) const
1974 {
1975  int rc = blpapi_Element_isNullValue(d_handle_p, position);
1976  if (rc != 0 && rc != 1) {
1978  }
1979  return rc ? true : false;
1980 }
1981 
1983  const char *nameString, bool excludeNullElements) const
1984 {
1985  if (excludeNullElements) {
1987  d_handle_p, nameString, 0, excludeNullElements, 0)
1988  ? true
1989  : false);
1990  }
1991  return blpapi_Element_hasElement(d_handle_p, nameString, 0) ? true : false;
1992 }
1993 
1995  const Name& elementName, bool excludeNullElements) const
1996 {
1997  if (excludeNullElements) {
1998  return (blpapi_Element_hasElementEx(d_handle_p,
1999  0,
2000  elementName.impl(),
2001  excludeNullElements,
2002  0)
2003  ? true
2004  : false);
2005  }
2006  return blpapi_Element_hasElement(d_handle_p, 0, elementName.impl())
2007  ? true
2008  : false;
2009 }
2010 
2011 inline Element Element::getElement(const Name& elementName) const
2012 {
2013  blpapi_Element_t *fldt = 0;
2015  d_handle_p, &fldt, 0, elementName.impl()));
2016  return Element(fldt);
2017 }
2018 
2019 inline Element Element::getElement(const char *elementName) const
2020 {
2021  blpapi_Element_t *fldt = 0;
2023  blpapi_Element_getElement(d_handle_p, &fldt, elementName, 0));
2024  return Element(fldt);
2025 }
2026 
2027 inline Element Element::getElement(size_t position) const
2028 {
2029  blpapi_Element_t *element = 0;
2031  blpapi_Element_getElementAt(d_handle_p, &element, position));
2032  return Element(element);
2033 }
2034 
2035 inline int Element::getValueAs(bool *buffer, size_t index) const
2036 {
2037  assert(buffer);
2038 
2039  blpapi_Bool_t tmp = false;
2040 
2041  int res = blpapi_Element_getValueAsBool(d_handle_p, &tmp, index);
2042  *buffer = tmp ? true : false;
2043  return res;
2044 }
2045 
2046 inline int Element::getValueAs(char *buffer, size_t index) const
2047 {
2048  return blpapi_Element_getValueAsChar(d_handle_p, buffer, index);
2049 }
2050 
2051 inline int Element::getValueAs(Int32 *buffer, size_t index) const
2052 {
2053  return blpapi_Element_getValueAsInt32(d_handle_p, buffer, index);
2054 }
2055 
2056 inline int Element::getValueAs(Int64 *buffer, size_t index) const
2057 {
2058  return blpapi_Element_getValueAsInt64(d_handle_p, buffer, index);
2059 }
2060 
2061 inline int Element::getValueAs(Float32 *buffer, size_t index) const
2062 {
2063  return blpapi_Element_getValueAsFloat32(d_handle_p, buffer, index);
2064 }
2065 
2066 inline int Element::getValueAs(Float64 *buffer, size_t index) const
2067 {
2068  return blpapi_Element_getValueAsFloat64(d_handle_p, buffer, index);
2069 }
2070 
2071 inline int Element::getValueAs(Datetime *buffer, size_t index) const
2072 {
2074  d_handle_p, buffer, index);
2075 }
2076 
2077 inline int Element::getValueAs(std::string *result, size_t index) const
2078 {
2079  assert(result);
2080 
2081  const char *buffer = 0;
2082  int rc = blpapi_Element_getValueAsString(d_handle_p, &buffer, index);
2083  if (!rc) {
2084  *result = buffer;
2085  }
2086  return rc;
2087 }
2088 
2089 inline int Element::getValueAs(Bytes *result, size_t index) const
2090 {
2091  assert(result);
2092 
2093  const char *buffer = 0;
2094  size_t length = 0;
2096  d_handle_p, &buffer, &length, index);
2097  if (!rc) {
2098  result->assign(buffer, length);
2099  }
2100  return rc;
2101 }
2102 
2103 inline int Element::getValueAs(Element *buffer, size_t index) const
2104 {
2105  assert(buffer);
2106 
2108  d_handle_p, &buffer->d_handle_p, index);
2109 }
2110 
2111 inline int Element::getValueAs(Name *buffer, size_t index) const
2112 {
2113  assert(buffer);
2114 
2115  blpapi_Name_t *tmpName = 0;
2116  int res = blpapi_Element_getValueAsName(d_handle_p, &tmpName, index);
2117  if (!res) {
2118  *buffer = Name(tmpName);
2119  }
2120  return res;
2121 }
2122 
2123 inline bool Element::getValueAsBool(size_t index) const
2124 {
2125  bool value = false;
2126  ExceptionUtil::throwOnError(getValueAs(&value, index));
2127  return value;
2128 }
2129 
2130 inline char Element::getValueAsChar(size_t index) const
2131 {
2132  char value = 0;
2133  ExceptionUtil::throwOnError(getValueAs(&value, index));
2134  return value;
2135 }
2136 
2137 inline Int32 Element::getValueAsInt32(size_t index) const
2138 {
2139  Int32 value = 0;
2140  ExceptionUtil::throwOnError(getValueAs(&value, index));
2141  return value;
2142 }
2143 
2144 inline Int64 Element::getValueAsInt64(size_t index) const
2145 {
2146  Int64 value = 0;
2147  ExceptionUtil::throwOnError(getValueAs(&value, index));
2148  return value;
2149 }
2150 
2151 inline Float32 Element::getValueAsFloat32(size_t index) const
2152 {
2153  Float32 value = 0.0;
2154  ExceptionUtil::throwOnError(getValueAs(&value, index));
2155  return value;
2156 }
2157 
2158 inline Float64 Element::getValueAsFloat64(size_t index) const
2159 {
2160  Float64 value = 0.0;
2161  ExceptionUtil::throwOnError(getValueAs(&value, index));
2162  return value;
2163 }
2164 
2165 inline Datetime Element::getValueAsDatetime(size_t index) const
2166 {
2167  Datetime value;
2168  ExceptionUtil::throwOnError(getValueAs(&value, index));
2169  return value;
2170 }
2171 
2172 inline const char *Element::getValueAsString(size_t index) const
2173 {
2174  const char *tmpStringBuffer = 0;
2176  d_handle_p, &tmpStringBuffer, index));
2177  return tmpStringBuffer;
2178 }
2179 
2180 inline Bytes Element::getValueAsBytes(size_t index) const
2181 {
2182  Bytes value;
2183  ExceptionUtil::throwOnError(getValueAs(&value, index));
2184  return value;
2185 }
2186 
2187 inline Element Element::getValueAsElement(size_t index) const
2188 {
2189  blpapi_Element_t *element = 0;
2191  blpapi_Element_getValueAsElement(d_handle_p, &element, index));
2192  return Element(element);
2193 }
2194 
2195 inline Name Element::getValueAsName(size_t index) const
2196 {
2197  blpapi_Name_t *nameValue = 0;
2199  blpapi_Element_getValueAsName(d_handle_p, &nameValue, index));
2200  return nameValue;
2201 }
2202 
2204 {
2205  blpapi_Element_t *element = 0;
2207  blpapi_Element_getChoice(d_handle_p, &element));
2208  return Element(element);
2209 }
2210 
2211 inline bool Element::getElementAsBool(const char *elementName) const
2212 {
2213  return getElement(elementName).getValueAsBool();
2214 }
2215 
2216 inline bool Element::getElementAsBool(const Name& elementName) const
2217 {
2218  return getElement(elementName).getValueAsBool();
2219 }
2220 
2221 inline char Element::getElementAsChar(const char *elementName) const
2222 {
2223  return getElement(elementName).getValueAsChar();
2224 }
2225 
2226 inline char Element::getElementAsChar(const Name& elementName) const
2227 {
2228  return getElement(elementName).getValueAsChar();
2229 }
2230 
2231 inline Int32 Element::getElementAsInt32(const char *elementName) const
2232 {
2233  return getElement(elementName).getValueAsInt32();
2234 }
2235 
2236 inline Int32 Element::getElementAsInt32(const Name& elementName) const
2237 {
2238  return getElement(elementName).getValueAsInt32();
2239 }
2240 
2241 inline Int64 Element::getElementAsInt64(const char *elementName) const
2242 {
2243  return getElement(elementName).getValueAsInt64();
2244 }
2245 
2246 inline Int64 Element::getElementAsInt64(const Name& elementName) const
2247 {
2248  return getElement(elementName).getValueAsInt64();
2249 }
2250 
2251 inline Float32 Element::getElementAsFloat32(const char *elementName) const
2252 {
2253  return getElement(elementName).getValueAsFloat32();
2254 }
2255 
2256 inline Float32 Element::getElementAsFloat32(const Name& elementName) const
2257 {
2258  return getElement(elementName).getValueAsFloat32();
2259 }
2260 
2261 inline Float64 Element::getElementAsFloat64(const char *elementName) const
2262 {
2263  return getElement(elementName).getValueAsFloat64();
2264 }
2265 
2266 inline Float64 Element::getElementAsFloat64(const Name& elementName) const
2267 {
2268  return getElement(elementName).getValueAsFloat64();
2269 }
2270 
2271 inline Datetime Element::getElementAsDatetime(const char *elementName) const
2272 {
2273  return getElement(elementName).getValueAsDatetime();
2274 }
2275 
2276 inline Datetime Element::getElementAsDatetime(const Name& elementName) const
2277 {
2278  return getElement(elementName).getValueAsDatetime();
2279 }
2280 
2281 inline const char *Element::getElementAsString(const char *elementName) const
2282 {
2283  return getElement(elementName).getValueAsString();
2284 }
2285 
2286 inline const char *Element::getElementAsString(const Name& elementName) const
2287 {
2288  return getElement(elementName).getValueAsString();
2289 }
2290 
2291 inline Bytes Element::getElementAsBytes(const Name& elementName) const
2292 {
2293  return getElement(elementName).getValueAsBytes();
2294 }
2295 
2296 inline Name Element::getElementAsName(const char *elementName) const
2297 {
2298  return getElement(elementName).getValueAsName();
2299 }
2300 
2301 inline Name Element::getElementAsName(const Name& elementName) const
2302 {
2303  return getElement(elementName).getValueAsName();
2304 }
2305 
2306 inline const blpapi_Element_t *Element::handle() const { return d_handle_p; }
2307 
2308 inline std::ostream& Element::print(
2309  std::ostream& stream, int level, int spacesPerLevel) const
2310 {
2311  blpapi_Element_print(d_handle_p,
2313  &stream,
2314  level,
2315  spacesPerLevel);
2316  return stream;
2317 }
2318 
2319 inline std::ostream& operator<<(std::ostream& stream, const Element& element)
2320 {
2321  element.print(stream, 0, -1);
2322  return stream;
2323 }
2324 
2325 } // close namespace blpapi
2326 } // close namespace BloombergLP
2327 
2328 #endif // #ifdef __cplusplus
2329 #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:1887
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:2211
Datetime getValueAsDatetime(size_t index=0) const
Definition: blpapi_element.h:2165
Float64 getValueAsFloat64(size_t index=0) const
Definition: blpapi_element.h:2158
#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:1971
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:2251
Float64 getElementAsFloat64(const char *name) const
Definition: blpapi_element.h:2261
Definition: blpapi_abstractsession.h:215
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:2203
bool getValueAsBool(size_t index=0) const
Definition: blpapi_element.h:2123
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:1973
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:1941
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:2296
char getValueAsChar(size_t index=0) const
Definition: blpapi_element.h:2130
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:1936
void appendValue(bool value)
Definition: blpapi_element.h:1802
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:1576
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:2195
#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:2271
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:2151
Int32 getValueAsInt32(size_t index=0) const
Definition: blpapi_element.h:2137
Int64 getValueAsInt64(size_t index=0) const
Definition: blpapi_element.h:2144
bool isNull() const
Definition: blpapi_element.h:1946
Bytes getValueAsBytes(size_t index=0) const
Definition: blpapi_element.h:2180
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:2231
size_t numValues() const
Definition: blpapi_element.h:1961
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:1729
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:2035
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:1931
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:1891
#define BLPAPI_CALL_ELEMENT_GETVALUEASHIGHPRECISIONDATETIME(a1, a2, a3)
Definition: blpapi_call.h:403
Int64 getElementAsInt64(const char *name) const
Definition: blpapi_element.h:2241
Element appendElement()
Definition: blpapi_element.h:1863
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition: blpapi_datetime.h:1954
size_t numElements() const
Definition: blpapi_element.h:1966
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:1591
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:2221
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:1982
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_element.h:2291
Element setChoice(const char *selectionName)
Definition: blpapi_element.h:1871
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2308
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:1889
SchemaElementDefinition elementDefinition() const
Definition: blpapi_element.h:1956
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:2187
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:2281
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:1586
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:1951
const char * getValueAsString(size_t index=0) const
Definition: blpapi_element.h:2172