BLPAPI C++ 3.26.5
Loading...
Searching...
No Matches
blpapi_request.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
35
36#ifndef INCLUDED_BLPAPI_REQUEST
37#define INCLUDED_BLPAPI_REQUEST
38
67
69#include <blpapi_defs.h>
70#include <blpapi_deprecate.h>
71#include <blpapi_element.h>
72#include <blpapi_exception.h>
73#include <blpapi_name.h>
74#include <blpapi_types.h>
75
76struct blpapi_Request;
77#ifdef __cplusplus
78extern "C" {
79#endif
80
82typedef struct blpapi_Request blpapi_Request_t;
83
87
88BLPAPI_EXPORT
89void blpapi_Request_destroy(blpapi_Request_t *request);
90
91BLPAPI_EXPORT
92blpapi_Element_t *blpapi_Request_elements(blpapi_Request_t *request);
93
94BLPAPI_EXPORT
95void blpapi_Request_setPreferredRoute(
96 blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId);
97
98BLPAPI_EXPORT
99int blpapi_Request_getRequestId(
100 const blpapi_Request_t *request, const char **requestId);
101
104
105#ifdef __cplusplus
106}
107
108#include <cassert>
109#include <cstddef>
110#include <iosfwd>
111#include <string>
112
119
120namespace BloombergLP {
121namespace blpapi {
122
123class RequestRef;
124
163class Request {
164
165 blpapi_Request_t *d_handle;
166 Element d_elements;
167
169 Request& operator=(const Request& rhs);
170
171 public:
172 explicit Request(blpapi_Request_t *handle);
173
174 Request(RequestRef src);
175 Request(Request& src);
180
181 ~Request();
185
186 operator RequestRef();
187
188 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, bool value);
192
193 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, char value);
197
198 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Int32 value);
202
203 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Int64 value);
207
208 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Float32 value);
212
213 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Float64 value);
217
218 BLPAPI_DEPRECATE_STRING_NAME void set(
219 const char *name, const Datetime& value);
223
224 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, const char *value);
228
229 void set(const Name& name, bool value);
233
234 void set(const Name& name, char value);
238
239 void set(const Name& name, Int32 value);
243
244 void set(const Name& name, Int64 value);
248
249 void set(const Name& name, Float32 value);
253
254 void set(const Name& name, Float64 value);
258
259 void set(const Name& name, const Datetime& value);
263
264 void set(const Name& name, const char *value);
268
269 void set(const Name& name, const std::string& value);
273
274 void set(const Name& name, const void *value, std::size_t length);
278
279 template <typename BYTES,
280 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
281 = true>
282 void set(const Name& name, const BYTES& value);
286
287 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, bool value);
291
292 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, char value);
296
297 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Int32 value);
301
302 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Int64 value);
306
307 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Float32 value);
311
312 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Float64 value);
316
317 BLPAPI_DEPRECATE_STRING_NAME void append(
318 const char *name, const Datetime& value);
322
323 BLPAPI_DEPRECATE_STRING_NAME void append(
324 const char *name, const char *value);
328
329 void append(const Name& name, bool value);
333
334 void append(const Name& name, char value);
338
339 void append(const Name& name, Int32 value);
343
344 void append(const Name& name, Int64 value);
348
349 void append(const Name& name, Float32 value);
353
354 void append(const Name& name, Float64 value);
358
359 void append(const Name& name, const Datetime& value);
363
364 void append(const Name& name, const char *value);
368
369 void append(const Name& name, const std::string& value);
373
378
379 BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name);
383
384 Element getElement(const Name& name);
388
389 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
390 const char *name) const;
394
395 const Element getElement(const Name& name) const;
399
400 const Element asElement() const;
404
405 void fromJson(const char *json);
414
415 void fromJson(const std::string& json);
426
427 const char *getRequestId() const;
438
439 blpapi_Request_t *handle() const;
440
441 std::ostream& print(
442 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
455};
456
459
460std::ostream& operator<<(std::ostream& stream, const Request& request);
472
474 Request *d_request_p;
475
476 public:
477 RequestRef(Request *request_p);
478 Request *ptr() const;
479 Request *operator->() const;
480};
481
482//=============================================================================
483// INLINE FUNCTION DEFINITIONS
484//=============================================================================
485
486// -------------
487// class Request
488// -------------
489
490inline Request::Request(blpapi_Request_t *newHandle)
491{
492 d_handle = newHandle;
493 if (newHandle) {
494 d_elements.rebind(blpapi_Request_elements(newHandle));
495 }
496}
497
499{
500 Request *src = ref.ptr();
501 assert(src);
502 d_handle = src->d_handle;
503 d_elements = src->d_elements;
504 src->d_handle = 0;
505 src->d_elements.rebind(0);
506}
507
509{
510 d_handle = src.d_handle;
511 d_elements = src.d_elements;
512 src.d_handle = 0;
513 src.d_elements.rebind(0);
514}
515
517{
518 if (d_handle) {
519 blpapi_Request_destroy(d_handle);
520 }
521}
522
523inline Request::operator RequestRef() { return RequestRef(this); }
524
525inline void Request::set(const char *element, bool value)
526{
527 d_elements.setElement(Name(element), value);
528}
529
530inline void Request::set(const char *element, char value)
531{
532 d_elements.setElement(Name(element), value);
533}
534
535inline void Request::set(const char *element, Int32 value)
536{
537 d_elements.setElement(Name(element), value);
538}
539
540inline void Request::set(const char *element, Int64 value)
541{
542 d_elements.setElement(Name(element), value);
543}
544
545inline void Request::set(const char *element, Float32 value)
546{
547 d_elements.setElement(Name(element), value);
548}
549
550inline void Request::set(const char *element, Float64 value)
551{
552 d_elements.setElement(Name(element), value);
553}
554
555inline void Request::set(const char *element, const Datetime& value)
556{
557 d_elements.setElement(Name(element), value);
558}
559
560inline void Request::set(const char *element, const char *value)
561{
562 d_elements.setElement(Name(element), value);
563}
564
565inline void Request::append(const char *element, bool value)
566{
567 Element namedElement = d_elements.getElement(Name(element));
568 namedElement.appendValue(value);
569}
570
571inline void Request::append(const char *element, char value)
572{
573 Element namedElement = d_elements.getElement(Name(element));
574 namedElement.appendValue(value);
575}
576
577inline void Request::append(const char *element, Int32 value)
578{
579 Element namedElement = d_elements.getElement(Name(element));
580 namedElement.appendValue(value);
581}
582
583inline void Request::append(const char *element, Int64 value)
584{
585 Element namedElement = d_elements.getElement(Name(element));
586 namedElement.appendValue(value);
587}
588
589inline void Request::append(const char *element, Float32 value)
590{
591 Element namedElement = d_elements.getElement(Name(element));
592 namedElement.appendValue(value);
593}
594
595inline void Request::append(const char *element, Float64 value)
596{
597 Element namedElement = d_elements.getElement(Name(element));
598 namedElement.appendValue(value);
599}
600
601inline void Request::append(const char *element, const Datetime& value)
602{
603 Element namedElement = d_elements.getElement(Name(element));
604 namedElement.appendValue(value);
605}
606
607inline void Request::append(const char *element, const char *value)
608{
609 Element namedElement = d_elements.getElement(Name(element));
610 namedElement.appendValue(value);
611}
612
613inline void Request::set(const Name& element, bool value)
614{
615 d_elements.setElement(element, value);
616}
617
618inline void Request::set(const Name& element, char value)
619{
620 d_elements.setElement(element, value);
621}
622
623inline void Request::set(const Name& element, Int32 value)
624{
625 d_elements.setElement(element, value);
626}
627
628inline void Request::set(const Name& element, Int64 value)
629{
630 d_elements.setElement(element, value);
631}
632
633inline void Request::set(const Name& element, Float32 value)
634{
635 d_elements.setElement(element, value);
636}
637
638inline void Request::set(const Name& element, Float64 value)
639{
640 d_elements.setElement(element, value);
641}
642
643inline void Request::set(const Name& element, const Datetime& value)
644{
645 d_elements.setElement(element, value);
646}
647
648inline void Request::set(const Name& element, const char *value)
649{
650 d_elements.setElement(element, value);
651}
652
653inline void Request::set(const Name& element, const std::string& value)
654{
655 d_elements.setElement(element, value);
656}
657
658inline void Request::set(
659 const Name& element, const void *value, std::size_t length)
660{
661 d_elements.setElement(element, value, length);
662}
663
664template <typename BYTES,
665 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
666inline void Request::set(const Name& element, const BYTES& value)
667{
668 d_elements.setElement(element, value);
669}
670
671inline void Request::append(const Name& element, bool value)
672{
673 Element namedElement = d_elements.getElement(element);
674 namedElement.appendValue(value);
675}
676
677inline void Request::append(const Name& element, char value)
678{
679 Element namedElement = d_elements.getElement(element);
680 namedElement.appendValue(value);
681}
682
683inline void Request::append(const Name& element, Int32 value)
684{
685 Element namedElement = d_elements.getElement(element);
686 namedElement.appendValue(value);
687}
688
689inline void Request::append(const Name& element, Int64 value)
690{
691 Element namedElement = d_elements.getElement(element);
692 namedElement.appendValue(value);
693}
694
695inline void Request::append(const Name& element, Float32 value)
696{
697 Element namedElement = d_elements.getElement(element);
698 namedElement.appendValue(value);
699}
700
701inline void Request::append(const Name& element, Float64 value)
702{
703 Element namedElement = d_elements.getElement(element);
704 namedElement.appendValue(value);
705}
706
707inline void Request::append(const Name& element, const Datetime& value)
708{
709 Element namedElement = d_elements.getElement(element);
710 namedElement.appendValue(value);
711}
712
713inline void Request::append(const Name& element, const char *value)
714{
715 Element namedElement = d_elements.getElement(element);
716 namedElement.appendValue(value);
717}
718
719inline void Request::append(const Name& element, const std::string& value)
720{
721 Element namedElement = d_elements.getElement(element);
722 namedElement.appendValue(value);
723}
724
725inline Element Request::getElement(const char *name)
726{
727 return d_elements.getElement(Name(name));
728}
729
731{
732 return d_elements.getElement(name);
733}
734
735inline Element Request::asElement() { return d_elements; }
736
737inline const Element Request::getElement(const char *name) const
738{
739 return d_elements.getElement(Name(name));
740}
741
742inline const Element Request::getElement(const Name& name) const
743{
744 return d_elements.getElement(name);
745}
746
747inline const Element Request::asElement() const { return d_elements; }
748
749inline void Request::fromJson(const char *json) { d_elements.fromJson(json); }
750
751inline void Request::fromJson(const std::string& json)
752{
753 fromJson(json.c_str());
754}
755
756inline const char *Request::getRequestId() const
757{
758 const char *requestId = 0;
759 BLPAPI_CALL(blpapi_Request_getRequestId)(d_handle, &requestId);
760 return requestId;
761}
762
763inline blpapi_Request_t *Request::handle() const { return d_handle; }
764
765inline std::ostream& Request::print(
766 std::ostream& stream, int level, int spacesPerLevel) const
767{
768 return d_elements.print(stream, level, spacesPerLevel);
769}
770
771inline std::ostream& operator<<(std::ostream& stream, const Request& request)
772{
773 return request.print(stream, 0, -1);
774}
775// ----------------
776// class RequestRef
777// ----------------
778
780 : d_request_p(request)
781{
782}
783
784inline Request *RequestRef::ptr() const { return this->d_request_p; }
785
786inline Request *RequestRef::operator->() const { return this->d_request_p; }
787
788} // close namespace blpapi
789} // close namespace BloombergLP
790
791#endif // #ifdef __cplusplus
792
793#endif // #ifndef INCLUDED_BLPAPI_REQUEST
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
Provide a representation of an item in a message.
Defines Exceptions that can be thrown by the blpapi library.
Provide a representation of strings for use as container keys.
Provide BLPAPI types.
Definition blpapi_datetime.h:273
Definition blpapi_element.h:1167
void rebind(blpapi_Element_t *element)
Definition blpapi_element.h:2334
int getElement(Element *result, const char *name) const
Definition blpapi_element.h:2642
void appendValue(bool value)
Definition blpapi_element.h:2550
void fromJson(const char *json)
Definition blpapi_element.h:3078
Definition blpapi_name.h:242
Definition blpapi_request.h:473
Request * ptr() const
Definition blpapi_request.h:784
RequestRef(Request *request_p)
Definition blpapi_request.h:779
Request * operator->() const
Definition blpapi_request.h:786
Definition blpapi_request.h:163
void append(const char *name, bool value)
Definition blpapi_request.h:565
blpapi_Request_t * handle() const
Definition blpapi_request.h:763
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_request.h:765
void set(const char *name, bool value)
Definition blpapi_request.h:525
Element getElement(const char *name)
Definition blpapi_request.h:725
void fromJson(const char *json)
Definition blpapi_request.h:749
~Request()
Definition blpapi_request.h:516
Request(blpapi_Request_t *handle)
Definition blpapi_request.h:490
const char * getRequestId() const
Definition blpapi_request.h:756
Element asElement()
Definition blpapi_request.h:735
Definition blpapi_abstractsession.h:212
blpapi_Float64_t Float64
Definition blpapi_types.h:485
blpapi_Float32_t Float32
Definition blpapi_types.h:484
blpapi_Int64_t Int64
Definition blpapi_types.h:482
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:680
blpapi_Int32_t Int32
Definition blpapi_types.h:480
Definition blpapi_abstractsession.h:211