BLPAPI C++  3.20.6
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 #ifndef INCLUDED_BLPAPI_CALL
202 #include <blpapi_call.h>
203 #endif
204 
205 #ifndef INCLUDED_BLPAPI_CORRELATIONID
206 #include <blpapi_correlationid.h>
207 #endif
208 
209 #ifndef INCLUDED_BLPAPI_DEFS
210 #include <blpapi_defs.h>
211 #endif
212 
213 #ifndef INCLUDED_BLPAPI_EXCEPTION
214 #include <blpapi_exception.h>
215 #endif
216 
217 #ifndef INCLUDED_BLPAPI_TYPES
218 #include <blpapi_types.h>
219 #endif
220 
221 #include <stddef.h>
222 
223 struct blpapi_SubscriptionList;
224 typedef struct blpapi_SubscriptionList blpapi_SubscriptionList_t;
225 
226 #ifdef __cplusplus
227 extern "C" {
228 #endif
229 
232 
235 
238  const char *subscriptionString,
239  const blpapi_CorrelationId_t *correlationId,
240  const char **fields,
241  const char **options,
242  size_t numfields,
243  size_t numOptions);
244 
247  const char *subscriptionString,
248  const blpapi_CorrelationId_t *correlationId);
249 
252 
256 
259 
262  const blpapi_SubscriptionList_t *list,
263  blpapi_CorrelationId_t *result,
264  size_t index);
265 
268  blpapi_SubscriptionList_t *list, const char **result, size_t index);
269 
272  blpapi_SubscriptionList_t *list, int *result, size_t index);
273 
274 #ifdef __cplusplus
275 }
276 
277 #ifndef INCLUDED_CSTRING
278 #include <cstring>
279 #define INCLUDED_CSTRING
280 #endif
281 
282 #ifndef INCLUDED_STRING
283 #include <string>
284 #define INCLUDED_STRING
285 #endif
286 
287 #ifndef INCLUDED_VECTOR
288 #include <vector>
289 #define INCLUDED_VECTOR
290 #endif
291 
299 namespace BloombergLP {
300 namespace blpapi {
301 
302 // ======================
303 // class SubscriptionList
304 // ======================
305 
315 
316  blpapi_SubscriptionList_t *d_handle_p;
317 
318  public:
323  SubscriptionList(const SubscriptionList& original);
334  // MANIPULATORS
335 
336  int add(const char *subscriptionString);
348  int add(const char *subscriptionString,
349  const CorrelationId& correlationId);
361  int add(const char *subscriptionWithoutOptions,
362  const std::vector<std::string>& fields,
363  const std::vector<std::string>& options,
364  const CorrelationId& correlationId);
372  int add(const char *subscriptionWithoutOptions,
373  const char *fields,
374  const char *options,
375  const CorrelationId& correlationId);
384  int add(const CorrelationId& correlationId);
392  int addResolved(const char *subscriptionString);
406  int addResolved(const char *subscriptionString,
407  const CorrelationId& correlationId);
421  int append(const SubscriptionList& other);
430  void clear();
444  // ACCESSORS
445 
446  size_t size() const;
451  CorrelationId correlationIdAt(size_t index) const;
458  const char *topicStringAt(size_t index) const;
468  bool isResolvedTopicAt(size_t index) const;
477  const blpapi_SubscriptionList_t *impl() const;
480 };
481 
485 // ============================================================================
486 // INLINE FUNCTION DEFINITIONS
487 // ============================================================================
488 
489 // ----------------------
490 // class SubscriptionList
491 // ----------------------
493  : d_handle_p(blpapi_SubscriptionList_create())
494 {
495 }
496 
498  : d_handle_p(blpapi_SubscriptionList_create())
499 {
500  blpapi_SubscriptionList_append(d_handle_p, original.d_handle_p);
501 }
502 
504 {
506 }
507 
508 inline int SubscriptionList::add(const char *subscriptionString)
509 {
510  blpapi_CorrelationId_t correlationId;
511  std::memset(&correlationId, 0, sizeof(correlationId));
513  d_handle_p, subscriptionString, &correlationId, 0, 0, 0, 0);
514 }
515 
517  const char *subscriptionString, const CorrelationId& correlationId)
518 {
520  d_handle_p, subscriptionString, &correlationId.impl(), 0, 0, 0, 0);
521 }
522 
523 inline int SubscriptionList::add(const char *subscriptionString,
524  const std::vector<std::string>& fields,
525  const std::vector<std::string>& options,
526  const CorrelationId& correlationId)
527 {
528  std::vector<const char *> tmpVector;
529  const char *arena[256];
530  const char **tmpArray = arena;
531  size_t sizeNeeded = fields.size() + options.size();
532 
533  if (sizeNeeded > sizeof(arena) / sizeof(arena[0])) {
534  tmpVector.resize(sizeNeeded);
535  tmpArray = &tmpVector[0];
536  }
537 
538  const char **p = tmpArray;
539  for (std::vector<std::string>::const_iterator itr = fields.begin(),
540  end = fields.end();
541  itr != end;
542  ++itr, ++p) {
543  *p = itr->c_str();
544  }
545 
546  for (std::vector<std::string>::const_iterator itr = options.begin(),
547  end = options.end();
548  itr != end;
549  ++itr, ++p) {
550  *p = itr->c_str();
551  }
552 
553  return blpapi_SubscriptionList_add(d_handle_p,
554  subscriptionString,
555  &correlationId.impl(),
556  tmpArray,
557  tmpArray + fields.size(),
558  fields.size(),
559  options.size());
560 }
561 
562 inline int SubscriptionList::add(const char *subscriptionString,
563  const char *fields,
564  const char *options,
565  const CorrelationId& correlationId)
566 {
567  return blpapi_SubscriptionList_add(d_handle_p,
568  subscriptionString,
569  &correlationId.impl(),
570  &fields,
571  &options,
572  fields ? 1u : 0u,
573  options ? 1u : 0u);
574 }
575 
576 inline int SubscriptionList::add(const CorrelationId& correlationId)
577 {
579  d_handle_p, "", &correlationId.impl(), 0, 0, 0, 0);
580 }
581 
582 inline int SubscriptionList::addResolved(const char *subscriptionString)
583 {
584  blpapi_CorrelationId_t correlationId;
585  std::memset(&correlationId, 0, sizeof(correlationId));
587  d_handle_p, subscriptionString, &correlationId);
588 }
589 
591  const char *subscriptionString, const CorrelationId& correlationId)
592 {
594  d_handle_p, subscriptionString, &correlationId.impl());
595 }
596 
598 {
599  return blpapi_SubscriptionList_append(d_handle_p, other.d_handle_p);
600 }
601 
603 {
604  blpapi_SubscriptionList_clear(d_handle_p);
605 }
606 
608  const SubscriptionList& rhs)
609 {
610  if (d_handle_p != rhs.d_handle_p) {
611  blpapi_SubscriptionList_clear(d_handle_p);
612  blpapi_SubscriptionList_append(d_handle_p, rhs.d_handle_p);
613  }
614  return *this;
615 }
616 
617 inline size_t SubscriptionList::size() const
618 {
619  return static_cast<size_t>(blpapi_SubscriptionList_size(d_handle_p));
620 }
621 
623 {
624  blpapi_CorrelationId_t correlationId;
625 
627  d_handle_p, &correlationId, index));
628 
629  return CorrelationId(correlationId);
630 }
631 
632 inline const char *SubscriptionList::topicStringAt(size_t index) const
633 {
634  const char *result = 0;
635 
637  blpapi_SubscriptionList_topicStringAt(d_handle_p, &result, index));
638 
639  return result;
640 }
641 
642 inline bool SubscriptionList::isResolvedTopicAt(size_t index) const
643 {
644  int result = 0;
645 
647  d_handle_p, &result, index));
648 
649  return result ? true : false;
650 }
651 
652 inline const blpapi_SubscriptionList_t *SubscriptionList::impl() const
653 {
654  return d_handle_p;
655 }
656 
657 } // close package namespace
658 } // close enterprise namespace
659 
660 #endif // ifdef __cplusplus
661 
662 #endif // #ifndef INCLUDED_BLPAPI_SUBSCRIPTIONLIST
struct blpapi_SubscriptionList blpapi_SubscriptionList_t
Definition: blpapi_subscriptionlist.h:224
~SubscriptionList()
Definition: blpapi_subscriptionlist.h:503
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:508
Definition: blpapi_abstractsession.h:215
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:492
Provide a key to identify individual subscriptions or requests.
void clear()
Definition: blpapi_subscriptionlist.h:602
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
bool isResolvedTopicAt(size_t index) const
Definition: blpapi_subscriptionlist.h:642
int addResolved(const char *subscriptionString)
Definition: blpapi_subscriptionlist.h:582
Definition: blpapi_correlationid.h:201
Definition: blpapi_subscriptionlist.h:314
#define BLPAPI_CALL_SUBSCRIPTIONLIST_ADDRESOLVED(a1, a2, a3)
Definition: blpapi_call.h:415
size_t size() const
Definition: blpapi_subscriptionlist.h:617
#define BLPAPI_CALL_SUBSCRIPTIONLIST_ISRESOLVEDAT(a1, a2, a3)
Definition: blpapi_call.h:417
SubscriptionList & operator=(const SubscriptionList &rhs)
Definition: blpapi_subscriptionlist.h:607
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:597
Defines Exceptions that can be thrown by the blpapi library.
CorrelationId correlationIdAt(size_t index) const
Definition: blpapi_subscriptionlist.h:622
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:632
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)