36#ifndef INCLUDED_BLPAPI_CORRELATIONID
37#define INCLUDED_BLPAPI_CORRELATIONID
83struct blpapi_ManagedPtr_t_;
84typedef struct blpapi_ManagedPtr_t_ blpapi_ManagedPtr_t;
86typedef int (*blpapi_ManagedPtr_ManagerFunction_t)(
87 blpapi_ManagedPtr_t *managedPtr,
88 const blpapi_ManagedPtr_t *srcPtr,
94} blpapi_ManagedPtr_t_data_;
96struct blpapi_ManagedPtr_t_ {
98 blpapi_ManagedPtr_t_data_ userData[4];
99 blpapi_ManagedPtr_ManagerFunction_t manager;
107typedef struct blpapi_CorrelationId_t_ {
108 unsigned int size : 8;
109 unsigned int valueType
111 unsigned int classId : 16;
112 unsigned int internalClassId : 4;
115 blpapi_UInt64_t intValue;
116 blpapi_ManagedPtr_t ptrValue;
118} blpapi_CorrelationId_t;
121int blpapi_CorrelationId_managedPtrAddRef(
122 int *numRef, blpapi_CorrelationId_t *cid);
125int blpapi_CorrelationId_managedPtrRelease(
126 int *numRef, blpapi_CorrelationId_t *cid);
228 e_FOREIGN_OBJECT = BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT
232 blpapi_CorrelationId_t d_impl;
234 void copy(
const blpapi_CorrelationId_t& src,
bool firstCopy);
236 template <
typename TYPE>
237 static int managerFunc(blpapi_ManagedPtr_t *managedPtr,
238 const blpapi_ManagedPtr_t *srcPtr,
242 template <
typename TYPE>
static void assertSmartPtrFits();
277 explicit CorrelationId(
const blpapi_CorrelationId_t& correlation);
303 template <
typename TYPE>
339 unsigned short classId()
const;
368 blpapi_CorrelationId_t& impl();
369 const blpapi_CorrelationId_t& impl()
const;
377inline bool operator==(
const CorrelationId& lhs,
const CorrelationId& rhs);
386inline bool operator!=(
const CorrelationId& lhs,
const CorrelationId& rhs);
391inline bool operator<(
const CorrelationId& lhs,
const CorrelationId& rhs);
412 std::memset(&d_impl, 0,
sizeof(d_impl));
417 const blpapi_CorrelationId_t& correlationId)
419 copy(correlationId,
true);
425 copy(original.d_impl,
false);
430 std::memset(&d_impl, 0,
sizeof(d_impl));
432 d_impl.size =
static_cast<unsigned>(
sizeof(d_impl));
434 d_impl.value.intValue =
static_cast<blpapi_UInt64_t
>(intValue);
435 d_impl.classId =
static_cast<unsigned>(newClassId);
440 std::memset(&d_impl, 0,
sizeof(d_impl));
442 d_impl.size =
static_cast<unsigned>(
sizeof(d_impl));
444 d_impl.value.ptrValue.pointer = ptrValue;
445 d_impl.classId =
static_cast<unsigned>(newClassId);
448template <
typename TYPE>
450 const TYPE& smartPtr,
void *ptrValue,
int newClassId)
455 assertSmartPtrFits<TYPE>();
457 std::memset(&d_impl, 0,
sizeof(d_impl));
459 d_impl.size =
sizeof(d_impl);
461 d_impl.classId = newClassId;
463 d_impl.value.ptrValue.pointer = ptrValue;
464 d_impl.value.ptrValue.manager = &CorrelationId::managerFunc<TYPE>;
466 void *arena = (
void *)d_impl.value.ptrValue.userData;
467 new (arena) TYPE(smartPtr);
473 blpapi_ManagedPtr_ManagerFunction_t& manager
474 = d_impl.value.ptrValue.manager;
477 if (d_impl.internalClassId == e_FOREIGN_OBJECT
479 blpapi_CorrelationId_managedPtrRelease)
481 blpapi_CorrelationId_managedPtrRelease)(
487 manager(&d_impl.value.ptrValue, 0, BLPAPI_MANAGEDPTR_DESTROY);
496 swap(other.d_impl, d_impl);
507inline blpapi_CorrelationId_t& CorrelationId::impl() {
return d_impl; }
519 return d_impl.value.ptrValue.pointer;
524 typedef int (*ManagerFuncPtr)(
525 blpapi_ManagedPtr_t *,
const blpapi_ManagedPtr_t *, int);
527 ManagerFuncPtr managerFnPtr
528 =
static_cast<ManagerFuncPtr
>(&(CorrelationId::managerFunc<TYPE>));
530 || (d_impl.value.ptrValue.manager != managerFnPtr)) {
533 return *(TYPE *)d_impl.value.ptrValue.userData;
538 return static_cast<long long>(d_impl.value.intValue);
542inline const blpapi_CorrelationId_t& CorrelationId::impl()
const
549inline void CorrelationId::copy(
550 const blpapi_CorrelationId_t& src,
bool firstCopy)
555 blpapi_ManagedPtr_ManagerFunction_t& manager
556 = d_impl.value.ptrValue.manager;
558 if (d_impl.internalClassId == e_FOREIGN_OBJECT) {
567 std::memset(&d_impl.value.ptrValue.userData,
569 sizeof(d_impl.value.ptrValue.userData));
573 BLPAPI_CALL(blpapi_CorrelationId_managedPtrAddRef)(
579 manager(&d_impl.value.ptrValue,
581 BLPAPI_MANAGEDPTR_COPY);
588template <
typename TYPE>
589inline int CorrelationId::managerFunc(blpapi_ManagedPtr_t *managedPtr,
590 const blpapi_ManagedPtr_t *srcPtr,
593 if (operation == BLPAPI_MANAGEDPTR_COPY) {
594 managedPtr->pointer = srcPtr->pointer;
595 managedPtr->manager = srcPtr->manager;
597 void *arena = managedPtr->userData;
598 new (arena) TYPE(*((TYPE *)&srcPtr->userData[0]));
599 }
else if (operation == BLPAPI_MANAGEDPTR_DESTROY) {
600 TYPE *managedPtr_p = (TYPE *)&managedPtr->userData[0];
601 managedPtr_p->~TYPE();
602 }
else if (operation == BLPAPI_MANAGEDPTR_IMPOSSIBLE_OPERATION) {
603 static int uniquePerTemplateInstantiation;
605 const int *address = &uniquePerTemplateInstantiation;
607 std::memcpy(&rc, &address, std::min(
sizeof address,
sizeof rc));
624template <
typename TYPE>
inline void CorrelationId::assertSmartPtrFits()
630 char errorIfSmartPtrDoesNotFit[
sizeof(TYPE) <= (
sizeof(
void *) * 4)
633 (void)errorIfSmartPtrDoesNotFit;
645 if (lhs.impl().internalClassId != rhs.impl().internalClassId) {
662 return !(lhs == rhs);
668 && lhs.impl().internalClassId
669 == BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT
671 && rhs.impl().internalClassId
672 == BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT) {
677 return std::memcmp(&lhs.impl(), &rhs.impl(),
sizeof(rhs.impl())) < 0;
683 const char *valueType = 0;
692 valueType =
"POINTER";
695 valueType =
"AUTOGEN";
698 valueType =
"UNKNOWN";
701 os <<
"[ valueType=" << valueType <<
" classId=" << correlator.
classId()
702 <<
" internalClassId=" << correlator.impl().internalClassId
Provide functions for dispatchtbl.
#define BLPAPI_CALL_UNCHECKED(FUNCNAME)
Definition blpapi_call.h:362
#define BLPAPI_CALL_AVAILABLE(FUNCNAME)
Definition blpapi_call.h:360
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
Common definitions used by the library.
Defines Exceptions that can be thrown by the blpapi library.
Definition blpapi_correlationid.h:225
void swap(CorrelationId &other)
Definition blpapi_correlationid.h:492
@ MAX_CLASS_ID
Definition blpapi_correlationid.h:264
unsigned short classId() const
Definition blpapi_correlationid.h:515
ValueType valueType() const
Definition blpapi_correlationid.h:510
void * asPointer() const
Definition blpapi_correlationid.h:517
TYPE asSmartPointer() const
Definition blpapi_correlationid.h:522
~CorrelationId()
Definition blpapi_correlationid.h:470
CorrelationId()
Definition blpapi_correlationid.h:410
long long asInteger() const
Definition blpapi_correlationid.h:536
ValueType
Definition blpapi_correlationid.h:247
@ AUTOGEN_VALUE
The CorrelationId was created internally by API.
Definition blpapi_correlationid.h:257
@ UNSET_VALUE
Definition blpapi_correlationid.h:248
@ INT_VALUE
Definition blpapi_correlationid.h:251
@ POINTER_VALUE
Definition blpapi_correlationid.h:254
CorrelationId & operator=(const CorrelationId &rhs)
Definition blpapi_correlationid.h:499
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
Definition blpapi_abstractsession.h:212
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:637
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:680
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:660
bool operator<(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:665
Definition blpapi_abstractsession.h:211