BLPAPI C++  3.24.4
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_name.h>
65 #include <blpapi_types.h>
66 
67 struct blpapi_Request;
68 typedef struct blpapi_Request blpapi_Request_t;
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
76 
79 
82  blpapi_Request_t *request, blpapi_CorrelationId_t *correlationId);
83 
86  const blpapi_Request_t *request, const char **requestId);
87 
88 #ifdef __cplusplus
89 }
90 
91 #include <cassert>
92 #include <cstddef>
93 #include <iosfwd>
94 #include <string>
95 
103 namespace BloombergLP {
104 namespace blpapi {
105 
106 class RequestRef;
107 
146 class Request {
147 
148  blpapi_Request_t *d_handle;
149  Element d_elements;
150 
152  Request& operator=(const Request& rhs);
153 
154  public:
155  explicit Request(blpapi_Request_t *handle);
156 
157  Request(RequestRef src);
158  Request(Request& src);
164  ~Request();
169  operator RequestRef();
170 
171  [[deprecated("Use the form that takes Name instead of const char*")]] void
172  set(const char *name, bool value);
177  [[deprecated("Use the form that takes Name instead of const char*")]] void
178  set(const char *name, char value);
183  [[deprecated("Use the form that takes Name instead of const char*")]] void
184  set(const char *name, Int32 value);
189  [[deprecated("Use the form that takes Name instead of const char*")]] void
190  set(const char *name, Int64 value);
195  [[deprecated("Use the form that takes Name instead of const char*")]] void
196  set(const char *name, Float32 value);
201  [[deprecated("Use the form that takes Name instead of const char*")]] void
202  set(const char *name, Float64 value);
207  [[deprecated("Use the form that takes Name instead of const char*")]] void
208  set(const char *name, const Datetime& value);
213  [[deprecated("Use the form that takes Name instead of const char*")]] void
214  set(const char *name, const char *value);
219  void set(const Name& name, bool value);
224  void set(const Name& name, char value);
229  void set(const Name& name, Int32 value);
234  void set(const Name& name, Int64 value);
239  void set(const Name& name, Float32 value);
244  void set(const Name& name, Float64 value);
249  void set(const Name& name, const Datetime& value);
254  void set(const Name& name, const char *value);
259  void set(const Name& name, const std::string& value);
264  void set(const Name& name, const void *value, std::size_t length);
269  template <typename BYTES,
270  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type
271  = true>
272  void set(const Name& name, const BYTES& value);
277  [[deprecated("Use the form that takes Name instead of const char*")]] void
278  append(const char *name, bool value);
283  [[deprecated("Use the form that takes Name instead of const char*")]] void
284  append(const char *name, char value);
289  [[deprecated("Use the form that takes Name instead of const char*")]] void
290  append(const char *name, Int32 value);
295  [[deprecated("Use the form that takes Name instead of const char*")]] void
296  append(const char *name, Int64 value);
301  [[deprecated("Use the form that takes Name instead of const char*")]] void
302  append(const char *name, Float32 value);
307  [[deprecated("Use the form that takes Name instead of const char*")]] void
308  append(const char *name, Float64 value);
313  [[deprecated("Use the form that takes Name instead of const char*")]] void
314  append(const char *name, const Datetime& value);
319  [[deprecated("Use the form that takes Name instead of const char*")]] void
320  append(const char *name, const char *value);
325  void append(const Name& name, bool value);
330  void append(const Name& name, char value);
335  void append(const Name& name, Int32 value);
340  void append(const Name& name, Int64 value);
345  void append(const Name& name, Float32 value);
350  void append(const Name& name, Float64 value);
355  void append(const Name& name, const Datetime& value);
360  void append(const Name& name, const char *value);
365  void append(const Name& name, const std::string& value);
370  Element asElement();
375  [[deprecated(
376  "Use the form that takes Name instead of const char*")]] Element
377  getElement(const char *name);
382  Element getElement(const Name& name);
387  [[deprecated("Use the form that takes Name instead of const "
388  "char*")]] const Element
389  getElement(const char *name) const;
394  const Element getElement(const Name& name) const;
399  const Element asElement() const;
404  const char *getRequestId() const;
416  blpapi_Request_t *handle() const;
417 
418  std::ostream& print(
419  std::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
432 };
433 
437 std::ostream& operator<<(std::ostream& stream, const Request& request);
450 class RequestRef {
451  Request *d_request_p;
452 
453  public:
454  RequestRef(Request *request_p);
455  Request *ptr() const;
456  Request *operator->() const;
457 };
458 
459 //=============================================================================
460 // INLINE FUNCTION DEFINITIONS
461 //=============================================================================
462 
463 // -------------
464 // class Request
465 // -------------
466 
468 {
469  d_handle = newHandle;
470  if (newHandle) {
471  d_elements.rebind(blpapi_Request_elements(newHandle));
472  }
473 }
474 
476 {
477  Request *src = ref.ptr();
478  assert(src);
479  d_handle = src->d_handle;
480  d_elements = src->d_elements;
481  src->d_handle = 0;
482  src->d_elements.rebind(0);
483 }
484 
486 {
487  d_handle = src.d_handle;
488  d_elements = src.d_elements;
489  src.d_handle = 0;
490  src.d_elements.rebind(0);
491 }
492 
494 {
495  if (d_handle) {
496  blpapi_Request_destroy(d_handle);
497  }
498 }
499 
500 inline Request::operator RequestRef() { return RequestRef(this); }
501 
502 inline void Request::set(const char *element, bool value)
503 {
504  d_elements.setElement(Name(element), value);
505 }
506 
507 inline void Request::set(const char *element, char value)
508 {
509  d_elements.setElement(Name(element), value);
510 }
511 
512 inline void Request::set(const char *element, Int32 value)
513 {
514  d_elements.setElement(Name(element), value);
515 }
516 
517 inline void Request::set(const char *element, Int64 value)
518 {
519  d_elements.setElement(Name(element), value);
520 }
521 
522 inline void Request::set(const char *element, Float32 value)
523 {
524  d_elements.setElement(Name(element), value);
525 }
526 
527 inline void Request::set(const char *element, Float64 value)
528 {
529  d_elements.setElement(Name(element), value);
530 }
531 
532 inline void Request::set(const char *element, const Datetime& value)
533 {
534  d_elements.setElement(Name(element), value);
535 }
536 
537 inline void Request::set(const char *element, const char *value)
538 {
539  d_elements.setElement(Name(element), value);
540 }
541 
542 inline void Request::append(const char *element, bool value)
543 {
544  Element namedElement = d_elements.getElement(Name(element));
545  namedElement.appendValue(value);
546 }
547 
548 inline void Request::append(const char *element, char value)
549 {
550  Element namedElement = d_elements.getElement(Name(element));
551  namedElement.appendValue(value);
552 }
553 
554 inline void Request::append(const char *element, Int32 value)
555 {
556  Element namedElement = d_elements.getElement(Name(element));
557  namedElement.appendValue(value);
558 }
559 
560 inline void Request::append(const char *element, Int64 value)
561 {
562  Element namedElement = d_elements.getElement(Name(element));
563  namedElement.appendValue(value);
564 }
565 
566 inline void Request::append(const char *element, Float32 value)
567 {
568  Element namedElement = d_elements.getElement(Name(element));
569  namedElement.appendValue(value);
570 }
571 
572 inline void Request::append(const char *element, Float64 value)
573 {
574  Element namedElement = d_elements.getElement(Name(element));
575  namedElement.appendValue(value);
576 }
577 
578 inline void Request::append(const char *element, const Datetime& value)
579 {
580  Element namedElement = d_elements.getElement(Name(element));
581  namedElement.appendValue(value);
582 }
583 
584 inline void Request::append(const char *element, const char *value)
585 {
586  Element namedElement = d_elements.getElement(Name(element));
587  namedElement.appendValue(value);
588 }
589 
590 inline void Request::set(const Name& element, bool value)
591 {
592  d_elements.setElement(element, value);
593 }
594 
595 inline void Request::set(const Name& element, char value)
596 {
597  d_elements.setElement(element, value);
598 }
599 
600 inline void Request::set(const Name& element, Int32 value)
601 {
602  d_elements.setElement(element, value);
603 }
604 
605 inline void Request::set(const Name& element, Int64 value)
606 {
607  d_elements.setElement(element, value);
608 }
609 
610 inline void Request::set(const Name& element, Float32 value)
611 {
612  d_elements.setElement(element, value);
613 }
614 
615 inline void Request::set(const Name& element, Float64 value)
616 {
617  d_elements.setElement(element, value);
618 }
619 
620 inline void Request::set(const Name& element, const Datetime& value)
621 {
622  d_elements.setElement(element, value);
623 }
624 
625 inline void Request::set(const Name& element, const char *value)
626 {
627  d_elements.setElement(element, value);
628 }
629 
630 inline void Request::set(const Name& element, const std::string& value)
631 {
632  d_elements.setElement(element, value);
633 }
634 
635 inline void Request::set(
636  const Name& element, const void *value, std::size_t length)
637 {
638  d_elements.setElement(element, value, length);
639 }
640 
641 template <typename BYTES,
642  typename std::enable_if<IsByteSequence<BYTES>::value, bool>::type>
643 inline void Request::set(const Name& element, const BYTES& value)
644 {
645  d_elements.setElement(element, value);
646 }
647 
648 inline void Request::append(const Name& element, bool value)
649 {
650  Element namedElement = d_elements.getElement(element);
651  namedElement.appendValue(value);
652 }
653 
654 inline void Request::append(const Name& element, char value)
655 {
656  Element namedElement = d_elements.getElement(element);
657  namedElement.appendValue(value);
658 }
659 
660 inline void Request::append(const Name& element, Int32 value)
661 {
662  Element namedElement = d_elements.getElement(element);
663  namedElement.appendValue(value);
664 }
665 
666 inline void Request::append(const Name& element, Int64 value)
667 {
668  Element namedElement = d_elements.getElement(element);
669  namedElement.appendValue(value);
670 }
671 
672 inline void Request::append(const Name& element, Float32 value)
673 {
674  Element namedElement = d_elements.getElement(element);
675  namedElement.appendValue(value);
676 }
677 
678 inline void Request::append(const Name& element, Float64 value)
679 {
680  Element namedElement = d_elements.getElement(element);
681  namedElement.appendValue(value);
682 }
683 
684 inline void Request::append(const Name& element, const Datetime& value)
685 {
686  Element namedElement = d_elements.getElement(element);
687  namedElement.appendValue(value);
688 }
689 
690 inline void Request::append(const Name& element, const char *value)
691 {
692  Element namedElement = d_elements.getElement(element);
693  namedElement.appendValue(value);
694 }
695 
696 inline void Request::append(const Name& element, const std::string& value)
697 {
698  Element namedElement = d_elements.getElement(element);
699  namedElement.appendValue(value);
700 }
701 
702 inline Element Request::getElement(const char *name)
703 {
704  return d_elements.getElement(Name(name));
705 }
706 
707 inline Element Request::getElement(const Name& name)
708 {
709  return d_elements.getElement(name);
710 }
711 
712 inline Element Request::asElement() { return d_elements; }
713 
714 inline const Element Request::getElement(const char *name) const
715 {
716  return d_elements.getElement(Name(name));
717 }
718 
719 inline const Element Request::getElement(const Name& name) const
720 {
721  return d_elements.getElement(name);
722 }
723 
724 inline const Element Request::asElement() const { return d_elements; }
725 
726 inline const char *Request::getRequestId() const
727 {
728  const char *requestId = 0;
729  BLPAPI_CALL(blpapi_Request_getRequestId)(d_handle, &requestId);
730  return requestId;
731 }
732 
733 inline blpapi_Request_t *Request::handle() const { return d_handle; }
734 
735 inline std::ostream& Request::print(
736  std::ostream& stream, int level, int spacesPerLevel) const
737 {
738  return d_elements.print(stream, level, spacesPerLevel);
739 }
740 
741 inline std::ostream& operator<<(std::ostream& stream, const Request& request)
742 {
743  return request.print(stream, 0, -1);
744 }
745 // ----------------
746 // class RequestRef
747 // ----------------
748 
750  : d_request_p(request)
751 {
752 }
753 
754 inline Request *RequestRef::ptr() const { return this->d_request_p; }
755 
756 inline Request *RequestRef::operator->() const { return this->d_request_p; }
757 
758 } // close namespace blpapi
759 } // close namespace BloombergLP
760 
761 #endif // #ifdef __cplusplus
762 
763 #endif // #ifndef INCLUDED_BLPAPI_REQUEST
Request * operator->() const
Definition: blpapi_request.h:756
RequestRef(Request *request_p)
Definition: blpapi_request.h:749
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition: blpapi_request.h:735
struct blpapi_Element blpapi_Element_t
Definition: blpapi_types.h:136
blpapi_Request_t * handle() const
Definition: blpapi_request.h:733
struct blpapi_Request blpapi_Request_t
Definition: blpapi_request.h:68
Element getElement(const char *name)
Definition: blpapi_request.h:702
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:712
void appendValue(bool value)
Definition: blpapi_element.h:1830
void set(const char *name, bool value)
Definition: blpapi_request.h:502
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
Provide a key to identify individual subscriptions or requests.
Definition: blpapi_request.h:146
Definition: blpapi_element.h:464
Definition: blpapi_request.h:450
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:726
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:1922
void setElement(const char *name, bool value)
Definition: blpapi_element.h:1619
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:2339
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
~Request()
Definition: blpapi_request.h:493
Definition: blpapi_datetime.h:245
void append(const char *name, bool value)
Definition: blpapi_request.h:542
Provide BLPAPI types.
Request(blpapi_Request_t *handle)
Definition: blpapi_request.h:467
int blpapi_Request_getRequestId(const blpapi_Request_t *request, const char **requestId)
Request * ptr() const
Definition: blpapi_request.h:754
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:1614