BLPAPI C++  3.25.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
blpapi_subscriptionlist.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_SUBSCRIPTIONLIST
29 #define INCLUDED_BLPAPI_SUBSCRIPTIONLIST
30 
201 #include <blpapi_call.h>
202 #include <blpapi_correlationid.h>
203 #include <blpapi_defs.h>
204 #include <blpapi_deprecate.h>
205 #include <blpapi_exception.h>
206 #include <blpapi_types.h>
207 #include <stddef.h>
208 
209 struct blpapi_SubscriptionList;
210 typedef struct blpapi_SubscriptionList blpapi_SubscriptionList_t;
211 
212 #ifdef __cplusplus
213 extern "C" {
214 #endif
215 
218 
221 
224  const char *subscriptionString,
225  const blpapi_CorrelationId_t *correlationId,
226  const char **fields,
227  const char **options,
228  size_t numfields,
229  size_t numOptions);
230 
233  const char *subscriptionString,
234  const blpapi_CorrelationId_t *correlationId);
235 
238 
242 
245 
248  const blpapi_SubscriptionList_t *list,
249  blpapi_CorrelationId_t *result,
250  size_t index);
251 
254  blpapi_SubscriptionList_t *list, const char **result, size_t index);
255 
258  blpapi_SubscriptionList_t *list, int *result, size_t index);
259 
260 #ifdef __cplusplus
261 }
262 
263 #ifndef INCLUDED_CSTRING
264 #include <cstring>
265 #define INCLUDED_CSTRING
266 #endif
267 
268 #ifndef INCLUDED_STRING
269 #include <string>
270 #define INCLUDED_STRING
271 #endif
272 
273 #ifndef INCLUDED_VECTOR
274 #include <vector>
275 #define INCLUDED_VECTOR
276 #endif
277 
285 namespace BloombergLP {
286 namespace blpapi {
287 
288 // ======================
289 // class SubscriptionList
290 // ======================
291 
301 
302  blpapi_SubscriptionList_t *d_handle_p;
303 
304  public:
309  SubscriptionList(const SubscriptionList& original);
320  // MANIPULATORS
321 
322  int add(const char *subscriptionString);
334  int add(const char *subscriptionString,
335  const CorrelationId& correlationId);
347  int add(const char *subscriptionWithoutOptions,
348  const std::vector<std::string>& fields,
349  const std::vector<std::string>& options,
350  const CorrelationId& correlationId);
358  int add(const char *subscriptionWithoutOptions,
359  const char *fields,
360  const char *options,
361  const CorrelationId& correlationId);
370  int add(const CorrelationId& correlationId);
378  BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(
379  const char *subscriptionString);
396  BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(
397  const char *subscriptionString,
398  const CorrelationId& correlationId);
415  int append(const SubscriptionList& other);
424  void clear();
438  // ACCESSORS
439 
440  size_t size() const;
445  CorrelationId correlationIdAt(size_t index) const;
452  const char *topicStringAt(size_t index) const;
462  BLPAPI_DEPRECATE_PRERESOLVED_TOPICS bool isResolvedTopicAt(
463  size_t index) const;
475  const blpapi_SubscriptionList_t *impl() const;
478 };
479 
483 // ============================================================================
484 // INLINE FUNCTION DEFINITIONS
485 // ============================================================================
486 
487 // ----------------------
488 // class SubscriptionList
489 // ----------------------
491  : d_handle_p(blpapi_SubscriptionList_create())
492 {
493 }
494 
496  : d_handle_p(blpapi_SubscriptionList_create())
497 {
498  blpapi_SubscriptionList_append(d_handle_p, original.d_handle_p);
499 }
500 
502 {
504 }
505 
506 inline int SubscriptionList::add(const char *subscriptionString)
507 {
508  blpapi_CorrelationId_t correlationId;
509  std::memset(&correlationId, 0, sizeof(correlationId));
511  d_handle_p, subscriptionString, &correlationId, 0, 0, 0, 0);
512 }
513 
515  const char *subscriptionString, const CorrelationId& correlationId)
516 {
518  d_handle_p, subscriptionString, &correlationId.impl(), 0, 0, 0, 0);
519 }
520 
521 inline int SubscriptionList::add(const char *subscriptionString,
522  const std::vector<std::string>& fields,
523  const std::vector<std::string>& options,
524  const CorrelationId& correlationId)
525 {
526  std::vector<const char *> tmpVector;
527  const char *arena[256];
528  const char **tmpArray = arena;
529  size_t sizeNeeded = fields.size() + options.size();
530 
531  if (sizeNeeded > sizeof(arena) / sizeof(arena[0])) {
532  tmpVector.resize(sizeNeeded);
533  tmpArray = &tmpVector[0];
534  }
535 
536  const char **p = tmpArray;
537  for (std::vector<std::string>::const_iterator itr = fields.begin(),
538  end = fields.end();
539  itr != end;
540  ++itr, ++p) {
541  *p = itr->c_str();
542  }
543 
544  for (std::vector<std::string>::const_iterator itr = options.begin(),
545  end = options.end();
546  itr != end;
547  ++itr, ++p) {
548  *p = itr->c_str();
549  }
550 
551  return blpapi_SubscriptionList_add(d_handle_p,
552  subscriptionString,
553  &correlationId.impl(),
554  tmpArray,
555  tmpArray + fields.size(),
556  fields.size(),
557  options.size());
558 }
559 
560 inline int SubscriptionList::add(const char *subscriptionString,
561  const char *fields,
562  const char *options,
563  const CorrelationId& correlationId)
564 {
565  return blpapi_SubscriptionList_add(d_handle_p,
566  subscriptionString,
567  &correlationId.impl(),
568  &fields,
569  &options,
570  fields ? 1u : 0u,
571  options ? 1u : 0u);
572 }
573 
574 inline int SubscriptionList::add(const CorrelationId& correlationId)
575 {
577  d_handle_p, "", &correlationId.impl(), 0, 0, 0, 0);
578 }
579 
580 inline int SubscriptionList::addResolved(const char *subscriptionString)
581 {
582  blpapi_CorrelationId_t correlationId;
583  std::memset(&correlationId, 0, sizeof(correlationId));
585  d_handle_p, subscriptionString, &correlationId);
586 }
587 
589  const char *subscriptionString, const CorrelationId& correlationId)
590 {
592  d_handle_p, subscriptionString, &correlationId.impl());
593 }
594 
596 {
597  return blpapi_SubscriptionList_append(d_handle_p, other.d_handle_p);
598 }
599 
601 {
602  blpapi_SubscriptionList_clear(d_handle_p);
603 }
604 
606  const SubscriptionList& rhs)
607 {
608  if (d_handle_p != rhs.d_handle_p) {
609  blpapi_SubscriptionList_clear(d_handle_p);
610  blpapi_SubscriptionList_append(d_handle_p, rhs.d_handle_p);
611  }
612  return *this;
613 }
614 
615 inline size_t SubscriptionList::size() const
616 {
617  return static_cast<size_t>(blpapi_SubscriptionList_size(d_handle_p));
618 }
619 
621 {
622  blpapi_CorrelationId_t correlationId;
623 
625  d_handle_p, &correlationId, index));
626 
627  return CorrelationId(correlationId);
628 }
629 
630 inline const char *SubscriptionList::topicStringAt(size_t index) const
631 {
632  const char *result = 0;
633 
635  blpapi_SubscriptionList_topicStringAt(d_handle_p, &result, index));
636 
637  return result;
638 }
639 
640 inline bool SubscriptionList::isResolvedTopicAt(size_t index) const
641 {
642  int result = 0;
643 
645  d_handle_p, &result, index));
646 
647  return result ? true : false;
648 }
649 
650 inline const blpapi_SubscriptionList_t *SubscriptionList::impl() const
651 {
652  return d_handle_p;
653 }
654 
655 } // close package namespace
656 } // close enterprise namespace
657 
658 #endif // ifdef __cplusplus
659 
660 #endif // #ifndef INCLUDED_BLPAPI_SUBSCRIPTIONLIST
~SubscriptionList()
Definition: blpapi_subscriptionlist.h:501
int blpapi_SubscriptionList_topicStringAt(blpapi_SubscriptionList_t *list, const char **result, size_t index)
Common definitions used by the library.
int add(const char *subscriptionString)
Definition: blpapi_subscriptionlist.h:506
Definition: blpapi_abstractsession.h:195
int blpapi_SubscriptionList_size(const blpapi_SubscriptionList_t *list)
void blpapi_SubscriptionList_destroy(blpapi_SubscriptionList_t *list)
int blpapi_SubscriptionList_clear(blpapi_SubscriptionList_t *list)
SubscriptionList()
Definition: blpapi_subscriptionlist.h:490
Provide a key to identify individual subscriptions or requests.
void clear()
Definition: blpapi_subscriptionlist.h:600
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
struct blpapi_SubscriptionList blpapi_SubscriptionList_t
Definition: blpapi_dispatchtbl.h:90
BLPAPI_DEPRECATE_PRERESOLVED_TOPICS bool isResolvedTopicAt(size_t index) const
Definition: blpapi_subscriptionlist.h:640
BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(const char *subscriptionString)
Definition: blpapi_subscriptionlist.h:580
Definition: blpapi_correlationid.h:201
Definition: blpapi_subscriptionlist.h:300
#define BLPAPI_CALL_SUBSCRIPTIONLIST_ADDRESOLVED(a1, a2, a3)
Definition: blpapi_call.h:415
size_t size() const
Definition: blpapi_subscriptionlist.h:615
#define BLPAPI_CALL_SUBSCRIPTIONLIST_ISRESOLVEDAT(a1, a2, a3)
Definition: blpapi_call.h:417
SubscriptionList & operator=(const SubscriptionList &rhs)
Definition: blpapi_subscriptionlist.h:605
int blpapi_SubscriptionList_correlationIdAt(const blpapi_SubscriptionList_t *list, blpapi_CorrelationId_t *result, size_t index)
int blpapi_SubscriptionList_isResolvedAt(blpapi_SubscriptionList_t *list, int *result, size_t index)
int append(const SubscriptionList &other)
Definition: blpapi_subscriptionlist.h:595
Defines Exceptions that can be thrown by the blpapi library.
CorrelationId correlationIdAt(size_t index) const
Definition: blpapi_subscriptionlist.h:620
blpapi_SubscriptionList_t * blpapi_SubscriptionList_create(void)
int blpapi_SubscriptionList_addResolved(blpapi_SubscriptionList_t *list, const char *subscriptionString, const blpapi_CorrelationId_t *correlationId)
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
Provide functions for dispatchtbl.
Provide BLPAPI types.
int blpapi_SubscriptionList_append(blpapi_SubscriptionList_t *dest, const blpapi_SubscriptionList_t *src)
const char * topicStringAt(size_t index) const
Definition: blpapi_subscriptionlist.h:630
int blpapi_SubscriptionList_add(blpapi_SubscriptionList_t *list, const char *subscriptionString, const blpapi_CorrelationId_t *correlationId, const char **fields, const char **options, size_t numfields, size_t numOptions)