38#ifndef INCLUDED_BLPAPI_CORRELATIONID
39#define INCLUDED_BLPAPI_CORRELATIONID
93struct blpapi_ManagedPtr_t_;
94typedef struct blpapi_ManagedPtr_t_
113typedef int (*blpapi_ManagedPtr_ManagerFunction_t)(
114 blpapi_ManagedPtr_t *managedPtr,
115 const blpapi_ManagedPtr_t *srcPtr,
129} blpapi_ManagedPtr_t_data_;
138struct blpapi_ManagedPtr_t_ {
140 blpapi_ManagedPtr_t_data_
142 blpapi_ManagedPtr_ManagerFunction_t
154typedef struct blpapi_CorrelationId_t_ {
155 unsigned int size : 8;
156 unsigned int valueType
160 unsigned int internalClassId : 4;
163 blpapi_UInt64_t intValue;
167} blpapi_CorrelationId_t;
186int blpapi_CorrelationId_managedPtrAddRef(
187 int *numRef, blpapi_CorrelationId_t *cid);
207int blpapi_CorrelationId_managedPtrRelease(
208 int *numRef, blpapi_CorrelationId_t *cid);
309 e_FOREIGN_OBJECT = BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT
313 blpapi_CorrelationId_t d_impl;
315 void copy(
const blpapi_CorrelationId_t& src,
bool firstCopy);
317 template <
typename TYPE>
318 static int managerFunc(blpapi_ManagedPtr_t *managedPtr,
319 const blpapi_ManagedPtr_t *srcPtr,
323 template <
typename TYPE>
static void assertSmartPtrFits();
358 explicit CorrelationId(
const blpapi_CorrelationId_t& correlation);
384 template <
typename TYPE>
420 unsigned short classId()
const;
449 blpapi_CorrelationId_t& impl();
450 const blpapi_CorrelationId_t& impl()
const;
458inline bool operator==(
const CorrelationId& lhs,
const CorrelationId& rhs);
467inline bool operator!=(
const CorrelationId& lhs,
const CorrelationId& rhs);
472inline bool operator<(
const CorrelationId& lhs,
const CorrelationId& rhs);
493 std::memset(&d_impl, 0,
sizeof(d_impl));
498 const blpapi_CorrelationId_t& correlationId)
500 copy(correlationId,
true);
506 copy(original.d_impl,
false);
511 std::memset(&d_impl, 0,
sizeof(d_impl));
513 d_impl.size =
static_cast<unsigned>(
sizeof(d_impl));
515 d_impl.value.intValue =
static_cast<blpapi_UInt64_t
>(intValue);
516 d_impl.classId =
static_cast<unsigned>(newClassId);
521 std::memset(&d_impl, 0,
sizeof(d_impl));
523 d_impl.size =
static_cast<unsigned>(
sizeof(d_impl));
525 d_impl.value.ptrValue.pointer = ptrValue;
526 d_impl.classId =
static_cast<unsigned>(newClassId);
529template <
typename TYPE>
531 const TYPE& smartPtr,
void *ptrValue,
int newClassId)
536 assertSmartPtrFits<TYPE>();
538 std::memset(&d_impl, 0,
sizeof(d_impl));
540 d_impl.size =
sizeof(d_impl);
542 d_impl.classId = newClassId;
544 d_impl.value.ptrValue.pointer = ptrValue;
545 d_impl.value.ptrValue.manager = &CorrelationId::managerFunc<TYPE>;
547 void *arena = (
void *)d_impl.value.ptrValue.userData;
548 new (arena) TYPE(smartPtr);
554 blpapi_ManagedPtr_ManagerFunction_t& manager
555 = d_impl.value.ptrValue.manager;
558 if (d_impl.internalClassId == e_FOREIGN_OBJECT
559 && BLPAPI_CALL_AVAILABLE(
560 blpapi_CorrelationId_managedPtrRelease)
561 && BLPAPI_CALL_UNCHECKED(
562 blpapi_CorrelationId_managedPtrRelease)(
568 manager(&d_impl.value.ptrValue, 0, BLPAPI_MANAGEDPTR_DESTROY);
577 swap(other.d_impl, d_impl);
588inline blpapi_CorrelationId_t& CorrelationId::impl() {
return d_impl; }
600 return d_impl.value.ptrValue.pointer;
605 typedef int (*ManagerFuncPtr)(
606 blpapi_ManagedPtr_t *,
const blpapi_ManagedPtr_t *, int);
608 ManagerFuncPtr managerFnPtr
609 =
static_cast<ManagerFuncPtr
>(&(CorrelationId::managerFunc<TYPE>));
611 || (d_impl.value.ptrValue.manager != managerFnPtr)) {
614 return *(TYPE *)d_impl.value.ptrValue.userData;
619 return static_cast<long long>(d_impl.value.intValue);
623inline const blpapi_CorrelationId_t& CorrelationId::impl()
const
630inline void CorrelationId::copy(
631 const blpapi_CorrelationId_t& src,
bool firstCopy)
636 blpapi_ManagedPtr_ManagerFunction_t& manager
637 = d_impl.value.ptrValue.manager;
639 if (d_impl.internalClassId == e_FOREIGN_OBJECT) {
648 std::memset(&d_impl.value.ptrValue.userData,
650 sizeof(d_impl.value.ptrValue.userData));
654 BLPAPI_CALL(blpapi_CorrelationId_managedPtrAddRef)(
660 manager(&d_impl.value.ptrValue,
662 BLPAPI_MANAGEDPTR_COPY);
669template <
typename TYPE>
670inline int CorrelationId::managerFunc(blpapi_ManagedPtr_t *managedPtr,
671 const blpapi_ManagedPtr_t *srcPtr,
674 if (operation == BLPAPI_MANAGEDPTR_COPY) {
675 managedPtr->pointer = srcPtr->pointer;
676 managedPtr->manager = srcPtr->manager;
678 void *arena = managedPtr->userData;
679 new (arena) TYPE(*((TYPE *)&srcPtr->userData[0]));
680 }
else if (operation == BLPAPI_MANAGEDPTR_DESTROY) {
681 TYPE *managedPtr_p = (TYPE *)&managedPtr->userData[0];
682 managedPtr_p->~TYPE();
683 }
else if (operation == BLPAPI_MANAGEDPTR_IMPOSSIBLE_OPERATION) {
684 static int uniquePerTemplateInstantiation;
686 const int *address = &uniquePerTemplateInstantiation;
688 std::memcpy(&rc, &address, std::min(
sizeof address,
sizeof rc));
705template <
typename TYPE>
inline void CorrelationId::assertSmartPtrFits()
711 char errorIfSmartPtrDoesNotFit[
sizeof(TYPE) <= (
sizeof(
void *) * 4)
714 (void)errorIfSmartPtrDoesNotFit;
726 if (lhs.impl().internalClassId != rhs.impl().internalClassId) {
743 return !(lhs == rhs);
749 && lhs.impl().internalClassId
750 == BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT
752 && rhs.impl().internalClassId
753 == BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT) {
758 return std::memcmp(&lhs.impl(), &rhs.impl(),
sizeof(rhs.impl())) < 0;
764 const char *valueType = 0;
773 valueType =
"POINTER";
776 valueType =
"AUTOGEN";
779 valueType =
"UNKNOWN";
782 os <<
"[ valueType=" << valueType <<
" classId=" << correlator.
classId()
783 <<
" internalClassId=" << correlator.impl().internalClassId
Provide functions for dispatchtbl.
Common definitions used by the library.
Defines Exceptions that can be thrown by the blpapi library.
Definition blpapi_correlationid.h:306
@ MAX_CLASS_ID
Definition blpapi_correlationid.h:345
void swap(CorrelationId &other)
Definition blpapi_correlationid.h:573
unsigned short classId() const
Definition blpapi_correlationid.h:596
ValueType valueType() const
Definition blpapi_correlationid.h:591
void * asPointer() const
Definition blpapi_correlationid.h:598
TYPE asSmartPointer() const
Definition blpapi_correlationid.h:603
~CorrelationId()
Definition blpapi_correlationid.h:551
CorrelationId()
Definition blpapi_correlationid.h:491
long long asInteger() const
Definition blpapi_correlationid.h:617
ValueType
Definition blpapi_correlationid.h:328
@ AUTOGEN_VALUE
The CorrelationId was created internally by API.
Definition blpapi_correlationid.h:338
@ UNSET_VALUE
Definition blpapi_correlationid.h:329
@ INT_VALUE
Definition blpapi_correlationid.h:332
@ POINTER_VALUE
Definition blpapi_correlationid.h:335
CorrelationId & operator=(const CorrelationId &rhs)
Definition blpapi_correlationid.h:580
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Definition blpapi_abstractsession.h:452
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:718
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:761
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:741
bool operator<(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:746
Definition blpapi_abstractsession.h:451