BLPAPI C++ 3.25.8
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
28#ifndef INCLUDED_BLPAPI_REQUEST
29#define INCLUDED_BLPAPI_REQUEST
30
61#include <blpapi_defs.h>
62#include <blpapi_deprecate.h>
63#include <blpapi_element.h>
64#include <blpapi_exception.h>
65#include <blpapi_name.h>
66#include <blpapi_types.h>
67
68struct blpapi_Request;
69typedef struct blpapi_Request blpapi_Request_t;
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
77
80
83 blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId);
84
87 const blpapi_Request_t *request, const char **requestId);
88
89#ifdef __cplusplus
90}
91
92#include <cassert>
93#include <cstddef>
94#include <iosfwd>
95#include <string>
96
104namespace BloombergLP {
105namespace blpapi {
106
107class RequestRef;
108
147class Request {
148
149 blpapi_Request_t *d_handle;
150 Element d_elements;
151
153 Request& operator=(const Request& rhs);
154
155 public:
157
158 Request(RequestRef src);
159 Request(Request& src);
165 ~Request();
170 operator RequestRef();
171
172 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, bool value);
177 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, char value);
182 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Int32 value);
187 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Int64 value);
192 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Float32 value);
197 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Float64 value);
202 BLPAPI_DEPRECATE_STRING_NAME void set(
203 const char *name, const Datetime& value);
208 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, const char *value);
213 void set(const Name& name, bool value);
218 void set(const Name& name, char value);
223 void set(const Name& name, Int32 value);
228 void set(const Name& name, Int64 value);
233 void set(const Name& name, Float32 value);
238 void set(const Name& name, Float64 value);
243 void set(const Name& name, const Datetime& value);
248 void set(const Name& name, const char *value);
253 void set(const Name& name, const std::string& value);
258 void set(const Name& name, const void *value, std::size_t length);
263 template <typename BYTES,
264 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
265 = true>
266 void set(const Name& name, const BYTES& value);
271 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, bool value);
276 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, char value);
281 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Int32 value);
286 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Int64 value);
291 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Float32 value);
296 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Float64 value);
301 BLPAPI_DEPRECATE_STRING_NAME void append(
302 const char *name, const Datetime& value);
307 BLPAPI_DEPRECATE_STRING_NAME void append(
308 const char *name, const char *value);
313 void append(const Name& name, bool value);
318 void append(const Name& name, char value);
323 void append(const Name& name, Int32 value);
328 void append(const Name& name, Int64 value);
333 void append(const Name& name, Float32 value);
338 void append(const Name& name, Float64 value);
343 void append(const Name& name, const Datetime& value);
348 void append(const Name& name, const char *value);
353 void append(const Name& name, const std::string& value);
363 BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name);
368 Element getElement(const Name& name);
373 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
374 const char *name) const;
379 const Element getElement(const Name& name) const;
384 const Element asElement() const;
389 const char *getRequestId() const;
401 blpapi_Request_t *handle() const;
402
403 std::ostream& print(
404 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
417};
418
422std::ostream& operator<<(std::ostream& stream, const Request& request);
436 Request *d_request_p;
437
438 public:
439 RequestRef(Request *request_p);
440 Request *ptr() const;
441 Request *operator->() const;
442};
443
444//=============================================================================
445// INLINE FUNCTION DEFINITIONS
446//=============================================================================
447
448// -------------
449// class Request
450// -------------
451
453{
454 d_handle = newHandle;
455 if (newHandle) {
456 d_elements.rebind(blpapi_Request_elements(newHandle));
457 }
458}
459
461{
462 Request *src = ref.ptr();
463 assert(src);
464 d_handle = src->d_handle;
465 d_elements = src->d_elements;
466 src->d_handle = 0;
467 src->d_elements.rebind(0);
468}
469
471{
472 d_handle = src.d_handle;
473 d_elements = src.d_elements;
474 src.d_handle = 0;
475 src.d_elements.rebind(0);
476}
477
479{
480 if (d_handle) {
481 blpapi_Request_destroy(d_handle);
482 }
483}
484
485inline Request::operator RequestRef() { return RequestRef(this); }
486
487inline void Request::set(const char *element, bool value)
488{
489 d_elements.setElement(Name(element), value);
490}
491
492inline void Request::set(const char *element, char value)
493{
494 d_elements.setElement(Name(element), value);
495}
496
497inline void Request::set(const char *element, Int32 value)
498{
499 d_elements.setElement(Name(element), value);
500}
501
502inline void Request::set(const char *element, Int64 value)
503{
504 d_elements.setElement(Name(element), value);
505}
506
507inline void Request::set(const char *element, Float32 value)
508{
509 d_elements.setElement(Name(element), value);
510}
511
512inline void Request::set(const char *element, Float64 value)
513{
514 d_elements.setElement(Name(element), value);
515}
516
517inline void Request::set(const char *element, const Datetime& value)
518{
519 d_elements.setElement(Name(element), value);
520}
521
522inline void Request::set(const char *element, const char *value)
523{
524 d_elements.setElement(Name(element), value);
525}
526
527inline void Request::append(const char *element, bool value)
528{
529 Element namedElement = d_elements.getElement(Name(element));
530 namedElement.appendValue(value);
531}
532
533inline void Request::append(const char *element, char value)
534{
535 Element namedElement = d_elements.getElement(Name(element));
536 namedElement.appendValue(value);
537}
538
539inline void Request::append(const char *element, Int32 value)
540{
541 Element namedElement = d_elements.getElement(Name(element));
542 namedElement.appendValue(value);
543}
544
545inline void Request::append(const char *element, Int64 value)
546{
547 Element namedElement = d_elements.getElement(Name(element));
548 namedElement.appendValue(value);
549}
550
551inline void Request::append(const char *element, Float32 value)
552{
553 Element namedElement = d_elements.getElement(Name(element));
554 namedElement.appendValue(value);
555}
556
557inline void Request::append(const char *element, Float64 value)
558{
559 Element namedElement = d_elements.getElement(Name(element));
560 namedElement.appendValue(value);
561}
562
563inline void Request::append(const char *element, const Datetime& value)
564{
565 Element namedElement = d_elements.getElement(Name(element));
566 namedElement.appendValue(value);
567}
568
569inline void Request::append(const char *element, const char *value)
570{
571 Element namedElement = d_elements.getElement(Name(element));
572 namedElement.appendValue(value);
573}
574
575inline void Request::set(const Name& element, bool value)
576{
577 d_elements.setElement(element, value);
578}
579
580inline void Request::set(const Name& element, char value)
581{
582 d_elements.setElement(element, value);
583}
584
585inline void Request::set(const Name& element, Int32 value)
586{
587 d_elements.setElement(element, value);
588}
589
590inline void Request::set(const Name& element, Int64 value)
591{
592 d_elements.setElement(element, value);
593}
594
595inline void Request::set(const Name& element, Float32 value)
596{
597 d_elements.setElement(element, value);
598}
599
600inline void Request::set(const Name& element, Float64 value)
601{
602 d_elements.setElement(element, value);
603}
604
605inline void Request::set(const Name& element, const Datetime& value)
606{
607 d_elements.setElement(element, value);
608}
609
610inline void Request::set(const Name& element, const char *value)
611{
612 d_elements.setElement(element, value);
613}
614
615inline void Request::set(const Name& element, const std::string& value)
616{
617 d_elements.setElement(element, value);
618}
619
620inline void Request::set(
621 const Name& element, const void *value, std::size_t length)
622{
623 d_elements.setElement(element, value, length);
624}
625
626template <typename BYTES,
627 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
628inline void Request::set(const Name& element, const BYTES& value)
629{
630 d_elements.setElement(element, value);
631}
632
633inline void Request::append(const Name& element, bool value)
634{
635 Element namedElement = d_elements.getElement(element);
636 namedElement.appendValue(value);
637}
638
639inline void Request::append(const Name& element, char value)
640{
641 Element namedElement = d_elements.getElement(element);
642 namedElement.appendValue(value);
643}
644
645inline void Request::append(const Name& element, Int32 value)
646{
647 Element namedElement = d_elements.getElement(element);
648 namedElement.appendValue(value);
649}
650
651inline void Request::append(const Name& element, Int64 value)
652{
653 Element namedElement = d_elements.getElement(element);
654 namedElement.appendValue(value);
655}
656
657inline void Request::append(const Name& element, Float32 value)
658{
659 Element namedElement = d_elements.getElement(element);
660 namedElement.appendValue(value);
661}
662
663inline void Request::append(const Name& element, Float64 value)
664{
665 Element namedElement = d_elements.getElement(element);
666 namedElement.appendValue(value);
667}
668
669inline void Request::append(const Name& element, const Datetime& value)
670{
671 Element namedElement = d_elements.getElement(element);
672 namedElement.appendValue(value);
673}
674
675inline void Request::append(const Name& element, const char *value)
676{
677 Element namedElement = d_elements.getElement(element);
678 namedElement.appendValue(value);
679}
680
681inline void Request::append(const Name& element, const std::string& value)
682{
683 Element namedElement = d_elements.getElement(element);
684 namedElement.appendValue(value);
685}
686
687inline Element Request::getElement(const char *name)
688{
689 return d_elements.getElement(Name(name));
690}
691
693{
694 return d_elements.getElement(name);
695}
696
697inline Element Request::asElement() { return d_elements; }
698
699inline const Element Request::getElement(const char *name) const
700{
701 return d_elements.getElement(Name(name));
702}
703
704inline const Element Request::getElement(const Name& name) const
705{
706 return d_elements.getElement(name);
707}
708
709inline const Element Request::asElement() const { return d_elements; }
710
711inline const char *Request::getRequestId() const
712{
713 const char *requestId = 0;
714 BLPAPI_CALL(blpapi_Request_getRequestId)(d_handle, &requestId);
715 return requestId;
716}
717
718inline blpapi_Request_t *Request::handle() const { return d_handle; }
719
720inline std::ostream& Request::print(
721 std::ostream& stream, int level, int spacesPerLevel) const
722{
723 return d_elements.print(stream, level, spacesPerLevel);
724}
725
726inline std::ostream& operator<<(std::ostream& stream, const Request& request)
727{
728 return request.print(stream, 0, -1);
729}
730// ----------------
731// class RequestRef
732// ----------------
733
735 : d_request_p(request)
736{
737}
738
739inline Request *RequestRef::ptr() const { return this->d_request_p; }
740
741inline Request *RequestRef::operator->() const { return this->d_request_p; }
742
743} // close namespace blpapi
744} // close namespace BloombergLP
745
746#endif // #ifdef __cplusplus
747
748#endif // #ifndef INCLUDED_BLPAPI_REQUEST
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:353
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
#define BLPAPI_EXPORT
Definition blpapi_defs.h:171
struct blpapi_Request blpapi_Request_t
Definition blpapi_dispatchtbl.h:81
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.
BLPAPI_EXPORT void blpapi_Request_setPreferredRoute(blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId)
BLPAPI_EXPORT int blpapi_Request_getRequestId(const blpapi_Request_t *request, const char **requestId)
BLPAPI_EXPORT void blpapi_Request_destroy(blpapi_Request_t *request)
BLPAPI_EXPORT blpapi_Element_t * blpapi_Request_elements(blpapi_Request_t *request)
Provide BLPAPI types.
Definition blpapi_datetime.h:245
Definition blpapi_element.h:465
void rebind(blpapi_Element_t *element)
Definition blpapi_element.h:1602
BLPAPI_DEPRECATE_STRING_NAME int getElement(Element *result, const char *name) const
Definition blpapi_element.h:1910
void appendValue(bool value)
Definition blpapi_element.h:1818
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_element.h:2327
BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, bool value)
Definition blpapi_element.h:1607
Definition blpapi_name.h:150
Definition blpapi_request.h:435
Request * ptr() const
Definition blpapi_request.h:739
RequestRef(Request *request_p)
Definition blpapi_request.h:734
Request * operator->() const
Definition blpapi_request.h:741
Definition blpapi_request.h:147
BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, bool value)
Definition blpapi_request.h:527
blpapi_Request_t * handle() const
Definition blpapi_request.h:718
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_request.h:720
BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, bool value)
Definition blpapi_request.h:487
BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name)
Definition blpapi_request.h:687
~Request()
Definition blpapi_request.h:478
Request(blpapi_Request_t *handle)
Definition blpapi_request.h:452
const char * getRequestId() const
Definition blpapi_request.h:711
Element asElement()
Definition blpapi_request.h:697
struct blpapi_Element blpapi_Element_t
Definition blpapi_types.h:136
blpapi_Float64_t Float64
Definition blpapi_types.h:474
blpapi_Float32_t Float32
Definition blpapi_types.h:473
blpapi_Int64_t Int64
Definition blpapi_types.h:471
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:592
blpapi_Int32_t Int32
Definition blpapi_types.h:469
Definition blpapi_abstractsession.h:195