BLPAPI C++ 3.26.6
Loading...
Searching...
No Matches
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
37
38#ifndef INCLUDED_BLPAPI_SUBSCRIPTIONLIST
39#define INCLUDED_BLPAPI_SUBSCRIPTIONLIST
40
199
200#include <blpapi_call.h>
201#include <blpapi_correlationid.h>
202#include <blpapi_defs.h>
203#include <blpapi_deprecate.h>
204#include <blpapi_exception.h>
205#include <blpapi_types.h>
206
207#include <stddef.h>
208
209struct blpapi_SubscriptionList;
210#ifdef __cplusplus
211extern "C" {
212#endif
213
215typedef struct blpapi_SubscriptionList blpapi_SubscriptionList_t;
216
220
227BLPAPI_EXPORT
228blpapi_SubscriptionList_t *blpapi_SubscriptionList_create(void);
229
237BLPAPI_EXPORT
238void blpapi_SubscriptionList_destroy(blpapi_SubscriptionList_t *list);
239
260BLPAPI_EXPORT
261int blpapi_SubscriptionList_add(blpapi_SubscriptionList_t *list,
262 const char *subscriptionString,
263 const blpapi_CorrelationId_t *correlationId,
264 const char **fields,
265 const char **options,
266 size_t numfields,
267 size_t numOptions);
268
286BLPAPI_EXPORT
287int blpapi_SubscriptionList_addResolved(blpapi_SubscriptionList_t *list,
288 const char *subscriptionString,
289 const blpapi_CorrelationId_t *correlationId);
290
299BLPAPI_EXPORT
300int blpapi_SubscriptionList_clear(blpapi_SubscriptionList_t *list);
301
313BLPAPI_EXPORT
314int blpapi_SubscriptionList_append(
315 blpapi_SubscriptionList_t *dest, const blpapi_SubscriptionList_t *src);
316
324BLPAPI_EXPORT
325int blpapi_SubscriptionList_size(const blpapi_SubscriptionList_t *list);
326
339BLPAPI_EXPORT
340int blpapi_SubscriptionList_correlationIdAt(
341 const blpapi_SubscriptionList_t *list,
342 blpapi_CorrelationId_t *result,
343 size_t index);
344
359BLPAPI_EXPORT
360int blpapi_SubscriptionList_topicStringAt(
361 blpapi_SubscriptionList_t *list, const char **result, size_t index);
362
379BLPAPI_EXPORT
380int blpapi_SubscriptionList_isResolvedAt(
381 blpapi_SubscriptionList_t *list, int *result, size_t index);
382
385
386#ifdef __cplusplus
387}
388
389#include <cstring>
390#include <string>
391#include <vector>
392
393namespace BloombergLP {
394namespace blpapi {
401
402// ======================
403// class SubscriptionList
404// ======================
405
415
416 blpapi_SubscriptionList_t *d_handle_p;
417
418 public:
423 SubscriptionList(const SubscriptionList& original);
428
433
434 // MANIPULATORS
435
436 int add(const char *subscriptionString);
445
446 int add(const char *subscriptionString,
447 const CorrelationId& correlationId);
456
457 int add(const char *subscriptionWithoutOptions,
458 const std::vector<std::string>& fields,
459 const std::vector<std::string>& options,
460 const CorrelationId& correlationId);
467
468 int add(const char *subscriptionWithoutOptions,
469 const char *fields,
470 const char *options,
471 const CorrelationId& correlationId);
479
480 int add(const CorrelationId& correlationId);
487
488 BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(
489 const char *subscriptionString);
505
506 BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(
507 const char *subscriptionString,
508 const CorrelationId& correlationId);
524
525 int append(const SubscriptionList& other);
533
534 void clear();
538
547
548 // ACCESSORS
549
550 size_t size() const;
554
555 CorrelationId correlationIdAt(size_t index) const;
561
562 const char *topicStringAt(size_t index) const;
571
572 BLPAPI_DEPRECATE_PRERESOLVED_TOPICS bool isResolvedTopicAt(
573 size_t index) const;
584
586 const blpapi_SubscriptionList_t *impl() const;
588};
589
592
593// ============================================================================
594// INLINE FUNCTION DEFINITIONS
595// ============================================================================
596
597// ----------------------
598// class SubscriptionList
599// ----------------------
601 : d_handle_p(blpapi_SubscriptionList_create())
602{
603}
604
606 : d_handle_p(blpapi_SubscriptionList_create())
607{
608 blpapi_SubscriptionList_append(d_handle_p, original.d_handle_p);
609}
610
612{
613 blpapi_SubscriptionList_destroy(d_handle_p);
614}
615
616inline int SubscriptionList::add(const char *subscriptionString)
617{
618 blpapi_CorrelationId_t correlationId;
619 std::memset(&correlationId, 0, sizeof(correlationId));
620 return blpapi_SubscriptionList_add(
621 d_handle_p, subscriptionString, &correlationId, 0, 0, 0, 0);
622}
623
625 const char *subscriptionString, const CorrelationId& correlationId)
626{
627 return blpapi_SubscriptionList_add(
628 d_handle_p, subscriptionString, &correlationId.impl(), 0, 0, 0, 0);
629}
630
631inline int SubscriptionList::add(const char *subscriptionString,
632 const std::vector<std::string>& fields,
633 const std::vector<std::string>& options,
634 const CorrelationId& correlationId)
635{
636 std::vector<const char *> tmpVector;
637 const char *arena[256];
638 const char **tmpArray = arena;
639 size_t sizeNeeded = fields.size() + options.size();
640
641 if (sizeNeeded > sizeof(arena) / sizeof(arena[0])) {
642 tmpVector.resize(sizeNeeded);
643 tmpArray = &tmpVector[0];
644 }
645
646 const char **p = tmpArray;
647 for (std::vector<std::string>::const_iterator itr = fields.begin(),
648 end = fields.end();
649 itr != end;
650 ++itr, ++p) {
651 *p = itr->c_str();
652 }
653
654 for (std::vector<std::string>::const_iterator itr = options.begin(),
655 end = options.end();
656 itr != end;
657 ++itr, ++p) {
658 *p = itr->c_str();
659 }
660
661 return blpapi_SubscriptionList_add(d_handle_p,
662 subscriptionString,
663 &correlationId.impl(),
664 tmpArray,
665 tmpArray + fields.size(),
666 fields.size(),
667 options.size());
668}
669
670inline int SubscriptionList::add(const char *subscriptionString,
671 const char *fields,
672 const char *options,
673 const CorrelationId& correlationId)
674{
675 return blpapi_SubscriptionList_add(d_handle_p,
676 subscriptionString,
677 &correlationId.impl(),
678 &fields,
679 &options,
680 fields ? 1u : 0u,
681 options ? 1u : 0u);
682}
683
684inline int SubscriptionList::add(const CorrelationId& correlationId)
685{
686 return blpapi_SubscriptionList_add(
687 d_handle_p, "", &correlationId.impl(), 0, 0, 0, 0);
688}
689
690inline int SubscriptionList::addResolved(const char *subscriptionString)
691{
692 blpapi_CorrelationId_t correlationId;
693 std::memset(&correlationId, 0, sizeof(correlationId));
694 return BLPAPI_CALL_SUBSCRIPTIONLIST_ADDRESOLVED(
695 d_handle_p, subscriptionString, &correlationId);
696}
697
699 const char *subscriptionString, const CorrelationId& correlationId)
700{
701 return BLPAPI_CALL_SUBSCRIPTIONLIST_ADDRESOLVED(
702 d_handle_p, subscriptionString, &correlationId.impl());
703}
704
706{
707 return blpapi_SubscriptionList_append(d_handle_p, other.d_handle_p);
708}
709
711{
712 blpapi_SubscriptionList_clear(d_handle_p);
713}
714
716 const SubscriptionList& rhs)
717{
718 if (d_handle_p != rhs.d_handle_p) {
719 blpapi_SubscriptionList_clear(d_handle_p);
720 blpapi_SubscriptionList_append(d_handle_p, rhs.d_handle_p);
721 }
722 return *this;
723}
724
725inline size_t SubscriptionList::size() const
726{
727 return static_cast<size_t>(blpapi_SubscriptionList_size(d_handle_p));
728}
729
731{
732 blpapi_CorrelationId_t correlationId;
733
734 ExceptionUtil::throwOnError(blpapi_SubscriptionList_correlationIdAt(
735 d_handle_p, &correlationId, index));
736
737 return CorrelationId(correlationId);
738}
739
740inline const char *SubscriptionList::topicStringAt(size_t index) const
741{
742 const char *result = 0;
743
745 blpapi_SubscriptionList_topicStringAt(d_handle_p, &result, index));
746
747 return result;
748}
749
750inline bool SubscriptionList::isResolvedTopicAt(size_t index) const
751{
752 int result = 0;
753
754 ExceptionUtil::throwOnError(BLPAPI_CALL_SUBSCRIPTIONLIST_ISRESOLVEDAT(
755 d_handle_p, &result, index));
756
757 return result ? true : false;
758}
759
761inline const blpapi_SubscriptionList_t *SubscriptionList::impl() const
762{
763 return d_handle_p;
764}
766
767} // close package namespace
768} // close enterprise namespace
769
770#endif // ifdef __cplusplus
771
772#endif // #ifndef INCLUDED_BLPAPI_SUBSCRIPTIONLIST
Provide functions for dispatchtbl.
Provide a key to identify individual subscriptions or requests.
Common definitions used by the library.
Defines Exceptions that can be thrown by the blpapi library.
Provide BLPAPI types.
Definition blpapi_correlationid.h:306
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
const char * topicStringAt(size_t index) const
Definition blpapi_subscriptionlist.h:740
size_t size() const
Definition blpapi_subscriptionlist.h:725
SubscriptionList()
Definition blpapi_subscriptionlist.h:600
SubscriptionList & operator=(const SubscriptionList &rhs)
Definition blpapi_subscriptionlist.h:715
~SubscriptionList()
Definition blpapi_subscriptionlist.h:611
int append(const SubscriptionList &other)
Definition blpapi_subscriptionlist.h:705
CorrelationId correlationIdAt(size_t index) const
Definition blpapi_subscriptionlist.h:730
int addResolved(const char *subscriptionString)
Definition blpapi_subscriptionlist.h:690
int add(const char *subscriptionString)
Definition blpapi_subscriptionlist.h:616
void clear()
Definition blpapi_subscriptionlist.h:710
bool isResolvedTopicAt(size_t index) const
Definition blpapi_subscriptionlist.h:750
Definition blpapi_abstractsession.h:452
Definition blpapi_abstractsession.h:451