BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_SUBSCRIPTIONLIST
37#define INCLUDED_BLPAPI_SUBSCRIPTIONLIST
38
208
209#include <blpapi_call.h>
210#include <blpapi_correlationid.h>
211#include <blpapi_defs.h>
212#include <blpapi_deprecate.h>
213#include <blpapi_exception.h>
214#include <blpapi_types.h>
215#include <stddef.h>
216
217struct blpapi_SubscriptionList;
218#ifdef __cplusplus
219extern "C" {
220#endif
221
223typedef struct blpapi_SubscriptionList blpapi_SubscriptionList_t;
224
228
229BLPAPI_EXPORT
230blpapi_SubscriptionList_t *blpapi_SubscriptionList_create(void);
231
232BLPAPI_EXPORT
233void blpapi_SubscriptionList_destroy(blpapi_SubscriptionList_t *list);
234
235BLPAPI_EXPORT
236int blpapi_SubscriptionList_add(blpapi_SubscriptionList_t *list,
237 const char *subscriptionString,
238 const blpapi_CorrelationId_t *correlationId,
239 const char **fields,
240 const char **options,
241 size_t numfields,
242 size_t numOptions);
243
244BLPAPI_EXPORT
245int blpapi_SubscriptionList_addResolved(blpapi_SubscriptionList_t *list,
246 const char *subscriptionString,
247 const blpapi_CorrelationId_t *correlationId);
248
249BLPAPI_EXPORT
250int blpapi_SubscriptionList_clear(blpapi_SubscriptionList_t *list);
251
252BLPAPI_EXPORT
253int blpapi_SubscriptionList_append(
254 blpapi_SubscriptionList_t *dest, const blpapi_SubscriptionList_t *src);
255
256BLPAPI_EXPORT
257int blpapi_SubscriptionList_size(const blpapi_SubscriptionList_t *list);
258
259BLPAPI_EXPORT
260int blpapi_SubscriptionList_correlationIdAt(
261 const blpapi_SubscriptionList_t *list,
262 blpapi_CorrelationId_t *result,
263 size_t index);
264
265BLPAPI_EXPORT
266int blpapi_SubscriptionList_topicStringAt(
267 blpapi_SubscriptionList_t *list, const char **result, size_t index);
268
269BLPAPI_EXPORT
270int blpapi_SubscriptionList_isResolvedAt(
271 blpapi_SubscriptionList_t *list, int *result, size_t index);
272
275
276#ifdef __cplusplus
277}
278
279#ifndef INCLUDED_CSTRING
280#include <cstring>
281#define INCLUDED_CSTRING
282#endif
283
284#ifndef INCLUDED_STRING
285#include <string>
286#define INCLUDED_STRING
287#endif
288
289#ifndef INCLUDED_VECTOR
290#include <vector>
291#define INCLUDED_VECTOR
292#endif
293
300
301namespace BloombergLP {
302namespace blpapi {
303
304// ======================
305// class SubscriptionList
306// ======================
307
317
318 blpapi_SubscriptionList_t *d_handle_p;
319
320 public:
325 SubscriptionList(const SubscriptionList& original);
330
335
336 // MANIPULATORS
337
338 int add(const char *subscriptionString);
347
348 int add(const char *subscriptionString,
349 const CorrelationId& correlationId);
358
359 int add(const char *subscriptionWithoutOptions,
360 const std::vector<std::string>& fields,
361 const std::vector<std::string>& options,
362 const CorrelationId& correlationId);
369
370 int add(const char *subscriptionWithoutOptions,
371 const char *fields,
372 const char *options,
373 const CorrelationId& correlationId);
381
382 int add(const CorrelationId& correlationId);
389
390 BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(
391 const char *subscriptionString);
407
408 BLPAPI_DEPRECATE_PRERESOLVED_TOPICS int addResolved(
409 const char *subscriptionString,
410 const CorrelationId& correlationId);
426
427 int append(const SubscriptionList& other);
435
436 void clear();
440
449
450 // ACCESSORS
451
452 size_t size() const;
456
457 CorrelationId correlationIdAt(size_t index) const;
463
464 const char *topicStringAt(size_t index) const;
473
474 BLPAPI_DEPRECATE_PRERESOLVED_TOPICS bool isResolvedTopicAt(
475 size_t index) const;
486
488 const blpapi_SubscriptionList_t *impl() const;
490};
491
494
495// ============================================================================
496// INLINE FUNCTION DEFINITIONS
497// ============================================================================
498
499// ----------------------
500// class SubscriptionList
501// ----------------------
503 : d_handle_p(blpapi_SubscriptionList_create())
504{
505}
506
508 : d_handle_p(blpapi_SubscriptionList_create())
509{
510 blpapi_SubscriptionList_append(d_handle_p, original.d_handle_p);
511}
512
514{
515 blpapi_SubscriptionList_destroy(d_handle_p);
516}
517
518inline int SubscriptionList::add(const char *subscriptionString)
519{
520 blpapi_CorrelationId_t correlationId;
521 std::memset(&correlationId, 0, sizeof(correlationId));
522 return blpapi_SubscriptionList_add(
523 d_handle_p, subscriptionString, &correlationId, 0, 0, 0, 0);
524}
525
527 const char *subscriptionString, const CorrelationId& correlationId)
528{
529 return blpapi_SubscriptionList_add(
530 d_handle_p, subscriptionString, &correlationId.impl(), 0, 0, 0, 0);
531}
532
533inline int SubscriptionList::add(const char *subscriptionString,
534 const std::vector<std::string>& fields,
535 const std::vector<std::string>& options,
536 const CorrelationId& correlationId)
537{
538 std::vector<const char *> tmpVector;
539 const char *arena[256];
540 const char **tmpArray = arena;
541 size_t sizeNeeded = fields.size() + options.size();
542
543 if (sizeNeeded > sizeof(arena) / sizeof(arena[0])) {
544 tmpVector.resize(sizeNeeded);
545 tmpArray = &tmpVector[0];
546 }
547
548 const char **p = tmpArray;
549 for (std::vector<std::string>::const_iterator itr = fields.begin(),
550 end = fields.end();
551 itr != end;
552 ++itr, ++p) {
553 *p = itr->c_str();
554 }
555
556 for (std::vector<std::string>::const_iterator itr = options.begin(),
557 end = options.end();
558 itr != end;
559 ++itr, ++p) {
560 *p = itr->c_str();
561 }
562
563 return blpapi_SubscriptionList_add(d_handle_p,
564 subscriptionString,
565 &correlationId.impl(),
566 tmpArray,
567 tmpArray + fields.size(),
568 fields.size(),
569 options.size());
570}
571
572inline int SubscriptionList::add(const char *subscriptionString,
573 const char *fields,
574 const char *options,
575 const CorrelationId& correlationId)
576{
577 return blpapi_SubscriptionList_add(d_handle_p,
578 subscriptionString,
579 &correlationId.impl(),
580 &fields,
581 &options,
582 fields ? 1u : 0u,
583 options ? 1u : 0u);
584}
585
586inline int SubscriptionList::add(const CorrelationId& correlationId)
587{
588 return blpapi_SubscriptionList_add(
589 d_handle_p, "", &correlationId.impl(), 0, 0, 0, 0);
590}
591
592inline int SubscriptionList::addResolved(const char *subscriptionString)
593{
594 blpapi_CorrelationId_t correlationId;
595 std::memset(&correlationId, 0, sizeof(correlationId));
597 d_handle_p, subscriptionString, &correlationId);
598}
599
601 const char *subscriptionString, const CorrelationId& correlationId)
602{
604 d_handle_p, subscriptionString, &correlationId.impl());
605}
606
608{
609 return blpapi_SubscriptionList_append(d_handle_p, other.d_handle_p);
610}
611
613{
614 blpapi_SubscriptionList_clear(d_handle_p);
615}
616
618 const SubscriptionList& rhs)
619{
620 if (d_handle_p != rhs.d_handle_p) {
621 blpapi_SubscriptionList_clear(d_handle_p);
622 blpapi_SubscriptionList_append(d_handle_p, rhs.d_handle_p);
623 }
624 return *this;
625}
626
627inline size_t SubscriptionList::size() const
628{
629 return static_cast<size_t>(blpapi_SubscriptionList_size(d_handle_p));
630}
631
633{
634 blpapi_CorrelationId_t correlationId;
635
636 ExceptionUtil::throwOnError(blpapi_SubscriptionList_correlationIdAt(
637 d_handle_p, &correlationId, index));
638
639 return CorrelationId(correlationId);
640}
641
642inline const char *SubscriptionList::topicStringAt(size_t index) const
643{
644 const char *result = 0;
645
647 blpapi_SubscriptionList_topicStringAt(d_handle_p, &result, index));
648
649 return result;
650}
651
652inline bool SubscriptionList::isResolvedTopicAt(size_t index) const
653{
654 int result = 0;
655
657 d_handle_p, &result, index));
658
659 return result ? true : false;
660}
661
662inline const blpapi_SubscriptionList_t *SubscriptionList::impl() const
663{
664 return d_handle_p;
665}
666
667} // close package namespace
668} // close enterprise namespace
669
670#endif // ifdef __cplusplus
671
672#endif // #ifndef INCLUDED_BLPAPI_SUBSCRIPTIONLIST
Provide functions for dispatchtbl.
#define BLPAPI_CALL_SUBSCRIPTIONLIST_ADDRESOLVED(a1, a2, a3)
Definition blpapi_call.h:423
#define BLPAPI_CALL_SUBSCRIPTIONLIST_ISRESOLVEDAT(a1, a2, a3)
Definition blpapi_call.h:425
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:225
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
const char * topicStringAt(size_t index) const
Definition blpapi_subscriptionlist.h:642
size_t size() const
Definition blpapi_subscriptionlist.h:627
SubscriptionList()
Definition blpapi_subscriptionlist.h:502
SubscriptionList & operator=(const SubscriptionList &rhs)
Definition blpapi_subscriptionlist.h:617
~SubscriptionList()
Definition blpapi_subscriptionlist.h:513
int append(const SubscriptionList &other)
Definition blpapi_subscriptionlist.h:607
CorrelationId correlationIdAt(size_t index) const
Definition blpapi_subscriptionlist.h:632
int addResolved(const char *subscriptionString)
Definition blpapi_subscriptionlist.h:592
int add(const char *subscriptionString)
Definition blpapi_subscriptionlist.h:518
void clear()
Definition blpapi_subscriptionlist.h:612
bool isResolvedTopicAt(size_t index) const
Definition blpapi_subscriptionlist.h:652
Definition blpapi_abstractsession.h:211