BLPAPI C++  3.23.2
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_element.h>
63 #include <blpapi_exception.h>
64 #include <blpapi_types.h>
65 
66 struct blpapi_Request;
67 typedef struct blpapi_Request blpapi_Request_t;
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
75 
78 
81  blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId);
82 
85  const blpapi_Request_t *request, const char **requestId);
86 
87 #ifdef __cplusplus
88 }
89 
90 #include <cassert>
91 #include <cstddef>
92 #include <iosfwd>
93 #include <string>
94 
102 namespace BloombergLP {
103 namespace blpapi {
104 
105 class RequestRef;
106 
145 class Request {
146 
147  blpapi_Request_t *d_handle;
148  Element d_elements;
149 
151  Request& operator=(const Request& rhs);
152 
153  public:
154  explicit Request(blpapi_Request_t *handle);
155 
156  Request(RequestRef src);
157  Request(Request& src);
163  ~Request();
168  operator RequestRef();
169 
170  void set(const char *name, bool value);
175  void set(const char *name, char value);
180  void set(const char *name, Int32 value);
185  void set(const char *name, Int64 value);
190  void set(const char *name, Float32 value);
195  void set(const char *name, Float64 value);
200  void set(const char *name, const Datetime& value);
205  void set(const char *name, const char *value);
210  void set(const Name& name, bool value);
215  void set(const Name& name, char value);
220  void set(const Name& name, Int32 value);
225  void set(const Name& name, Int64 value);
230  void set(const Name& name, Float32 value);
235  void set(const Name& name, Float64 value);
240  void set(const Name& name, const Datetime& value);
245  void set(const Name& name, const char *value);
250  void set(const Name& name, const std::string& value);
255  void set(const Name& name, const void *value, std::size_t length);
260  template <typename BYTES,
261  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
262  = true>
263  void set(const Name& name, const BYTES& value);
268  void append(const char *name, bool value);
273  void append(const char *name, char value);
278  void append(const char *name, Int32 value);
283  void append(const char *name, Int64 value);
288  void append(const char *name, Float32 value);
293  void append(const char *name, Float64 value);
298  void append(const char *name, const Datetime& value);
303  void append(const char *name, const char *value);
308  void append(const Name& name, bool value);
313  void append(const Name& name, char value);
318  void append(const Name& name, Int32 value);
323  void append(const Name& name, Int64 value);
328  void append(const Name& name, Float32 value);
333  void append(const Name& name, Float64 value);
338  void append(const Name& name, const Datetime& value);
343  void append(const Name& name, const char *value);
348  void append(const Name& name, const std::string& value);
353  Element asElement();
358  Element getElement(const char *name);
363  Element getElement(const Name& name);
368  const Element getElement(const char *name) const;
373  const Element getElement(const Name& name) const;
378  const Element asElement() const;
383  const char *getRequestId() const;
395  blpapi_Request_t *handle() const;
396 
397  std::ostream& print(
398  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
411 };
412 
416 std::ostream& operator<<(std::ostream& stream, const Request& request);
429 class RequestRef {
430  Request *d_request_p;
431 
432  public:
433  RequestRef(Request *request_p);
434  Request *ptr() const;
435  Request *operator->() const;
436 };
437 
438 //=============================================================================
439 // INLINE FUNCTION DEFINITIONS
440 //=============================================================================
441 
442 // -------------
443 // class Request
444 // -------------
445 
447 {
448  d_handle = newHandle;
449  if (newHandle) {
450  d_elements.rebind(blpapi_Request_elements(newHandle));
451  }
452 }
453 
455 {
456  Request *src = ref.ptr();
457  assert(src);
458  d_handle = src->d_handle;
459  d_elements = src->d_elements;
460  src->d_handle = 0;
461  src->d_elements.rebind(0);
462 }
463 
465 {
466  d_handle = src.d_handle;
467  d_elements = src.d_elements;
468  src.d_handle = 0;
469  src.d_elements.rebind(0);
470 }
471 
473 {
474  if (d_handle) {
475  blpapi_Request_destroy(d_handle);
476  }
477 }
478 
479 inline Request::operator RequestRef() { return this; }
480 
481 inline void Request::set(const char *element, bool value)
482 {
483  d_elements.setElement(element, value);
484 }
485 
486 inline void Request::set(const char *element, char value)
487 {
488  d_elements.setElement(element, value);
489 }
490 
491 inline void Request::set(const char *element, Int32 value)
492 {
493  d_elements.setElement(element, value);
494 }
495 
496 inline void Request::set(const char *element, Int64 value)
497 {
498  d_elements.setElement(element, value);
499 }
500 
501 inline void Request::set(const char *element, Float32 value)
502 {
503  d_elements.setElement(element, value);
504 }
505 
506 inline void Request::set(const char *element, Float64 value)
507 {
508  d_elements.setElement(element, value);
509 }
510 
511 inline void Request::set(const char *element, const Datetime& value)
512 {
513  d_elements.setElement(element, value);
514 }
515 
516 inline void Request::set(const char *element, const char *value)
517 {
518  d_elements.setElement(element, value);
519 }
520 
521 inline void Request::append(const char *element, bool value)
522 {
523  Element namedElement = d_elements.getElement(element);
524  namedElement.appendValue(value);
525 }
526 
527 inline void Request::append(const char *element, char value)
528 {
529  Element namedElement = d_elements.getElement(element);
530  namedElement.appendValue(value);
531 }
532 
533 inline void Request::append(const char *element, Int32 value)
534 {
535  Element namedElement = d_elements.getElement(element);
536  namedElement.appendValue(value);
537 }
538 
539 inline void Request::append(const char *element, Int64 value)
540 {
541  Element namedElement = d_elements.getElement(element);
542  namedElement.appendValue(value);
543 }
544 
545 inline void Request::append(const char *element, Float32 value)
546 {
547  Element namedElement = d_elements.getElement(element);
548  namedElement.appendValue(value);
549 }
550 
551 inline void Request::append(const char *element, Float64 value)
552 {
553  Element namedElement = d_elements.getElement(element);
554  namedElement.appendValue(value);
555 }
556 
557 inline void Request::append(const char *element, const Datetime& value)
558 {
559  Element namedElement = d_elements.getElement(element);
560  namedElement.appendValue(value);
561 }
562 
563 inline void Request::append(const char *element, const char *value)
564 {
565  Element namedElement = d_elements.getElement(element);
566  namedElement.appendValue(value);
567 }
568 
569 inline void Request::set(const Name& element, bool value)
570 {
571  d_elements.setElement(element, value);
572 }
573 
574 inline void Request::set(const Name& element, char value)
575 {
576  d_elements.setElement(element, value);
577 }
578 
579 inline void Request::set(const Name& element, Int32 value)
580 {
581  d_elements.setElement(element, value);
582 }
583 
584 inline void Request::set(const Name& element, Int64 value)
585 {
586  d_elements.setElement(element, value);
587 }
588 
589 inline void Request::set(const Name& element, Float32 value)
590 {
591  d_elements.setElement(element, value);
592 }
593 
594 inline void Request::set(const Name& element, Float64 value)
595 {
596  d_elements.setElement(element, value);
597 }
598 
599 inline void Request::set(const Name& element, const Datetime& value)
600 {
601  d_elements.setElement(element, value);
602 }
603 
604 inline void Request::set(const Name& element, const char *value)
605 {
606  d_elements.setElement(element, value);
607 }
608 
609 inline void Request::set(const Name& element, const std::string& value)
610 {
611  d_elements.setElement(element, value);
612 }
613 
614 inline void Request::set(
615  const Name& element, const void *value, std::size_t length)
616 {
617  d_elements.setElement(element, value, length);
618 }
619 
620 template <typename BYTES,
621  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
622 inline void Request::set(const Name& element, const BYTES& value)
623 {
624  d_elements.setElement(element, value);
625 }
626 
627 inline void Request::append(const Name& element, bool value)
628 {
629  Element namedElement = d_elements.getElement(element);
630  namedElement.appendValue(value);
631 }
632 
633 inline void Request::append(const Name& element, char value)
634 {
635  Element namedElement = d_elements.getElement(element);
636  namedElement.appendValue(value);
637 }
638 
639 inline void Request::append(const Name& element, Int32 value)
640 {
641  Element namedElement = d_elements.getElement(element);
642  namedElement.appendValue(value);
643 }
644 
645 inline void Request::append(const Name& element, Int64 value)
646 {
647  Element namedElement = d_elements.getElement(element);
648  namedElement.appendValue(value);
649 }
650 
651 inline void Request::append(const Name& element, Float32 value)
652 {
653  Element namedElement = d_elements.getElement(element);
654  namedElement.appendValue(value);
655 }
656 
657 inline void Request::append(const Name& element, Float64 value)
658 {
659  Element namedElement = d_elements.getElement(element);
660  namedElement.appendValue(value);
661 }
662 
663 inline void Request::append(const Name& element, const Datetime& value)
664 {
665  Element namedElement = d_elements.getElement(element);
666  namedElement.appendValue(value);
667 }
668 
669 inline void Request::append(const Name& element, const char *value)
670 {
671  Element namedElement = d_elements.getElement(element);
672  namedElement.appendValue(value);
673 }
674 
675 inline void Request::append(const Name& element, const std::string& value)
676 {
677  Element namedElement = d_elements.getElement(element);
678  namedElement.appendValue(value);
679 }
680 
681 inline Element Request::getElement(const char *name)
682 {
683  return d_elements.getElement(name);
684 }
685 
686 inline Element Request::getElement(const Name& name)
687 {
688  return d_elements.getElement(name);
689 }
690 
691 inline Element Request::asElement() { return d_elements; }
692 
693 inline const Element Request::getElement(const char *name) const
694 {
695  return d_elements.getElement(name);
696 }
697 
698 inline const Element Request::getElement(const Name& name) const
699 {
700  return d_elements.getElement(name);
701 }
702 
703 inline const Element Request::asElement() const { return d_elements; }
704 
705 inline const char *Request::getRequestId() const
706 {
707  const char *requestId = 0;
708  BLPAPI_CALL(blpapi_Request_getRequestId)(d_handle, &requestId);
709  return requestId;
710 }
711 
712 inline blpapi_Request_t *Request::handle() const { return d_handle; }
713 
714 inline std::ostream& Request::print(
715  std::ostream& stream, int level, int spacesPerLevel) const
716 {
717  return d_elements.print(stream, level, spacesPerLevel);
718 }
719 
720 inline std::ostream& operator<<(std::ostream& stream, const Request& request)
721 {
722  return request.print(stream, 0, -1);
723 }
724 // ----------------
725 // class RequestRef
726 // ----------------
727 
729  : d_request_p(request)
730 {
731 }
732 
733 inline Request *RequestRef::ptr() const { return this->d_request_p; }
734 
735 inline Request *RequestRef::operator->() const { return this->d_request_p; }
736 
737 } // close namespace blpapi
738 } // close namespace BloombergLP
739 
740 #endif // #ifdef __cplusplus
741 
742 #endif // #ifndef INCLUDED_BLPAPI_REQUEST
Request * operator->() const
Definition: blpapi_request.h:735
RequestRef(Request *request_p)
Definition: blpapi_request.h:728
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_request.h:714
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
blpapi_Request_t * handle() const
Definition: blpapi_request.h:712
struct blpapi_Request blpapi_Request_t
Definition: blpapi_request.h:67
Element getElement(const char *name)
Definition: blpapi_request.h:681
Common definitions used by the library.
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
Definition: blpapi_abstractsession.h:220
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:691
void appendValue(bool value)
Definition: blpapi_element.h:1802
void set(const char *name, bool value)
Definition: blpapi_request.h:481
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
Provide a key to identify individual subscriptions or requests.
Definition: blpapi_request.h:145
Definition: blpapi_element.h:464
Definition: blpapi_request.h:429
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:705
blpapi_Int64_t Int64
Definition: blpapi_types.h:471
void blpapi_Request_destroy(blpapi_Request_t *request)
int getElement(Element *result, const char *name) const
Definition: blpapi_element.h:1891
void setElement(const char *name, bool value)
Definition: blpapi_element.h:1591
Defines Exceptions that can be thrown by the blpapi library.
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_element.h:2308
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
~Request()
Definition: blpapi_request.h:472
Definition: blpapi_datetime.h:245
void append(const char *name, bool value)
Definition: blpapi_request.h:521
Provide BLPAPI types.
Request(blpapi_Request_t *handle)
Definition: blpapi_request.h:446
int blpapi_Request_getRequestId(const blpapi_Request_t *request, const char **requestId)
Request * ptr() const
Definition: blpapi_request.h:733
Provide a representation of an item in a message.
void rebind(blpapi_Element_t *element)
Definition: blpapi_element.h:1586