BLPAPI C++  3.24.2
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  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
1890 {
1891  return Name(blpapi_Element_name(d_handle_p));
1892 }
1893 
1894 inline int Element::getElement(Element *element, const char *nameString) const
1895 {
1896  assert(element);
1897 
1898  blpapi_Element_t *fldt = 0;
1899  int rc = blpapi_Element_getElement(d_handle_p, &fldt, nameString, 0);
1900  if (!rc) {
1901  element->rebind(fldt);
1902  }
1903 
1904  return rc;
1905 }
1906 
1907 inline int Element::getElement(Element *element, const Name& elementName) const
1908 {
1909  assert(element);
1910 
1911  blpapi_Element_t *fldt = 0;
1912  int rc = blpapi_Element_getElement(
1913  d_handle_p, &fldt, 0, elementName.impl());
1914  if (!rc) {
1915  element->rebind(fldt);
1916  }
1917 
1918  return rc;
1919 }
1920 
1921 inline int Element::getElement(Element *element, size_t position) const
1922 {
1923  assert(element);
1924 
1925  blpapi_Element_t *fldt = 0;
1926  int rc = blpapi_Element_getElementAt(d_handle_p, &fldt, position);
1927  if (!rc) {
1928  element->rebind(fldt);
1929  }
1930 
1931  return rc;
1932 }
1933 
1934 inline int Element::datatype() const
1935 {
1936  return blpapi_Element_datatype(d_handle_p);
1937 }
1938 
1939 inline bool Element::isComplexType() const
1940 {
1941  return blpapi_Element_isComplexType(d_handle_p) ? true : false;
1942 }
1943 
1944 inline bool Element::isArray() const
1945 {
1946  return blpapi_Element_isArray(d_handle_p) ? true : false;
1947 }
1948 
1949 inline bool Element::isNull() const
1950 {
1951  return blpapi_Element_isNull(d_handle_p) ? true : false;
1952 }
1953 
1954 inline bool Element::isReadOnly() const
1955 {
1956  return blpapi_Element_isReadOnly(d_handle_p) ? true : false;
1957 }
1958 
1960 {
1962 }
1963 
1964 inline size_t Element::numValues() const
1965 {
1966  return blpapi_Element_numValues(d_handle_p);
1967 }
1968 
1969 inline size_t Element::numElements() const
1970 {
1971  return blpapi_Element_numElements(d_handle_p);
1972 }
1973 
1974 inline bool Element::isValid() const { return d_handle_p ? true : false; }
1975 
1976 inline bool Element::isNullValue(size_t position) const
1977 {
1978  int rc = blpapi_Element_isNullValue(d_handle_p, position);
1979  if (rc != 0 && rc != 1) {
1981  }
1982  return rc ? true : false;
1983 }
1984 
1986  const char *nameString, bool excludeNullElements) const
1987 {
1988  if (excludeNullElements) {
1990  d_handle_p, nameString, 0, excludeNullElements, 0)
1991  ? true
1992  : false);
1993  }
1994  return blpapi_Element_hasElement(d_handle_p, nameString, 0) ? true : false;
1995 }
1996 
1998  const Name& elementName, bool excludeNullElements) const
1999 {
2000  if (excludeNullElements) {
2001  return (blpapi_Element_hasElementEx(d_handle_p,
2002  0,
2003  elementName.impl(),
2004  excludeNullElements,
2005  0)
2006  ? true
2007  : false);
2008  }
2009  return blpapi_Element_hasElement(d_handle_p, 0, elementName.impl())
2010  ? true
2011  : false;
2012 }
2013 
2014 inline Element Element::getElement(const Name& elementName) const
2015 {
2016  blpapi_Element_t *fldt = 0;
2018  d_handle_p, &fldt, 0, elementName.impl()));
2019  return Element(fldt);
2020 }
2021 
2022 inline Element Element::getElement(const char *elementName) const
2023 {
2024  blpapi_Element_t *fldt = 0;
2026  blpapi_Element_getElement(d_handle_p, &fldt, elementName, 0));
2027  return Element(fldt);
2028 }
2029 
2030 inline Element Element::getElement(size_t position) const
2031 {
2032  blpapi_Element_t *element = 0;
2034  blpapi_Element_getElementAt(d_handle_p, &element, position));
2035  return Element(element);
2036 }
2037 
2038 inline int Element::getValueAs(bool *buffer, size_t index) const
2039 {
2040  assert(buffer);
2041 
2042  blpapi_Bool_t tmp = false;
2043 
2044  int res = blpapi_Element_getValueAsBool(d_handle_p, &tmp, index);
2045  *buffer = tmp ? true : false;
2046  return res;
2047 }
2048 
2049 inline int Element::getValueAs(char *buffer, size_t index) const
2050 {
2051  return blpapi_Element_getValueAsChar(d_handle_p, buffer, index);
2052 }
2053 
2054 inline int Element::getValueAs(Int32 *buffer, size_t index) const
2055 {
2056  return blpapi_Element_getValueAsInt32(d_handle_p, buffer, index);
2057 }
2058 
2059 inline int Element::getValueAs(Int64 *buffer, size_t index) const
2060 {
2061  return blpapi_Element_getValueAsInt64(d_handle_p, buffer, index);
2062 }
2063 
2064 inline int Element::getValueAs(Float32 *buffer, size_t index) const
2065 {
2066  return blpapi_Element_getValueAsFloat32(d_handle_p, buffer, index);
2067 }
2068 
2069 inline int Element::getValueAs(Float64 *buffer, size_t index) const
2070 {
2071  return blpapi_Element_getValueAsFloat64(d_handle_p, buffer, index);
2072 }
2073 
2074 inline int Element::getValueAs(Datetime *buffer, size_t index) const
2075 {
2077  d_handle_p, buffer, index);
2078 }
2079 
2080 inline int Element::getValueAs(std::string *result, size_t index) const
2081 {
2082  assert(result);
2083 
2084  const char *buffer = 0;
2085  int rc = blpapi_Element_getValueAsString(d_handle_p, &buffer, index);
2086  if (!rc) {
2087  *result = buffer;
2088  }
2089  return rc;
2090 }
2091 
2092 inline int Element::getValueAs(Bytes *result, size_t index) const
2093 {
2094  assert(result);
2095 
2096  const char *buffer = 0;
2097  size_t length = 0;
2099  d_handle_p, &buffer, &length, index);
2100  if (!rc) {
2101  result->assign(buffer, length);
2102  }
2103  return rc;
2104 }
2105 
2106 inline int Element::getValueAs(Element *buffer, size_t index) const
2107 {
2108  assert(buffer);
2109 
2111  d_handle_p, &buffer->d_handle_p, index);
2112 }
2113 
2114 inline int Element::getValueAs(Name *buffer, size_t index) const
2115 {
2116  assert(buffer);
2117 
2118  blpapi_Name_t *tmpName = 0;
2119  int res = blpapi_Element_getValueAsName(d_handle_p, &tmpName, index);
2120  if (!res) {
2121  *buffer = Name(tmpName);
2122  }
2123  return res;
2124 }
2125 
2126 inline bool Element::getValueAsBool(size_t index) const
2127 {
2128  bool value = false;
2129  ExceptionUtil::throwOnError(getValueAs(&value, index));
2130  return value;
2131 }
2132 
2133 inline char Element::getValueAsChar(size_t index) const
2134 {
2135  char value = 0;
2136  ExceptionUtil::throwOnError(getValueAs(&value, index));
2137  return value;
2138 }
2139 
2140 inline Int32 Element::getValueAsInt32(size_t index) const
2141 {
2142  Int32 value = 0;
2143  ExceptionUtil::throwOnError(getValueAs(&value, index));
2144  return value;
2145 }
2146 
2147 inline Int64 Element::getValueAsInt64(size_t index) const
2148 {
2149  Int64 value = 0;
2150  ExceptionUtil::throwOnError(getValueAs(&value, index));
2151  return value;
2152 }
2153 
2154 inline Float32 Element::getValueAsFloat32(size_t index) const
2155 {
2156  Float32 value = 0.0;
2157  ExceptionUtil::throwOnError(getValueAs(&value, index));
2158  return value;
2159 }
2160 
2161 inline Float64 Element::getValueAsFloat64(size_t index) const
2162 {
2163  Float64 value = 0.0;
2164  ExceptionUtil::throwOnError(getValueAs(&value, index));
2165  return value;
2166 }
2167 
2168 inline Datetime Element::getValueAsDatetime(size_t index) const
2169 {
2170  Datetime value;
2171  ExceptionUtil::throwOnError(getValueAs(&value, index));
2172  return value;
2173 }
2174 
2175 inline const char *Element::getValueAsString(size_t index) const
2176 {
2177  const char *tmpStringBuffer = 0;
2179  d_handle_p, &tmpStringBuffer, index));
2180  return tmpStringBuffer;
2181 }
2182 
2183 inline Bytes Element::getValueAsBytes(size_t index) const
2184 {
2185  Bytes value;
2186  ExceptionUtil::throwOnError(getValueAs(&value, index));
2187  return value;
2188 }
2189 
2190 inline Element Element::getValueAsElement(size_t index) const
2191 {
2192  blpapi_Element_t *element = 0;
2194  blpapi_Element_getValueAsElement(d_handle_p, &element, index));
2195  return Element(element);
2196 }
2197 
2198 inline Name Element::getValueAsName(size_t index) const
2199 {
2200  blpapi_Name_t *nameValue = 0;
2202  blpapi_Element_getValueAsName(d_handle_p, &nameValue, index));
2203  return Name(nameValue);
2204 }
2205 
2207 {
2208  blpapi_Element_t *element = 0;
2210  blpapi_Element_getChoice(d_handle_p, &element));
2211  return Element(element);
2212 }
2213 
2214 inline bool Element::getElementAsBool(const char *elementName) const
2215 {
2216  return getElement(elementName).getValueAsBool();
2217 }
2218 
2219 inline bool Element::getElementAsBool(const Name& elementName) const
2220 {
2221  return getElement(elementName).getValueAsBool();
2222 }
2223 
2224 inline char Element::getElementAsChar(const char *elementName) const
2225 {
2226  return getElement(elementName).getValueAsChar();
2227 }
2228 
2229 inline char Element::getElementAsChar(const Name& elementName) const
2230 {
2231  return getElement(elementName).getValueAsChar();
2232 }
2233 
2234 inline Int32 Element::getElementAsInt32(const char *elementName) const
2235 {
2236  return getElement(elementName).getValueAsInt32();
2237 }
2238 
2239 inline Int32 Element::getElementAsInt32(const Name& elementName) const
2240 {
2241  return getElement(elementName).getValueAsInt32();
2242 }
2243 
2244 inline Int64 Element::getElementAsInt64(const char *elementName) const
2245 {
2246  return getElement(elementName).getValueAsInt64();
2247 }
2248 
2249 inline Int64 Element::getElementAsInt64(const Name& elementName) const
2250 {
2251  return getElement(elementName).getValueAsInt64();
2252 }
2253 
2254 inline Float32 Element::getElementAsFloat32(const char *elementName) const
2255 {
2256  return getElement(elementName).getValueAsFloat32();
2257 }
2258 
2259 inline Float32 Element::getElementAsFloat32(const Name& elementName) const
2260 {
2261  return getElement(elementName).getValueAsFloat32();
2262 }
2263 
2264 inline Float64 Element::getElementAsFloat64(const char *elementName) const
2265 {
2266  return getElement(elementName).getValueAsFloat64();
2267 }
2268 
2269 inline Float64 Element::getElementAsFloat64(const Name& elementName) const
2270 {
2271  return getElement(elementName).getValueAsFloat64();
2272 }
2273 
2274 inline Datetime Element::getElementAsDatetime(const char *elementName) const
2275 {
2276  return getElement(elementName).getValueAsDatetime();
2277 }
2278 
2279 inline Datetime Element::getElementAsDatetime(const Name& elementName) const
2280 {
2281  return getElement(elementName).getValueAsDatetime();
2282 }
2283 
2284 inline const char *Element::getElementAsString(const char *elementName) const
2285 {
2286  return getElement(elementName).getValueAsString();
2287 }
2288 
2289 inline const char *Element::getElementAsString(const Name& elementName) const
2290 {
2291  return getElement(elementName).getValueAsString();
2292 }
2293 
2294 inline Bytes Element::getElementAsBytes(const Name& elementName) const
2295 {
2296  return getElement(elementName).getValueAsBytes();
2297 }
2298 
2299 inline Name Element::getElementAsName(const char *elementName) const
2300 {
2301  return getElement(elementName).getValueAsName();
2302 }
2303 
2304 inline Name Element::getElementAsName(const Name& elementName) const
2305 {
2306  return getElement(elementName).getValueAsName();
2307 }
2308 
2309 inline const blpapi_Element_t *Element::handle() const { return d_handle_p; }
2310 
2311 inline std::ostream& Element::print(
2312  std::ostream& stream, int level, int spacesPerLevel) const
2313 {
2314  blpapi_Element_print(d_handle_p,
2316  &stream,
2317  level,
2318  spacesPerLevel);
2319  return stream;
2320 }
2321 
2322 inline std::ostream& operator<<(std::ostream& stream, const Element& element)
2323 {
2324  element.print(stream, 0, -1);
2325  return stream;
2326 }
2327 
2328 } // close namespace blpapi
2329 } // close namespace BloombergLP
2330 
2331 #endif // #ifdef __cplusplus
2332 #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:2214
Datetime getValueAsDatetime(size_t index=0) const
Definition: blpapi_element.h:2168
Float64 getValueAsFloat64(size_t index=0) const
Definition: blpapi_element.h:2161
#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:1974
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:2254
Float64 getElementAsFloat64(const char *name) const
Definition: blpapi_element.h:2264
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:2206
bool getValueAsBool(size_t index=0) const
Definition: blpapi_element.h:2126
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:1976
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:1944
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:2299
char getValueAsChar(size_t index=0) const
Definition: blpapi_element.h:2133
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:1939
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:2198
#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:2274
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:2154
Int32 getValueAsInt32(size_t index=0) const
Definition: blpapi_element.h:2140
Int64 getValueAsInt64(size_t index=0) const
Definition: blpapi_element.h:2147
bool isNull() const
Definition: blpapi_element.h:1949
Bytes getValueAsBytes(size_t index=0) const
Definition: blpapi_element.h:2183
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:2234
size_t numValues() const
Definition: blpapi_element.h:1964
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:2038
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:1934
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:1894
#define BLPAPI_CALL_ELEMENT_GETVALUEASHIGHPRECISIONDATETIME(a1, a2, a3)
Definition: blpapi_call.h:403
Int64 getElementAsInt64(const char *name) const
Definition: blpapi_element.h:2244
Element appendElement()
Definition: blpapi_element.h:1863
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition: blpapi_datetime.h:1954
size_t numElements() const
Definition: blpapi_element.h:1969
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:2224
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:1985
Bytes getElementAsBytes(const Name &name) const
Definition: blpapi_element.h:2294
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:2311
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:1959
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:2190
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:2284
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:1954
const char * getValueAsString(size_t index=0) const
Definition: blpapi_element.h:2175