BLPAPI C++ 3.26.6
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
37
38#ifndef INCLUDED_BLPAPI_REQUEST
39#define INCLUDED_BLPAPI_REQUEST
40
72
74#include <blpapi_defs.h>
75#include <blpapi_deprecate.h>
76#include <blpapi_element.h>
77#include <blpapi_exception.h>
78#include <blpapi_name.h>
79#include <blpapi_types.h>
80
81struct blpapi_Request;
82#ifdef __cplusplus
83extern "C" {
84#endif
85
87typedef struct blpapi_Request blpapi_Request_t;
88
92
103BLPAPI_EXPORT
104void blpapi_Request_destroy(blpapi_Request_t *request);
105
116BLPAPI_EXPORT
117blpapi_Element_t *blpapi_Request_elements(blpapi_Request_t *request);
118
130BLPAPI_EXPORT
131void blpapi_Request_setPreferredRoute(
132 blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId);
133
150BLPAPI_EXPORT
151int blpapi_Request_getRequestId(
152 const blpapi_Request_t *request, const char **requestId);
153
156
157#ifdef __cplusplus
158}
159
160#include <cassert>
161#include <cstddef>
162#include <iosfwd>
163#include <string>
164
165namespace BloombergLP {
166namespace blpapi {
173
174class RequestRef;
175
214class Request {
215
216 blpapi_Request_t *d_handle;
217 Element d_elements;
218
220 Request& operator=(const Request& rhs);
221
222 public:
223 explicit Request(blpapi_Request_t *handle);
224
225 Request(RequestRef src);
226 Request(Request& src);
231
232 ~Request();
236
237 operator RequestRef();
245
246 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, bool value);
252
253 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, char value);
259
260 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Int32 value);
266
267 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Int64 value);
273
274 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Float32 value);
280
281 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, Float64 value);
287
288 BLPAPI_DEPRECATE_STRING_NAME void set(
289 const char *name, const Datetime& value);
295
296 BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, const char *value);
302
303 void set(const Name& name, bool value);
307
308 void set(const Name& name, char value);
312
313 void set(const Name& name, Int32 value);
317
318 void set(const Name& name, Int64 value);
322
323 void set(const Name& name, Float32 value);
327
328 void set(const Name& name, Float64 value);
332
333 void set(const Name& name, const Datetime& value);
337
338 void set(const Name& name, const char *value);
342
343 void set(const Name& name, const std::string& value);
347
348 void set(const Name& name, const void *value, std::size_t length);
352
353 template <typename BYTES,
354 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
355 = true>
356 void set(const Name& name, const BYTES& value);
360
361 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, bool value);
367
368 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, char value);
374
375 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Int32 value);
381
382 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Int64 value);
388
389 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Float32 value);
395
396 BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, Float64 value);
402
403 BLPAPI_DEPRECATE_STRING_NAME void append(
404 const char *name, const Datetime& value);
410
411 BLPAPI_DEPRECATE_STRING_NAME void append(
412 const char *name, const char *value);
418
419 void append(const Name& name, bool value);
423
424 void append(const Name& name, char value);
428
429 void append(const Name& name, Int32 value);
433
434 void append(const Name& name, Int64 value);
438
439 void append(const Name& name, Float32 value);
443
444 void append(const Name& name, Float64 value);
448
449 void append(const Name& name, const Datetime& value);
453
454 void append(const Name& name, const char *value);
458
459 void append(const Name& name, const std::string& value);
463
468
469 BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name);
475
476 Element getElement(const Name& name);
480
481 BLPAPI_DEPRECATE_STRING_NAME const Element getElement(
482 const char *name) const;
488
489 const Element getElement(const Name& name) const;
493
494 const Element asElement() const;
498
499 void fromJson(const char *json);
508
509 void fromJson(const std::string& json);
520
521 const char *getRequestId() const;
532
534 blpapi_Request_t *handle() const;
536
537 std::ostream& print(
538 std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
551};
552
555
556std::ostream& operator<<(std::ostream& stream, const Request& request);
568
575
588 Request *d_request_p;
589
590 public:
591 RequestRef(Request *request_p);
596
597 Request *ptr() const;
601
602 Request *operator->() const;
606};
607
610
611//=============================================================================
612// INLINE FUNCTION DEFINITIONS
613//=============================================================================
614
615// -------------
616// class Request
617// -------------
618
619inline Request::Request(blpapi_Request_t *newHandle)
620{
621 d_handle = newHandle;
622 if (newHandle) {
623 d_elements.rebind(blpapi_Request_elements(newHandle));
624 }
625}
626
628{
629 Request *src = ref.ptr();
630 assert(src);
631 d_handle = src->d_handle;
632 d_elements = src->d_elements;
633 src->d_handle = 0;
634 src->d_elements.rebind(0);
635}
636
638{
639 d_handle = src.d_handle;
640 d_elements = src.d_elements;
641 src.d_handle = 0;
642 src.d_elements.rebind(0);
643}
644
646{
647 if (d_handle) {
648 blpapi_Request_destroy(d_handle);
649 }
650}
651
652inline Request::operator RequestRef() { return RequestRef(this); }
653
654inline void Request::set(const char *element, bool value)
655{
656 d_elements.setElement(Name(element), value);
657}
658
659inline void Request::set(const char *element, char value)
660{
661 d_elements.setElement(Name(element), value);
662}
663
664inline void Request::set(const char *element, Int32 value)
665{
666 d_elements.setElement(Name(element), value);
667}
668
669inline void Request::set(const char *element, Int64 value)
670{
671 d_elements.setElement(Name(element), value);
672}
673
674inline void Request::set(const char *element, Float32 value)
675{
676 d_elements.setElement(Name(element), value);
677}
678
679inline void Request::set(const char *element, Float64 value)
680{
681 d_elements.setElement(Name(element), value);
682}
683
684inline void Request::set(const char *element, const Datetime& value)
685{
686 d_elements.setElement(Name(element), value);
687}
688
689inline void Request::set(const char *element, const char *value)
690{
691 d_elements.setElement(Name(element), value);
692}
693
694inline void Request::append(const char *element, bool value)
695{
696 Element namedElement = d_elements.getElement(Name(element));
697 namedElement.appendValue(value);
698}
699
700inline void Request::append(const char *element, char value)
701{
702 Element namedElement = d_elements.getElement(Name(element));
703 namedElement.appendValue(value);
704}
705
706inline void Request::append(const char *element, Int32 value)
707{
708 Element namedElement = d_elements.getElement(Name(element));
709 namedElement.appendValue(value);
710}
711
712inline void Request::append(const char *element, Int64 value)
713{
714 Element namedElement = d_elements.getElement(Name(element));
715 namedElement.appendValue(value);
716}
717
718inline void Request::append(const char *element, Float32 value)
719{
720 Element namedElement = d_elements.getElement(Name(element));
721 namedElement.appendValue(value);
722}
723
724inline void Request::append(const char *element, Float64 value)
725{
726 Element namedElement = d_elements.getElement(Name(element));
727 namedElement.appendValue(value);
728}
729
730inline void Request::append(const char *element, const Datetime& value)
731{
732 Element namedElement = d_elements.getElement(Name(element));
733 namedElement.appendValue(value);
734}
735
736inline void Request::append(const char *element, const char *value)
737{
738 Element namedElement = d_elements.getElement(Name(element));
739 namedElement.appendValue(value);
740}
741
742inline void Request::set(const Name& element, bool value)
743{
744 d_elements.setElement(element, value);
745}
746
747inline void Request::set(const Name& element, char value)
748{
749 d_elements.setElement(element, value);
750}
751
752inline void Request::set(const Name& element, Int32 value)
753{
754 d_elements.setElement(element, value);
755}
756
757inline void Request::set(const Name& element, Int64 value)
758{
759 d_elements.setElement(element, value);
760}
761
762inline void Request::set(const Name& element, Float32 value)
763{
764 d_elements.setElement(element, value);
765}
766
767inline void Request::set(const Name& element, Float64 value)
768{
769 d_elements.setElement(element, value);
770}
771
772inline void Request::set(const Name& element, const Datetime& value)
773{
774 d_elements.setElement(element, value);
775}
776
777inline void Request::set(const Name& element, const char *value)
778{
779 d_elements.setElement(element, value);
780}
781
782inline void Request::set(const Name& element, const std::string& value)
783{
784 d_elements.setElement(element, value);
785}
786
787inline void Request::set(
788 const Name& element, const void *value, std::size_t length)
789{
790 d_elements.setElement(element, value, length);
791}
792
793template <typename BYTES,
794 typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
795inline void Request::set(const Name& element, const BYTES& value)
796{
797 d_elements.setElement(element, value);
798}
799
800inline void Request::append(const Name& element, bool value)
801{
802 Element namedElement = d_elements.getElement(element);
803 namedElement.appendValue(value);
804}
805
806inline void Request::append(const Name& element, char value)
807{
808 Element namedElement = d_elements.getElement(element);
809 namedElement.appendValue(value);
810}
811
812inline void Request::append(const Name& element, Int32 value)
813{
814 Element namedElement = d_elements.getElement(element);
815 namedElement.appendValue(value);
816}
817
818inline void Request::append(const Name& element, Int64 value)
819{
820 Element namedElement = d_elements.getElement(element);
821 namedElement.appendValue(value);
822}
823
824inline void Request::append(const Name& element, Float32 value)
825{
826 Element namedElement = d_elements.getElement(element);
827 namedElement.appendValue(value);
828}
829
830inline void Request::append(const Name& element, Float64 value)
831{
832 Element namedElement = d_elements.getElement(element);
833 namedElement.appendValue(value);
834}
835
836inline void Request::append(const Name& element, const Datetime& value)
837{
838 Element namedElement = d_elements.getElement(element);
839 namedElement.appendValue(value);
840}
841
842inline void Request::append(const Name& element, const char *value)
843{
844 Element namedElement = d_elements.getElement(element);
845 namedElement.appendValue(value);
846}
847
848inline void Request::append(const Name& element, const std::string& value)
849{
850 Element namedElement = d_elements.getElement(element);
851 namedElement.appendValue(value);
852}
853
854inline Element Request::getElement(const char *name)
855{
856 return d_elements.getElement(Name(name));
857}
858
860{
861 return d_elements.getElement(name);
862}
863
864inline Element Request::asElement() { return d_elements; }
865
866inline const Element Request::getElement(const char *name) const
867{
868 return d_elements.getElement(Name(name));
869}
870
871inline const Element Request::getElement(const Name& name) const
872{
873 return d_elements.getElement(name);
874}
875
876inline const Element Request::asElement() const { return d_elements; }
877
878inline void Request::fromJson(const char *json) { d_elements.fromJson(json); }
879
880inline void Request::fromJson(const std::string& json)
881{
882 fromJson(json.c_str());
883}
884
885inline const char *Request::getRequestId() const
886{
887 const char *requestId = 0;
888 BLPAPI_CALL(blpapi_Request_getRequestId)(d_handle, &requestId);
889 return requestId;
890}
891
893inline blpapi_Request_t *Request::handle() const { return d_handle; }
895
896inline std::ostream& Request::print(
897 std::ostream& stream, int level, int spacesPerLevel) const
898{
899 return d_elements.print(stream, level, spacesPerLevel);
900}
901
902inline std::ostream& operator<<(std::ostream& stream, const Request& request)
903{
904 return request.print(stream, 0, -1);
905}
906// ----------------
907// class RequestRef
908// ----------------
909
911 : d_request_p(request)
912{
913}
914
915inline Request *RequestRef::ptr() const { return this->d_request_p; }
916
917inline Request *RequestRef::operator->() const { return this->d_request_p; }
918
919} // close namespace blpapi
920} // close namespace BloombergLP
921
922#endif // #ifdef __cplusplus
923
924#endif // #ifndef INCLUDED_BLPAPI_REQUEST
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:312
Definition blpapi_element.h:1098
void rebind(blpapi_Element_t *element)
Definition blpapi_element.h:2255
int getElement(Element *result, const char *name) const
Definition blpapi_element.h:2565
void appendValue(bool value)
Definition blpapi_element.h:2471
void fromJson(const char *json)
Definition blpapi_element.h:3003
Definition blpapi_name.h:228
Definition blpapi_request.h:587
Request * ptr() const
Definition blpapi_request.h:915
RequestRef(Request *request_p)
Definition blpapi_request.h:910
Request * operator->() const
Definition blpapi_request.h:917
Definition blpapi_request.h:214
void append(const char *name, bool value)
Definition blpapi_request.h:694
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition blpapi_request.h:896
void set(const char *name, bool value)
Definition blpapi_request.h:654
Element getElement(const char *name)
Definition blpapi_request.h:854
void fromJson(const char *json)
Definition blpapi_request.h:878
~Request()
Definition blpapi_request.h:645
Request(blpapi_Request_t *handle)
Definition blpapi_request.h:619
const char * getRequestId() const
Definition blpapi_request.h:885
Element asElement()
Definition blpapi_request.h:864
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