BLPAPI C++  3.24.10
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 
60 #include <blpapi_correlationid.h>
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 
68 struct blpapi_Request;
69 typedef struct blpapi_Request blpapi_Request_t;
70 
71 #ifdef __cplusplus
72 extern "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 
104 namespace BloombergLP {
105 namespace blpapi {
106 
107 class RequestRef;
108 
147 class Request {
148 
149  blpapi_Request_t *d_handle;
150  Element d_elements;
151 
153  Request& operator=(const Request& rhs);
154 
155  public:
156  explicit Request(blpapi_Request_t *handle);
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);
358  Element asElement();
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 
422 std::ostream& operator<<(std::ostream& stream, const Request& request);
435 class RequestRef {
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 
485 inline Request::operator RequestRef() { return RequestRef(this); }
486 
487 inline void Request::set(const char *element, bool value)
488 {
489  d_elements.setElement(Name(element), value);
490 }
491 
492 inline void Request::set(const char *element, char value)
493 {
494  d_elements.setElement(Name(element), value);
495 }
496 
497 inline void Request::set(const char *element, Int32 value)
498 {
499  d_elements.setElement(Name(element), value);
500 }
501 
502 inline void Request::set(const char *element, Int64 value)
503 {
504  d_elements.setElement(Name(element), value);
505 }
506 
507 inline void Request::set(const char *element, Float32 value)
508 {
509  d_elements.setElement(Name(element), value);
510 }
511 
512 inline void Request::set(const char *element, Float64 value)
513 {
514  d_elements.setElement(Name(element), value);
515 }
516 
517 inline void Request::set(const char *element, const Datetime& value)
518 {
519  d_elements.setElement(Name(element), value);
520 }
521 
522 inline void Request::set(const char *element, const char *value)
523 {
524  d_elements.setElement(Name(element), value);
525 }
526 
527 inline void Request::append(const char *element, bool value)
528 {
529  Element namedElement = d_elements.getElement(Name(element));
530  namedElement.appendValue(value);
531 }
532 
533 inline void Request::append(const char *element, char value)
534 {
535  Element namedElement = d_elements.getElement(Name(element));
536  namedElement.appendValue(value);
537 }
538 
539 inline void Request::append(const char *element, Int32 value)
540 {
541  Element namedElement = d_elements.getElement(Name(element));
542  namedElement.appendValue(value);
543 }
544 
545 inline void Request::append(const char *element, Int64 value)
546 {
547  Element namedElement = d_elements.getElement(Name(element));
548  namedElement.appendValue(value);
549 }
550 
551 inline void Request::append(const char *element, Float32 value)
552 {
553  Element namedElement = d_elements.getElement(Name(element));
554  namedElement.appendValue(value);
555 }
556 
557 inline void Request::append(const char *element, Float64 value)
558 {
559  Element namedElement = d_elements.getElement(Name(element));
560  namedElement.appendValue(value);
561 }
562 
563 inline void Request::append(const char *element, const Datetime& value)
564 {
565  Element namedElement = d_elements.getElement(Name(element));
566  namedElement.appendValue(value);
567 }
568 
569 inline void Request::append(const char *element, const char *value)
570 {
571  Element namedElement = d_elements.getElement(Name(element));
572  namedElement.appendValue(value);
573 }
574 
575 inline void Request::set(const Name& element, bool value)
576 {
577  d_elements.setElement(element, value);
578 }
579 
580 inline void Request::set(const Name& element, char value)
581 {
582  d_elements.setElement(element, value);
583 }
584 
585 inline void Request::set(const Name& element, Int32 value)
586 {
587  d_elements.setElement(element, value);
588 }
589 
590 inline void Request::set(const Name& element, Int64 value)
591 {
592  d_elements.setElement(element, value);
593 }
594 
595 inline void Request::set(const Name& element, Float32 value)
596 {
597  d_elements.setElement(element, value);
598 }
599 
600 inline void Request::set(const Name& element, Float64 value)
601 {
602  d_elements.setElement(element, value);
603 }
604 
605 inline void Request::set(const Name& element, const Datetime& value)
606 {
607  d_elements.setElement(element, value);
608 }
609 
610 inline void Request::set(const Name& element, const char *value)
611 {
612  d_elements.setElement(element, value);
613 }
614 
615 inline void Request::set(const Name& element, const std::string& value)
616 {
617  d_elements.setElement(element, value);
618 }
619 
620 inline void Request::set(
621  const Name& element, const void *value, std::size_t length)
622 {
623  d_elements.setElement(element, value, length);
624 }
625 
626 template <typename BYTES,
627  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
628 inline void Request::set(const Name& element, const BYTES& value)
629 {
630  d_elements.setElement(element, value);
631 }
632 
633 inline void Request::append(const Name& element, bool value)
634 {
635  Element namedElement = d_elements.getElement(element);
636  namedElement.appendValue(value);
637 }
638 
639 inline void Request::append(const Name& element, char value)
640 {
641  Element namedElement = d_elements.getElement(element);
642  namedElement.appendValue(value);
643 }
644 
645 inline void Request::append(const Name& element, Int32 value)
646 {
647  Element namedElement = d_elements.getElement(element);
648  namedElement.appendValue(value);
649 }
650 
651 inline void Request::append(const Name& element, Int64 value)
652 {
653  Element namedElement = d_elements.getElement(element);
654  namedElement.appendValue(value);
655 }
656 
657 inline void Request::append(const Name& element, Float32 value)
658 {
659  Element namedElement = d_elements.getElement(element);
660  namedElement.appendValue(value);
661 }
662 
663 inline void Request::append(const Name& element, Float64 value)
664 {
665  Element namedElement = d_elements.getElement(element);
666  namedElement.appendValue(value);
667 }
668 
669 inline void Request::append(const Name& element, const Datetime& value)
670 {
671  Element namedElement = d_elements.getElement(element);
672  namedElement.appendValue(value);
673 }
674 
675 inline void Request::append(const Name& element, const char *value)
676 {
677  Element namedElement = d_elements.getElement(element);
678  namedElement.appendValue(value);
679 }
680 
681 inline void Request::append(const Name& element, const std::string& value)
682 {
683  Element namedElement = d_elements.getElement(element);
684  namedElement.appendValue(value);
685 }
686 
687 inline Element Request::getElement(const char *name)
688 {
689  return d_elements.getElement(Name(name));
690 }
691 
692 inline Element Request::getElement(const Name& name)
693 {
694  return d_elements.getElement(name);
695 }
696 
697 inline Element Request::asElement() { return d_elements; }
698 
699 inline const Element Request::getElement(const char *name) const
700 {
701  return d_elements.getElement(Name(name));
702 }
703 
704 inline const Element Request::getElement(const Name& name) const
705 {
706  return d_elements.getElement(name);
707 }
708 
709 inline const Element Request::asElement() const { return d_elements; }
710 
711 inline 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 
718 inline blpapi_Request_t *Request::handle() const { return d_handle; }
719 
720 inline std::ostream& Request::print(
721  std::ostream& stream, int level, int spacesPerLevel) const
722 {
723  return d_elements.print(stream, level, spacesPerLevel);
724 }
725 
726 inline 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 
739 inline Request *RequestRef::ptr() const { return this->d_request_p; }
740 
741 inline 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
Request * operator->() const
Definition: blpapi_request.h:741
RequestRef(Request *request_p)
Definition: blpapi_request.h:734
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_request.h:720
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
blpapi_Request_t * handle() const
Definition: blpapi_request.h:718
BLPAPI_DEPRECATE_STRING_NAME Element getElement(const char *name)
Definition: blpapi_request.h:687
Common definitions used by the library.
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
Definition: blpapi_abstractsession.h:187
blpapi_Element_t * blpapi_Request_elements(blpapi_Request_t *request)
Definition: blpapi_name.h:150
#define BLPAPI_CALL(FUNCNAME)
Definition: blpapi_call.h:353
blpapi_Float64_t Float64
Definition: blpapi_types.h:474
Element asElement()
Definition: blpapi_request.h:697
void appendValue(bool value)
Definition: blpapi_element.h:1818
BLPAPI_DEPRECATE_STRING_NAME void set(const char *name, bool value)
Definition: blpapi_request.h:487
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
Provide a key to identify individual subscriptions or requests.
Definition: blpapi_request.h:147
Definition: blpapi_element.h:465
Definition: blpapi_request.h:435
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition: blpapi_correlationid.h:592
void blpapi_Request_setPreferredRoute(blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId)
const char * getRequestId() const
Definition: blpapi_request.h:711
blpapi_Int64_t Int64
Definition: blpapi_types.h:471
void blpapi_Request_destroy(blpapi_Request_t *request)
BLPAPI_DEPRECATE_STRING_NAME int getElement(Element *result, const char *name) const
Definition: blpapi_element.h:1910
BLPAPI_DEPRECATE_STRING_NAME void setElement(const char *name, bool value)
Definition: blpapi_element.h:1607
Defines Exceptions that can be thrown by the blpapi library.
struct blpapi_Request blpapi_Request_t
Definition: blpapi_dispatchtbl.h:81
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2327
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
~Request()
Definition: blpapi_request.h:478
Definition: blpapi_datetime.h:245
BLPAPI_DEPRECATE_STRING_NAME void append(const char *name, bool value)
Definition: blpapi_request.h:527
Provide BLPAPI types.
Request(blpapi_Request_t *handle)
Definition: blpapi_request.h:452
int blpapi_Request_getRequestId(const blpapi_Request_t *request, const char **requestId)
Request * ptr() const
Definition: blpapi_request.h:739
Provide a representation of an item in a message.
Provide a representation of strings for use as container keys.
void rebind(blpapi_Element_t *element)
Definition: blpapi_element.h:1602