BLPAPI C++ 3.26.6
Loading...
Searching...
No Matches
blpapi_element.h
Go to the documentation of this file.
1/* Copyright 2012. Bloomberg Finance L.P.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions: The above
9 * copyright notice and this permission notice shall be included in all copies
10 * or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18 * IN THE SOFTWARE.
19 */
20
37
38#ifndef INCLUDED_BLPAPI_ELEMENT
39#define INCLUDED_BLPAPI_ELEMENT
40
67
68#include <blpapi_call.h>
69#include <blpapi_datetime.h>
70#include <blpapi_defs.h>
71#include <blpapi_deprecate.h>
72#include <blpapi_name.h>
73#include <blpapi_schema.h>
74#include <blpapi_streamproxy.h>
75#include <blpapi_types.h>
76
77#include <stddef.h>
78
79#ifdef __cplusplus
80extern "C" {
81#endif
82
84
87
94BLPAPI_EXPORT blpapi_Name_t *blpapi_Element_name(
95 const blpapi_Element_t *element);
96
104BLPAPI_EXPORT const char *blpapi_Element_nameString(
105 const blpapi_Element_t *element);
106
113BLPAPI_EXPORT blpapi_SchemaElementDefinition_t *blpapi_Element_definition(
114 const blpapi_Element_t *element);
115
123BLPAPI_EXPORT int blpapi_Element_datatype(const blpapi_Element_t *element);
124
132BLPAPI_EXPORT int blpapi_Element_isComplexType(
133 const blpapi_Element_t *element);
134
142BLPAPI_EXPORT int blpapi_Element_isArray(const blpapi_Element_t *element);
143
151BLPAPI_EXPORT int blpapi_Element_isReadOnly(const blpapi_Element_t *element);
152
160BLPAPI_EXPORT size_t blpapi_Element_numValues(const blpapi_Element_t *element);
161
169BLPAPI_EXPORT size_t blpapi_Element_numElements(
170 const blpapi_Element_t *element);
171
180BLPAPI_EXPORT int blpapi_Element_isNullValue(
181 const blpapi_Element_t *element, size_t position);
182
190BLPAPI_EXPORT int blpapi_Element_isNull(const blpapi_Element_t *element);
191
205BLPAPI_EXPORT int blpapi_Element_print(const blpapi_Element_t *element,
206 blpapi_StreamWriter_t streamWriter,
207 void *stream,
208 int level,
209 int spacesPerLevel);
210
221BLPAPI_EXPORT int blpapi_Element_toJson(const blpapi_Element_t *element,
222 blpapi_StreamWriter_t streamWriter,
223 void *stream);
224
233BLPAPI_EXPORT int blpapi_Element_fromJson(
234 const blpapi_Element_t *element, char const *json);
235
246BLPAPI_EXPORT
247int blpapi_Element_getElementAt(const blpapi_Element_t *element,
248 blpapi_Element_t **result,
249 size_t position);
250
267BLPAPI_EXPORT
268int blpapi_Element_getElement(const blpapi_Element_t *element,
269 blpapi_Element_t **result,
270 const char *nameString,
271 const blpapi_Name_t *name);
272
288BLPAPI_EXPORT
289int blpapi_Element_hasElement(const blpapi_Element_t *element,
290 const char *nameString,
291 const blpapi_Name_t *name);
292
313BLPAPI_EXPORT
314int blpapi_Element_hasElementEx(const blpapi_Element_t *element,
315 const char *nameString,
316 const blpapi_Name_t *name,
317 int excludeNullElements,
318 int reserved);
319
330BLPAPI_EXPORT
331int blpapi_Element_getValueAsBool(
332 const blpapi_Element_t *element, blpapi_Bool_t *buffer, size_t index);
333
343BLPAPI_EXPORT
344int blpapi_Element_getValueAsChar(
345 const blpapi_Element_t *element, blpapi_Char_t *buffer, size_t index);
346
356BLPAPI_EXPORT
357int blpapi_Element_getValueAsInt32(
358 const blpapi_Element_t *element, blpapi_Int32_t *buffer, size_t index);
359
369BLPAPI_EXPORT
370int blpapi_Element_getValueAsInt64(
371 const blpapi_Element_t *element, blpapi_Int64_t *buffer, size_t index);
372
382BLPAPI_EXPORT
383int blpapi_Element_getValueAsFloat32(const blpapi_Element_t *element,
384 blpapi_Float32_t *buffer,
385 size_t index);
386
396BLPAPI_EXPORT
397int blpapi_Element_getValueAsFloat64(const blpapi_Element_t *element,
398 blpapi_Float64_t *buffer,
399 size_t index);
400
411BLPAPI_EXPORT
412int blpapi_Element_getValueAsString(
413 const blpapi_Element_t *element, const char **buffer, size_t index);
414
424BLPAPI_EXPORT
425int blpapi_Element_getValueAsDatetime(const blpapi_Element_t *element,
426 blpapi_Datetime_t *buffer,
427 size_t index);
428
438BLPAPI_EXPORT
439int blpapi_Element_getValueAsHighPrecisionDatetime(
440 const blpapi_Element_t *element,
441 blpapi_HighPrecisionDatetime_t *buffer,
442 size_t index);
443
454BLPAPI_EXPORT
455int blpapi_Element_getValueAsElement(const blpapi_Element_t *element,
456 blpapi_Element_t **buffer,
457 size_t index);
458
469BLPAPI_EXPORT
470int blpapi_Element_getValueAsName(
471 const blpapi_Element_t *element, blpapi_Name_t **buffer, size_t index);
472
485BLPAPI_EXPORT
486int blpapi_Element_getValueAsBytes(const blpapi_Element_t *element,
487 const char **buffer,
488 size_t *length,
489 size_t index);
490
500BLPAPI_EXPORT
501int blpapi_Element_getChoice(
502 const blpapi_Element_t *element, blpapi_Element_t **result);
503
514BLPAPI_EXPORT
515int blpapi_Element_setValueBool(
516 blpapi_Element_t *element, blpapi_Bool_t value, size_t index);
517
527BLPAPI_EXPORT
528int blpapi_Element_setValueChar(
529 blpapi_Element_t *element, blpapi_Char_t value, size_t index);
530
540BLPAPI_EXPORT
541int blpapi_Element_setValueInt32(
542 blpapi_Element_t *element, blpapi_Int32_t value, size_t index);
543
553BLPAPI_EXPORT
554int blpapi_Element_setValueInt64(
555 blpapi_Element_t *element, blpapi_Int64_t value, size_t index);
556
566BLPAPI_EXPORT
567int blpapi_Element_setValueFloat32(
568 blpapi_Element_t *element, blpapi_Float32_t value, size_t index);
569
579BLPAPI_EXPORT
580int blpapi_Element_setValueFloat64(
581 blpapi_Element_t *element, blpapi_Float64_t value, size_t index);
582
592BLPAPI_EXPORT
593int blpapi_Element_setValueString(
594 blpapi_Element_t *element, const char *value, size_t index);
595
605BLPAPI_EXPORT
606int blpapi_Element_setValueDatetime(blpapi_Element_t *element,
607 const blpapi_Datetime_t *value,
608 size_t index);
609
619BLPAPI_EXPORT
620int blpapi_Element_setValueHighPrecisionDatetime(blpapi_Element_t *element,
621 const blpapi_HighPrecisionDatetime_t *value,
622 size_t index);
623
634BLPAPI_EXPORT
635int blpapi_Element_setValueBytes(blpapi_Element_t *element,
636 const char *value,
637 size_t length,
638 size_t index);
639
649BLPAPI_EXPORT
650int blpapi_Element_setValueFromElement(
651 blpapi_Element_t *element, blpapi_Element_t *value, size_t index);
652
662BLPAPI_EXPORT
663int blpapi_Element_setValueFromName(
664 blpapi_Element_t *element, const blpapi_Name_t *value, size_t index);
665
681BLPAPI_EXPORT
682int blpapi_Element_setElementBool(blpapi_Element_t *element,
683 const char *nameString,
684 const blpapi_Name_t *name,
685 blpapi_Bool_t value);
686
702BLPAPI_EXPORT
703int blpapi_Element_setElementChar(blpapi_Element_t *element,
704 const char *nameString,
705 const blpapi_Name_t *name,
706 blpapi_Char_t value);
707
723BLPAPI_EXPORT
724int blpapi_Element_setElementInt32(blpapi_Element_t *element,
725 const char *nameString,
726 const blpapi_Name_t *name,
727 blpapi_Int32_t value);
728
744BLPAPI_EXPORT
745int blpapi_Element_setElementInt64(blpapi_Element_t *element,
746 const char *nameString,
747 const blpapi_Name_t *name,
748 blpapi_Int64_t value);
749
766BLPAPI_EXPORT
767int blpapi_Element_setElementFloat32(blpapi_Element_t *element,
768 const char *nameString,
769 const blpapi_Name_t *name,
770 blpapi_Float32_t value);
771
788BLPAPI_EXPORT
789int blpapi_Element_setElementFloat64(blpapi_Element_t *element,
790 const char *nameString,
791 const blpapi_Name_t *name,
792 blpapi_Float64_t value);
793
810BLPAPI_EXPORT
811int blpapi_Element_setElementString(blpapi_Element_t *element,
812 const char *nameString,
813 const blpapi_Name_t *name,
814 const char *value);
815
831BLPAPI_EXPORT
832int blpapi_Element_setElementDatetime(blpapi_Element_t *element,
833 const char *nameString,
834 const blpapi_Name_t *name,
835 const blpapi_Datetime_t *value);
836
853BLPAPI_EXPORT
854int blpapi_Element_setElementHighPrecisionDatetime(blpapi_Element_t *element,
855 const char *nameString,
856 const blpapi_Name_t *name,
857 const blpapi_HighPrecisionDatetime_t *value);
858
875BLPAPI_EXPORT
876int blpapi_Element_setElementBytes(blpapi_Element_t *element,
877 const char *nameString,
878 const blpapi_Name_t *name,
879 const char *value,
880 size_t length);
881
898BLPAPI_EXPORT
899int blpapi_Element_setElementFromField(blpapi_Element_t *element,
900 const char *nameString,
901 const blpapi_Name_t *name,
902 blpapi_Element_t *sourcebuffer);
903
916BLPAPI_EXPORT
917int blpapi_Element_setElementFromName(blpapi_Element_t *element,
918 const char *elementName,
919 const blpapi_Name_t *name,
920 const blpapi_Name_t *buffer);
921
931BLPAPI_EXPORT
932int blpapi_Element_appendElement(
933 blpapi_Element_t *element, blpapi_Element_t **appendedElement);
934
950BLPAPI_EXPORT
951int blpapi_Element_setChoice(blpapi_Element_t *element,
952 blpapi_Element_t **resultElement,
953 const char *nameCstr,
954 const blpapi_Name_t *name,
955 size_t index);
956
959
960#ifdef __cplusplus
961}
962
963#include <blpapi_exception.h>
964
965#include <cassert>
966#include <sstream>
967#include <string>
968#include <type_traits>
969
970namespace BloombergLP {
971namespace blpapi {
978
1098class Element {
1099
1100 blpapi_Element_t *d_handle_p;
1101
1102 public:
1103 Element();
1109
1110 explicit Element(blpapi_Element_t *element);
1111
1112 // MANIPULATORS
1113
1114 void rebind(blpapi_Element_t *element);
1115
1116 BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, bool value);
1128
1129 BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, char value);
1141
1142 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1143 const char *name, Int32 value);
1155
1156 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1157 const char *name, Int64 value);
1169
1170 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1171 const char *name, Float32 value);
1183
1184 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1185 const char *name, Float64 value);
1197
1198 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1199 const char *name, const Datetime& value);
1211
1212 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1213 const char *name, const char *value);
1225
1226 BLPAPI_DEPRECATE_STRING_NAME void setElement(
1227 const char *name, const Name& value);
1240
1241 void setElement(const Name& name, bool value);
1251
1252 void setElement(const Name& name, char value);
1262
1263 void setElement(const Name& name, Int32 value);
1273
1274 void setElement(const Name& name, Int64 value);
1284
1285 void setElement(const Name& name, Float32 value);
1295
1296 void setElement(const Name& name, Float64 value);
1306
1307 void setElement(const Name& name, const Datetime& value);
1317
1318 void setElement(const Name& name, const char *value);
1328
1329 void setElement(const Name& name, const std::string& value);
1340
1341 void setElement(const Name& name, const Name& value);
1351
1352 void setElement(const Name& name, const void *value, size_t length);
1362
1363 template <typename BYTES,
1364 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
1365 = true>
1366 void setElement(const Name& name, const BYTES& value);
1380
1381 void setValue(bool value, size_t index = 0);
1389
1390 void setValue(char value, size_t index = 0);
1398
1399 void setValue(Int32 value, size_t index = 0);
1407
1408 void setValue(Int64 value, size_t index = 0);
1416
1417 void setValue(Float32 value, size_t index = 0);
1425
1426 void setValue(Float64 value, size_t index = 0);
1434
1435 void setValue(const Datetime& value, size_t index = 0);
1443
1444 void setValue(const char *value, size_t index = 0);
1452
1453 void setValue(const std::string& value, size_t index = 0);
1462
1463 void setValue(const Name& valueName, size_t index = 0);
1472
1473 void setValue(const void *value, size_t length, size_t index);
1480
1481 template <typename BYTES,
1482 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
1483 = true>
1484 void setValue(const BYTES& value, size_t index = 0);
1496
1497 void appendValue(bool value);
1506
1507 void appendValue(char value);
1516
1517 void appendValue(Int32 value);
1526
1527 void appendValue(Int64 value);
1536
1537 void appendValue(Float32 value);
1546
1547 void appendValue(Float64 value);
1556
1557 void appendValue(const Datetime& value);
1566
1567 void appendValue(const char *value);
1576
1577 void appendValue(const std::string& value);
1588
1589 void appendValue(const Name& value);
1599
1606
1607 BLPAPI_DEPRECATE_STRING_NAME Element setChoice(const char *selectionName);
1616
1617 Element setChoice(const Name& selectionName);
1624
1626 blpapi_Element_t *handle();
1628
1629 // ACCESSORS
1630
1631 Name name() const;
1639
1640 int datatype() const;
1647
1648 bool isComplexType() const;
1653
1654 bool isArray() const;
1660
1661 bool isNull() const;
1665
1666 bool isReadOnly() const;
1670
1676
1677 size_t numValues() const;
1686
1687 size_t numElements() const;
1694
1695 bool isValid() const;
1701
1702 bool isNullValue(size_t position = 0) const;
1708
1709 BLPAPI_DEPRECATE_STRING_NAME bool hasElement(
1710 const char *name, bool excludeNullElements = false) const;
1718
1719 bool hasElement(const Name& name, bool excludeNullElements = false) const;
1727
1728 int getValueAs(bool *result, size_t index = 0) const;
1735
1736 int getValueAs(char *result, size_t index = 0) const;
1743
1744 int getValueAs(Int32 *result, size_t index = 0) const;
1751
1752 int getValueAs(Int64 *result, size_t index = 0) const;
1759
1760 int getValueAs(Float32 *result, size_t index = 0) const;
1767
1768 int getValueAs(Float64 *result, size_t index = 0) const;
1775
1776 int getValueAs(Datetime *result, size_t index = 0) const;
1786
1787 int getValueAs(std::string *result, size_t index = 0) const;
1794
1795 int getValueAs(Bytes *result, size_t index = 0) const;
1802
1803 int getValueAs(Element *result, size_t index = 0) const;
1810
1811 int getValueAs(Name *result, size_t index = 0) const;
1818
1819 bool getValueAsBool(size_t index = 0) const;
1825
1826 char getValueAsChar(size_t index = 0) const;
1832
1833 Int32 getValueAsInt32(size_t index = 0) const;
1839
1840 Int64 getValueAsInt64(size_t index = 0) const;
1846
1847 Float32 getValueAsFloat32(size_t index = 0) const;
1853
1854 Float64 getValueAsFloat64(size_t index = 0) const;
1860
1861 Datetime getValueAsDatetime(size_t index = 0) const;
1871
1872 const char *getValueAsString(size_t index = 0) const;
1880
1881 Bytes getValueAsBytes(size_t index = 0) const;
1888
1889 Element getValueAsElement(size_t index = 0) const;
1895
1896 Name getValueAsName(size_t index = 0) const;
1902
1903 BLPAPI_DEPRECATE_STRING_NAME int getElement(
1904 Element *result, const char *name) const;
1914
1915 int getElement(Element *result, const Name& name) const;
1923
1924 int getElement(Element *result, size_t position) const;
1932
1933 Element getElement(size_t position) const;
1940
1941 Element getElement(const Name& name) const;
1948
1949 BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name) const;
1959
1960 BLPAPI_DEPRECATE_STRING_NAME bool getElementAsBool(const char *name) const;
1970
1971 bool getElementAsBool(const Name& name) const;
1979
1980 BLPAPI_DEPRECATE_STRING_NAME char getElementAsChar(const char *name) const;
1990
1991 char getElementAsChar(const Name& name) const;
1999
2000 BLPAPI_DEPRECATE_STRING_NAME Int32 getElementAsInt32(
2001 const char *name) const;
2011
2012 Int32 getElementAsInt32(const Name& name) const;
2020
2021 BLPAPI_DEPRECATE_STRING_NAME Int64 getElementAsInt64(
2022 const char *name) const;
2032
2033 Int64 getElementAsInt64(const Name& name) const;
2041
2042 BLPAPI_DEPRECATE_STRING_NAME Float32 getElementAsFloat32(
2043 const char *name) const;
2053
2054 Float32 getElementAsFloat32(const Name& name) const;
2062
2063 BLPAPI_DEPRECATE_STRING_NAME Float64 getElementAsFloat64(
2064 const char *name) const;
2074
2075 Float64 getElementAsFloat64(const Name& name) const;
2083
2084 BLPAPI_DEPRECATE_STRING_NAME Datetime getElementAsDatetime(
2085 const char *name) const;
2099
2100 Datetime getElementAsDatetime(const Name& name) const;
2111
2112 BLPAPI_DEPRECATE_STRING_NAME const char *getElementAsString(
2113 const char *name) const;
2124
2125 const char *getElementAsString(const Name& name) const;
2134
2135 Bytes getElementAsBytes(const Name& name) const;
2144
2145 BLPAPI_DEPRECATE_STRING_NAME Name getElementAsName(const char *name) const;
2155
2156 Name getElementAsName(const Name& name) const;
2164
2165 Element getChoice() const;
2170
2172 const blpapi_Element_t *handle() const;
2174
2175 std::ostream& print(
2176 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
2189
2190 std::string toJson() const;
2196
2197 void fromJson(const char *json);
2206
2207 void fromJson(const std::string& json);
2217};
2218
2221
2222// FREE OPERATORS
2223std::ostream& operator<<(std::ostream& stream, const Element& element);
2236
2237// ============================================================================
2238// INLINE AND TEMPLATE FUNCTION IMPLEMENTATIONS
2239// ============================================================================
2240
2241// -------------
2242// class Element
2243// -------------
2244
2246 : d_handle_p(0)
2247{
2248}
2249
2250inline Element::Element(blpapi_Element_t *newHandle)
2251 : d_handle_p(newHandle)
2252{
2253}
2254
2255inline void Element::rebind(blpapi_Element_t *element)
2256{
2257 d_handle_p = element;
2258}
2259
2260inline void Element::setElement(const char *elementName, bool value)
2261{
2262 ExceptionUtil::throwOnError(blpapi_Element_setElementBool(
2263 d_handle_p, elementName, 0, value ? 1 : 0));
2264}
2265
2266inline void Element::setElement(const char *elementName, char value)
2267{
2269 blpapi_Element_setElementChar(d_handle_p, elementName, 0, value));
2270}
2271
2272inline void Element::setElement(const char *elementName, Int32 value)
2273{
2275 blpapi_Element_setElementInt32(d_handle_p, elementName, 0, value));
2276}
2277
2278inline void Element::setElement(const char *elementName, Int64 value)
2279{
2281 blpapi_Element_setElementInt64(d_handle_p, elementName, 0, value));
2282}
2283
2284inline void Element::setElement(const char *elementName, Float32 value)
2285{
2286 ExceptionUtil::throwOnError(blpapi_Element_setElementFloat32(
2287 d_handle_p, elementName, 0, value));
2288}
2289
2290inline void Element::setElement(const char *elementName, Float64 value)
2291{
2292 ExceptionUtil::throwOnError(blpapi_Element_setElementFloat64(
2293 d_handle_p, elementName, 0, value));
2294}
2295
2296inline void Element::setElement(const char *elementName, const Datetime& value)
2297{
2299 BLPAPI_CALL_ELEMENT_SETELEMENTHIGHPRECISIONDATETIME(d_handle_p,
2300 elementName,
2301 0,
2302 &value.rawHighPrecisionValue()));
2303}
2304
2305inline void Element::setElement(const char *elementName, const char *value)
2306{
2307 ExceptionUtil::throwOnError(blpapi_Element_setElementString(
2308 d_handle_p, elementName, 0, value));
2309}
2310
2311inline void Element::setElement(const char *elementName, const Name& value)
2312{
2313 ExceptionUtil::throwOnError(blpapi_Element_setElementFromName(
2314 d_handle_p, elementName, 0, value.impl()));
2315}
2316
2317inline void Element::setElement(const Name& elementName, bool value)
2318{
2319 ExceptionUtil::throwOnError(blpapi_Element_setElementBool(
2320 d_handle_p, 0, elementName.impl(), value ? 1 : 0));
2321}
2322
2323inline void Element::setElement(const Name& elementName, char value)
2324{
2325 ExceptionUtil::throwOnError(blpapi_Element_setElementChar(
2326 d_handle_p, 0, elementName.impl(), value));
2327}
2328
2329inline void Element::setElement(const Name& elementName, Int32 value)
2330{
2331 ExceptionUtil::throwOnError(blpapi_Element_setElementInt32(
2332 d_handle_p, 0, elementName.impl(), value));
2333}
2334
2335inline void Element::setElement(const Name& elementName, Int64 value)
2336{
2337 ExceptionUtil::throwOnError(blpapi_Element_setElementInt64(
2338 d_handle_p, 0, elementName.impl(), value));
2339}
2340
2341inline void Element::setElement(const Name& elementName, Float32 value)
2342{
2343 ExceptionUtil::throwOnError(blpapi_Element_setElementFloat32(
2344 d_handle_p, 0, elementName.impl(), value));
2345}
2346
2347inline void Element::setElement(const Name& elementName, Float64 value)
2348{
2349 ExceptionUtil::throwOnError(blpapi_Element_setElementFloat64(
2350 d_handle_p, 0, elementName.impl(), value));
2351}
2352
2353inline void Element::setElement(const Name& elementName, const Datetime& value)
2354{
2356 BLPAPI_CALL_ELEMENT_SETELEMENTHIGHPRECISIONDATETIME(d_handle_p,
2357 0,
2358 elementName.impl(),
2359 &value.rawHighPrecisionValue()));
2360}
2361
2362inline void Element::setElement(const Name& elementName, const char *value)
2363{
2364 ExceptionUtil::throwOnError(blpapi_Element_setElementString(
2365 d_handle_p, 0, elementName.impl(), value));
2366}
2367
2369 const Name& elementName, const std::string& value)
2370{
2371 setElement(elementName, value.c_str());
2372}
2373
2374inline void Element::setElement(const Name& elementName, const Name& value)
2375{
2376 ExceptionUtil::throwOnError(blpapi_Element_setElementFromName(
2377 d_handle_p, 0, elementName.impl(), value.impl()));
2378}
2379
2381 const Name& elementName, const void *value, size_t length)
2382{
2384 BLPAPI_CALL(blpapi_Element_setElementBytes)(d_handle_p,
2385 0,
2386 elementName.impl(),
2387 reinterpret_cast<const char *>(value),
2388 length));
2389}
2390
2391template <typename BYTES,
2392 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
2393inline void Element::setElement(const Name& elementName, const BYTES& value)
2394{
2395 setElement(elementName, value.data(), value.size());
2396}
2397
2398inline void Element::setValue(bool value, size_t index)
2399{
2401 blpapi_Element_setValueBool(d_handle_p, value, index));
2402}
2403
2404inline void Element::setValue(char value, size_t index)
2405{
2407 blpapi_Element_setValueChar(d_handle_p, value, index));
2408}
2409
2410inline void Element::setValue(Int32 value, size_t index)
2411{
2413 blpapi_Element_setValueInt32(d_handle_p, value, index));
2414}
2415
2416inline void Element::setValue(Int64 value, size_t index)
2417{
2419 blpapi_Element_setValueInt64(d_handle_p, value, index));
2420}
2421
2422inline void Element::setValue(Float32 value, size_t index)
2423{
2425 blpapi_Element_setValueFloat32(d_handle_p, value, index));
2426}
2427
2428inline void Element::setValue(Float64 value, size_t index)
2429{
2431 blpapi_Element_setValueFloat64(d_handle_p, value, index));
2432}
2433
2434inline void Element::setValue(const Datetime& value, size_t index)
2435{
2437 BLPAPI_CALL_ELEMENT_SETVALUEHIGHPRECISIONDATETIME(
2438 d_handle_p, &value.rawHighPrecisionValue(), index));
2439}
2440
2441inline void Element::setValue(const char *value, size_t index)
2442{
2444 blpapi_Element_setValueString(d_handle_p, value, index));
2445}
2446
2447inline void Element::setValue(const std::string& value, size_t index)
2448{
2449 setValue(value.c_str(), index);
2450}
2451
2452inline void Element::setValue(const Name& valueName, size_t index)
2453{
2454 ExceptionUtil::throwOnError(blpapi_Element_setValueFromName(
2455 d_handle_p, valueName.impl(), index));
2456}
2457
2458inline void Element::setValue(const void *value, size_t length, size_t index)
2459{
2460 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_Element_setValueBytes)(
2461 d_handle_p, reinterpret_cast<const char *>(value), length, index));
2462}
2463
2464template <typename BYTES,
2465 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
2466inline void Element::setValue(const BYTES& value, size_t index)
2467{
2468 setValue(value.data(), value.size(), index);
2469}
2470
2471inline void Element::appendValue(bool value)
2472{
2473 ExceptionUtil::throwOnError(blpapi_Element_setValueBool(
2474 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2475}
2476
2477inline void Element::appendValue(char value)
2478{
2479 ExceptionUtil::throwOnError(blpapi_Element_setValueChar(
2480 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2481}
2482
2483inline void Element::appendValue(Int32 value)
2484{
2485 ExceptionUtil::throwOnError(blpapi_Element_setValueInt32(
2486 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2487}
2488
2489inline void Element::appendValue(Int64 value)
2490{
2491 ExceptionUtil::throwOnError(blpapi_Element_setValueInt64(
2492 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2493}
2494
2496{
2497 ExceptionUtil::throwOnError(blpapi_Element_setValueFloat32(
2498 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2499}
2500
2502{
2503 ExceptionUtil::throwOnError(blpapi_Element_setValueFloat64(
2504 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2505}
2506
2507inline void Element::appendValue(const Datetime& value)
2508{
2510 BLPAPI_CALL_ELEMENT_SETVALUEHIGHPRECISIONDATETIME(d_handle_p,
2511 &value.rawHighPrecisionValue(),
2512 BLPAPI_ELEMENT_INDEX_END));
2513}
2514
2515inline void Element::appendValue(const char *value)
2516{
2517 ExceptionUtil::throwOnError(blpapi_Element_setValueString(
2518 d_handle_p, value, BLPAPI_ELEMENT_INDEX_END));
2519}
2520
2521inline void Element::appendValue(const std::string& value)
2522{
2523 appendValue(value.c_str());
2524}
2525
2526inline void Element::appendValue(const Name& valueName)
2527{
2528 ExceptionUtil::throwOnError(blpapi_Element_setValueFromName(
2529 d_handle_p, valueName.impl(), BLPAPI_ELEMENT_INDEX_END));
2530}
2531
2533{
2534 blpapi_Element_t *appendedElement = 0;
2536 blpapi_Element_appendElement(d_handle_p, &appendedElement));
2537 return Element(appendedElement);
2538}
2539
2540inline Element Element::setChoice(const char *selectionName)
2541{
2542 blpapi_Element_t *resultElement = 0;
2543 ExceptionUtil::throwOnError(blpapi_Element_setChoice(
2544 d_handle_p, &resultElement, selectionName, 0, 0));
2545 return Element(resultElement);
2546}
2547
2548inline Element Element::setChoice(const Name& selectionName)
2549{
2550 blpapi_Element_t *resultElement = 0;
2551 ExceptionUtil::throwOnError(blpapi_Element_setChoice(
2552 d_handle_p, &resultElement, 0, selectionName.impl(), 0));
2553 return Element(resultElement);
2554}
2555
2557inline blpapi_Element_t *Element::handle() { return d_handle_p; }
2559
2560inline Name Element::name() const
2561{
2562 return Name(blpapi_Element_name(d_handle_p));
2563}
2564
2565inline int Element::getElement(Element *element, const char *nameString) const
2566{
2567 assert(element);
2568
2569 blpapi_Element_t *fldt = 0;
2570 int rc = blpapi_Element_getElement(d_handle_p, &fldt, nameString, 0);
2571 if (!rc) {
2572 element->rebind(fldt);
2573 }
2574
2575 return rc;
2576}
2577
2578inline int Element::getElement(Element *element, const Name& elementName) const
2579{
2580 assert(element);
2581
2582 blpapi_Element_t *fldt = 0;
2583 int rc = blpapi_Element_getElement(
2584 d_handle_p, &fldt, 0, elementName.impl());
2585 if (!rc) {
2586 element->rebind(fldt);
2587 }
2588
2589 return rc;
2590}
2591
2592inline int Element::getElement(Element *element, size_t position) const
2593{
2594 assert(element);
2595
2596 blpapi_Element_t *fldt = 0;
2597 int rc = blpapi_Element_getElementAt(d_handle_p, &fldt, position);
2598 if (!rc) {
2599 element->rebind(fldt);
2600 }
2601
2602 return rc;
2603}
2604
2605inline int Element::datatype() const
2606{
2607 return blpapi_Element_datatype(d_handle_p);
2608}
2609
2610inline bool Element::isComplexType() const
2611{
2612 return blpapi_Element_isComplexType(d_handle_p) ? true : false;
2613}
2614
2615inline bool Element::isArray() const
2616{
2617 return blpapi_Element_isArray(d_handle_p) ? true : false;
2618}
2619
2620inline bool Element::isNull() const
2621{
2622 return blpapi_Element_isNull(d_handle_p) ? true : false;
2623}
2624
2625inline bool Element::isReadOnly() const
2626{
2627 return blpapi_Element_isReadOnly(d_handle_p) ? true : false;
2628}
2629
2631{
2632 return SchemaElementDefinition(blpapi_Element_definition(d_handle_p));
2633}
2634
2635inline size_t Element::numValues() const
2636{
2637 return blpapi_Element_numValues(d_handle_p);
2638}
2639
2640inline size_t Element::numElements() const
2641{
2642 return blpapi_Element_numElements(d_handle_p);
2643}
2644
2645inline bool Element::isValid() const { return d_handle_p ? true : false; }
2646
2647inline bool Element::isNullValue(size_t position) const
2648{
2649 int rc = blpapi_Element_isNullValue(d_handle_p, position);
2650 if (rc != 0 && rc != 1) {
2652 }
2653 return rc ? true : false;
2654}
2655
2657 const char *nameString, bool excludeNullElements) const
2658{
2659 if (excludeNullElements) {
2660 return (blpapi_Element_hasElementEx(
2661 d_handle_p, nameString, 0, excludeNullElements, 0)
2662 ? true
2663 : false);
2664 }
2665 return blpapi_Element_hasElement(d_handle_p, nameString, 0) ? true : false;
2666}
2667
2669 const Name& elementName, bool excludeNullElements) const
2670{
2671 if (excludeNullElements) {
2672 return (blpapi_Element_hasElementEx(d_handle_p,
2673 0,
2674 elementName.impl(),
2675 excludeNullElements,
2676 0)
2677 ? true
2678 : false);
2679 }
2680 return blpapi_Element_hasElement(d_handle_p, 0, elementName.impl())
2681 ? true
2682 : false;
2683}
2684
2685inline Element Element::getElement(const Name& elementName) const
2686{
2687 blpapi_Element_t *fldt = 0;
2688 ExceptionUtil::throwOnError(blpapi_Element_getElement(
2689 d_handle_p, &fldt, 0, elementName.impl()));
2690 return Element(fldt);
2691}
2692
2693inline Element Element::getElement(const char *elementName) const
2694{
2695 blpapi_Element_t *fldt = 0;
2697 blpapi_Element_getElement(d_handle_p, &fldt, elementName, 0));
2698 return Element(fldt);
2699}
2700
2701inline Element Element::getElement(size_t position) const
2702{
2703 blpapi_Element_t *element = 0;
2705 blpapi_Element_getElementAt(d_handle_p, &element, position));
2706 return Element(element);
2707}
2708
2709inline int Element::getValueAs(bool *buffer, size_t index) const
2710{
2711 assert(buffer);
2712
2713 blpapi_Bool_t tmp = false;
2714
2715 int res = blpapi_Element_getValueAsBool(d_handle_p, &tmp, index);
2716 *buffer = tmp ? true : false;
2717 return res;
2718}
2719
2720inline int Element::getValueAs(char *buffer, size_t index) const
2721{
2722 return blpapi_Element_getValueAsChar(d_handle_p, buffer, index);
2723}
2724
2725inline int Element::getValueAs(Int32 *buffer, size_t index) const
2726{
2727 return blpapi_Element_getValueAsInt32(d_handle_p, buffer, index);
2728}
2729
2730inline int Element::getValueAs(Int64 *buffer, size_t index) const
2731{
2732 return blpapi_Element_getValueAsInt64(d_handle_p, buffer, index);
2733}
2734
2735inline int Element::getValueAs(Float32 *buffer, size_t index) const
2736{
2737 return blpapi_Element_getValueAsFloat32(d_handle_p, buffer, index);
2738}
2739
2740inline int Element::getValueAs(Float64 *buffer, size_t index) const
2741{
2742 return blpapi_Element_getValueAsFloat64(d_handle_p, buffer, index);
2743}
2744
2745inline int Element::getValueAs(Datetime *buffer, size_t index) const
2746{
2747 BLPAPI_CALL_ELEMENT_GETVALUEASHIGHPRECISIONDATETIME(
2748 d_handle_p, buffer, index);
2749}
2750
2751inline int Element::getValueAs(std::string *result, size_t index) const
2752{
2753 assert(result);
2754
2755 const char *buffer = 0;
2756 int rc = blpapi_Element_getValueAsString(d_handle_p, &buffer, index);
2757 if (!rc) {
2758 *result = buffer;
2759 }
2760 return rc;
2761}
2762
2763inline int Element::getValueAs(Bytes *result, size_t index) const
2764{
2765 assert(result);
2766
2767 const char *buffer = 0;
2768 size_t length = 0;
2769 const int rc = BLPAPI_CALL(blpapi_Element_getValueAsBytes)(
2770 d_handle_p, &buffer, &length, index);
2771 if (!rc) {
2772 result->assign(buffer, length);
2773 }
2774 return rc;
2775}
2776
2777inline int Element::getValueAs(Element *buffer, size_t index) const
2778{
2779 assert(buffer);
2780
2781 return blpapi_Element_getValueAsElement(
2782 d_handle_p, &buffer->d_handle_p, index);
2783}
2784
2785inline int Element::getValueAs(Name *buffer, size_t index) const
2786{
2787 assert(buffer);
2788
2789 blpapi_Name_t *tmpName = 0;
2790 int res = blpapi_Element_getValueAsName(d_handle_p, &tmpName, index);
2791 if (!res) {
2792 *buffer = Name(tmpName);
2793 }
2794 return res;
2795}
2796
2797inline bool Element::getValueAsBool(size_t index) const
2798{
2799 bool value = false;
2801 return value;
2802}
2803
2804inline char Element::getValueAsChar(size_t index) const
2805{
2806 char value = 0;
2808 return value;
2809}
2810
2811inline Int32 Element::getValueAsInt32(size_t index) const
2812{
2813 Int32 value = 0;
2815 return value;
2816}
2817
2818inline Int64 Element::getValueAsInt64(size_t index) const
2819{
2820 Int64 value = 0;
2822 return value;
2823}
2824
2825inline Float32 Element::getValueAsFloat32(size_t index) const
2826{
2827 Float32 value = 0.0;
2829 return value;
2830}
2831
2832inline Float64 Element::getValueAsFloat64(size_t index) const
2833{
2834 Float64 value = 0.0;
2836 return value;
2837}
2838
2839inline Datetime Element::getValueAsDatetime(size_t index) const
2840{
2841 Datetime value;
2843 return value;
2844}
2845
2846inline const char *Element::getValueAsString(size_t index) const
2847{
2848 const char *tmpStringBuffer = 0;
2849 ExceptionUtil::throwOnError(blpapi_Element_getValueAsString(
2850 d_handle_p, &tmpStringBuffer, index));
2851 return tmpStringBuffer;
2852}
2853
2854inline Bytes Element::getValueAsBytes(size_t index) const
2855{
2856 Bytes value;
2858 return value;
2859}
2860
2861inline Element Element::getValueAsElement(size_t index) const
2862{
2863 blpapi_Element_t *element = 0;
2865 blpapi_Element_getValueAsElement(d_handle_p, &element, index));
2866 return Element(element);
2867}
2868
2869inline Name Element::getValueAsName(size_t index) const
2870{
2871 blpapi_Name_t *nameValue = 0;
2873 blpapi_Element_getValueAsName(d_handle_p, &nameValue, index));
2874 return Name(nameValue);
2875}
2876
2878{
2879 blpapi_Element_t *element = 0;
2881 blpapi_Element_getChoice(d_handle_p, &element));
2882 return Element(element);
2883}
2884
2885inline bool Element::getElementAsBool(const char *elementName) const
2886{
2887 return getElement(Name(elementName)).getValueAsBool();
2888}
2889
2890inline bool Element::getElementAsBool(const Name& elementName) const
2891{
2892 return getElement(elementName).getValueAsBool();
2893}
2894
2895inline char Element::getElementAsChar(const char *elementName) const
2896{
2897 return getElement(Name(elementName)).getValueAsChar();
2898}
2899
2900inline char Element::getElementAsChar(const Name& elementName) const
2901{
2902 return getElement(elementName).getValueAsChar();
2903}
2904
2905inline Int32 Element::getElementAsInt32(const char *elementName) const
2906{
2907 return getElement(Name(elementName)).getValueAsInt32();
2908}
2909
2910inline Int32 Element::getElementAsInt32(const Name& elementName) const
2911{
2912 return getElement(elementName).getValueAsInt32();
2913}
2914
2915inline Int64 Element::getElementAsInt64(const char *elementName) const
2916{
2917 return getElement(Name(elementName)).getValueAsInt64();
2918}
2919
2920inline Int64 Element::getElementAsInt64(const Name& elementName) const
2921{
2922 return getElement(elementName).getValueAsInt64();
2923}
2924
2925inline Float32 Element::getElementAsFloat32(const char *elementName) const
2926{
2927 return getElement(Name(elementName)).getValueAsFloat32();
2928}
2929
2930inline Float32 Element::getElementAsFloat32(const Name& elementName) const
2931{
2932 return getElement(elementName).getValueAsFloat32();
2933}
2934
2935inline Float64 Element::getElementAsFloat64(const char *elementName) const
2936{
2937 return getElement(Name(elementName)).getValueAsFloat64();
2938}
2939
2940inline Float64 Element::getElementAsFloat64(const Name& elementName) const
2941{
2942 return getElement(elementName).getValueAsFloat64();
2943}
2944
2945inline Datetime Element::getElementAsDatetime(const char *elementName) const
2946{
2947 return getElement(Name(elementName)).getValueAsDatetime();
2948}
2949
2950inline Datetime Element::getElementAsDatetime(const Name& elementName) const
2951{
2952 return getElement(elementName).getValueAsDatetime();
2953}
2954
2955inline const char *Element::getElementAsString(const char *elementName) const
2956{
2957 return getElement(Name(elementName)).getValueAsString();
2958}
2959
2960inline const char *Element::getElementAsString(const Name& elementName) const
2961{
2962 return getElement(elementName).getValueAsString();
2963}
2964
2965inline Bytes Element::getElementAsBytes(const Name& elementName) const
2966{
2967 return getElement(elementName).getValueAsBytes();
2968}
2969
2970inline Name Element::getElementAsName(const char *elementName) const
2971{
2972 return getElement(Name(elementName)).getValueAsName();
2973}
2974
2975inline Name Element::getElementAsName(const Name& elementName) const
2976{
2977 return getElement(elementName).getValueAsName();
2978}
2979
2981inline const blpapi_Element_t *Element::handle() const { return d_handle_p; }
2983
2984inline std::ostream& Element::print(
2985 std::ostream& stream, int level, int spacesPerLevel) const
2986{
2987 blpapi_Element_print(d_handle_p,
2989 &stream,
2990 level,
2991 spacesPerLevel);
2992 return stream;
2993}
2994
2995inline std::string Element::toJson() const
2996{
2997 std::ostringstream stream;
2998 ExceptionUtil::throwOnError(blpapi_Element_toJson(
2999 d_handle_p, StreamProxyOstream::writeToStream, &stream));
3000 return stream.str();
3001}
3002
3003inline void Element::fromJson(const char *json)
3004{
3005 ExceptionUtil::throwOnError(blpapi_Element_fromJson(d_handle_p, json));
3006}
3007
3008inline void Element::fromJson(const std::string& json)
3009{
3010 fromJson(json.c_str());
3011}
3012
3013inline std::ostream& operator<<(std::ostream& stream, const Element& element)
3014{
3015 element.print(stream, 0, -1);
3016 return stream;
3017}
3018
3019} // close namespace blpapi
3020} // close namespace BloombergLP
3021
3022#endif // #ifdef __cplusplus
3023#endif // #ifndef INCLUDED_BLPAPI_ELEMENT
Provide functions for dispatchtbl.
Represents a date and/or time.
Common definitions used by the library.
Defines Exceptions that can be thrown by the blpapi library.
Provide a representation of strings for use as container keys.
Provide a representation of a schema describing structured messages.
A signature for callback on print and default C++ implementation.
Provide BLPAPI types.
Definition blpapi_types.h:395
void assign(pointer ptr, size_type length) noexcept
Definition blpapi_types.h:581
Definition blpapi_datetime.h:312
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition blpapi_datetime.h:2020
Definition blpapi_element.h:1098
Datetime getElementAsDatetime(const char *name) const
Definition blpapi_element.h:2945
Name name() const
Definition blpapi_element.h:2560
void rebind(blpapi_Element_t *element)
Definition blpapi_element.h:2255
int getValueAs(bool *result, size_t index=0) const
Definition blpapi_element.h:2709
Element setChoice(const char *selectionName)
Definition blpapi_element.h:2540
Bytes getElementAsBytes(const Name &name) const
Definition blpapi_element.h:2965
bool isNullValue(size_t position=0) const
Definition blpapi_element.h:2647
int getElement(Element *result, const char *name) const
Definition blpapi_element.h:2565
Float64 getValueAsFloat64(size_t index=0) const
Definition blpapi_element.h:2832
Element getValueAsElement(size_t index=0) const
Definition blpapi_element.h:2861
Name getValueAsName(size_t index=0) const
Definition blpapi_element.h:2869
int datatype() const
Definition blpapi_element.h:2605
Name getElementAsName(const char *name) const
Definition blpapi_element.h:2970
Int64 getValueAsInt64(size_t index=0) const
Definition blpapi_element.h:2818
Bytes getValueAsBytes(size_t index=0) const
Definition blpapi_element.h:2854
Float64 getElementAsFloat64(const char *name) const
Definition blpapi_element.h:2935
size_t numValues() const
Definition blpapi_element.h:2635
bool isReadOnly() const
Definition blpapi_element.h:2625
bool hasElement(const char *name, bool excludeNullElements=false) const
Definition blpapi_element.h:2656
void appendValue(bool value)
Definition blpapi_element.h:2471
bool isValid() const
Definition blpapi_element.h:2645
bool getElementAsBool(const char *name) const
Definition blpapi_element.h:2885
bool getValueAsBool(size_t index=0) const
Definition blpapi_element.h:2797
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_element.h:2984
void setValue(bool value, size_t index=0)
Definition blpapi_element.h:2398
char getElementAsChar(const char *name) const
Definition blpapi_element.h:2895
Element appendElement()
Definition blpapi_element.h:2532
const char * getValueAsString(size_t index=0) const
Definition blpapi_element.h:2846
bool isComplexType() const
Definition blpapi_element.h:2610
char getValueAsChar(size_t index=0) const
Definition blpapi_element.h:2804
void setElement(const char *name, bool value)
Definition blpapi_element.h:2260
std::string toJson() const
Definition blpapi_element.h:2995
void fromJson(const char *json)
Definition blpapi_element.h:3003
Element()
Definition blpapi_element.h:2245
Datetime getValueAsDatetime(size_t index=0) const
Definition blpapi_element.h:2839
bool isNull() const
Definition blpapi_element.h:2620
SchemaElementDefinition elementDefinition() const
Definition blpapi_element.h:2630
Int64 getElementAsInt64(const char *name) const
Definition blpapi_element.h:2915
Int32 getElementAsInt32(const char *name) const
Definition blpapi_element.h:2905
Element getChoice() const
Definition blpapi_element.h:2877
Float32 getValueAsFloat32(size_t index=0) const
Definition blpapi_element.h:2825
bool isArray() const
Definition blpapi_element.h:2615
Int32 getValueAsInt32(size_t index=0) const
Definition blpapi_element.h:2811
const char * getElementAsString(const char *name) const
Definition blpapi_element.h:2955
Float32 getElementAsFloat32(const char *name) const
Definition blpapi_element.h:2925
size_t numElements() const
Definition blpapi_element.h:2640
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Definition blpapi_name.h:228
Definition blpapi_schema.h:597
Definition blpapi_abstractsession.h:452
blpapi_Float64_t Float64
64-bit IEEE 754 float type alias.
Definition blpapi_types.h:559
blpapi_Float32_t Float32
32-bit IEEE 754 float type alias.
Definition blpapi_types.h:558
blpapi_Int64_t Int64
64-bit signed integer type alias.
Definition blpapi_types.h:556
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:761
blpapi_Int32_t Int32
32-bit signed integer type alias.
Definition blpapi_types.h:554
Definition blpapi_abstractsession.h:451
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:108