38#ifndef INCLUDED_BLPAPI_CORRELATIONID
39#define INCLUDED_BLPAPI_CORRELATIONID
95struct blpapi_ManagedPtr_t_;
96typedef struct blpapi_ManagedPtr_t_
115typedef int (*blpapi_ManagedPtr_ManagerFunction_t)(
116 blpapi_ManagedPtr_t *managedPtr,
117 const blpapi_ManagedPtr_t *srcPtr,
131} blpapi_ManagedPtr_t_data_;
140struct blpapi_ManagedPtr_t_ {
142 blpapi_ManagedPtr_t_data_
144 blpapi_ManagedPtr_ManagerFunction_t
156typedef struct blpapi_CorrelationId_t_ {
157 unsigned int size : 8;
158 unsigned int valueType
162 unsigned int internalClassId : 4;
165 blpapi_UInt64_t intValue;
169} blpapi_CorrelationId_t;
188int blpapi_CorrelationId_managedPtrAddRef(
189 int *numRef, blpapi_CorrelationId_t *cid);
209int blpapi_CorrelationId_managedPtrRelease(
210 int *numRef, blpapi_CorrelationId_t *cid);
224int blpapi_CorrelationId_hash(
size_t *hash,
const blpapi_CorrelationId_t *cid);
325 e_FOREIGN_OBJECT = BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT
329 blpapi_CorrelationId_t d_impl;
331 void copy(
const blpapi_CorrelationId_t& src,
bool firstCopy);
333 template <
typename TYPE>
334 static int managerFunc(blpapi_ManagedPtr_t *managedPtr,
335 const blpapi_ManagedPtr_t *srcPtr,
339 template <
typename TYPE>
static void assertSmartPtrFits();
374 explicit CorrelationId(
const blpapi_CorrelationId_t& correlation);
400 template <
typename TYPE>
436 unsigned short classId()
const;
465 blpapi_CorrelationId_t& impl();
466 const blpapi_CorrelationId_t& impl()
const;
474inline bool operator==(
const CorrelationId& lhs,
const CorrelationId& rhs);
483inline bool operator!=(
const CorrelationId& lhs,
const CorrelationId& rhs);
488inline bool operator<(
const CorrelationId& lhs,
const CorrelationId& rhs);
524 std::memset(&d_impl, 0,
sizeof(d_impl));
529 const blpapi_CorrelationId_t& correlationId)
531 copy(correlationId,
true);
537 copy(original.d_impl,
false);
542 std::memset(&d_impl, 0,
sizeof(d_impl));
544 d_impl.size =
static_cast<unsigned>(
sizeof(d_impl));
546 d_impl.value.intValue =
static_cast<blpapi_UInt64_t
>(intValue);
547 d_impl.classId =
static_cast<unsigned>(newClassId);
552 std::memset(&d_impl, 0,
sizeof(d_impl));
554 d_impl.size =
static_cast<unsigned>(
sizeof(d_impl));
556 d_impl.value.ptrValue.pointer = ptrValue;
557 d_impl.classId =
static_cast<unsigned>(newClassId);
560template <
typename TYPE>
562 const TYPE& smartPtr,
void *ptrValue,
int newClassId)
567 assertSmartPtrFits<TYPE>();
569 std::memset(&d_impl, 0,
sizeof(d_impl));
571 d_impl.size =
sizeof(d_impl);
573 d_impl.classId = newClassId;
575 d_impl.value.ptrValue.pointer = ptrValue;
576 d_impl.value.ptrValue.manager = &CorrelationId::managerFunc<TYPE>;
578 void *arena = (
void *)d_impl.value.ptrValue.userData;
579 new (arena) TYPE(smartPtr);
585 blpapi_ManagedPtr_ManagerFunction_t& manager
586 = d_impl.value.ptrValue.manager;
589 if (d_impl.internalClassId == e_FOREIGN_OBJECT
590 && BLPAPI_CALL_AVAILABLE(
591 blpapi_CorrelationId_managedPtrRelease)
592 && BLPAPI_CALL_UNCHECKED(
593 blpapi_CorrelationId_managedPtrRelease)(
599 manager(&d_impl.value.ptrValue, 0, BLPAPI_MANAGEDPTR_DESTROY);
608 swap(other.d_impl, d_impl);
619inline blpapi_CorrelationId_t& CorrelationId::impl() {
return d_impl; }
631 return d_impl.value.ptrValue.pointer;
636 typedef int (*ManagerFuncPtr)(
637 blpapi_ManagedPtr_t *,
const blpapi_ManagedPtr_t *, int);
639 ManagerFuncPtr managerFnPtr
640 =
static_cast<ManagerFuncPtr
>(&(CorrelationId::managerFunc<TYPE>));
642 || (d_impl.value.ptrValue.manager != managerFnPtr)) {
645 return *(TYPE *)d_impl.value.ptrValue.userData;
650 return static_cast<long long>(d_impl.value.intValue);
654inline const blpapi_CorrelationId_t& CorrelationId::impl()
const
661inline void CorrelationId::copy(
662 const blpapi_CorrelationId_t& src,
bool firstCopy)
667 blpapi_ManagedPtr_ManagerFunction_t& manager
668 = d_impl.value.ptrValue.manager;
670 if (d_impl.internalClassId == e_FOREIGN_OBJECT) {
679 std::memset(&d_impl.value.ptrValue.userData,
681 sizeof(d_impl.value.ptrValue.userData));
685 BLPAPI_CALL(blpapi_CorrelationId_managedPtrAddRef)(
691 manager(&d_impl.value.ptrValue,
693 BLPAPI_MANAGEDPTR_COPY);
700template <
typename TYPE>
701inline int CorrelationId::managerFunc(blpapi_ManagedPtr_t *managedPtr,
702 const blpapi_ManagedPtr_t *srcPtr,
705 if (operation == BLPAPI_MANAGEDPTR_COPY) {
706 managedPtr->pointer = srcPtr->pointer;
707 managedPtr->manager = srcPtr->manager;
709 void *arena = managedPtr->userData;
710 new (arena) TYPE(*((TYPE *)&srcPtr->userData[0]));
711 }
else if (operation == BLPAPI_MANAGEDPTR_DESTROY) {
712 TYPE *managedPtr_p = (TYPE *)&managedPtr->userData[0];
713 managedPtr_p->~TYPE();
714 }
else if (operation == BLPAPI_MANAGEDPTR_IMPOSSIBLE_OPERATION) {
715 static int uniquePerTemplateInstantiation;
717 const int *address = &uniquePerTemplateInstantiation;
719 std::memcpy(&rc, &address, std::min(
sizeof address,
sizeof rc));
736template <
typename TYPE>
inline void CorrelationId::assertSmartPtrFits()
742 char errorIfSmartPtrDoesNotFit[
sizeof(TYPE) <= (
sizeof(
void *) * 4)
745 (void)errorIfSmartPtrDoesNotFit;
757 if (lhs.impl().internalClassId != rhs.impl().internalClassId) {
774 return !(lhs == rhs);
780 && lhs.impl().internalClassId
781 == BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT
783 && rhs.impl().internalClassId
784 == BLPAPI_CORRELATION_INTERNAL_CLASS_FOREIGN_OBJECT) {
789 return std::memcmp(&lhs.impl(), &rhs.impl(),
sizeof(rhs.impl())) < 0;
795 const char *valueType = 0;
804 valueType =
"POINTER";
807 valueType =
"AUTOGEN";
810 valueType =
"UNKNOWN";
813 os <<
"[ valueType=" << valueType <<
" classId=" << correlator.
classId()
814 <<
" internalClassId=" << correlator.impl().internalClassId
834 return "UNSET_VALUE";
838 return "POINTER_VALUE";
840 return "AUTOGEN_VALUE";
Provide functions for dispatchtbl.
Common definitions used by the library.
Defines Exceptions that can be thrown by the blpapi library.
Definition blpapi_correlationid.h:322
@ MAX_CLASS_ID
Definition blpapi_correlationid.h:361
void swap(CorrelationId &other)
Definition blpapi_correlationid.h:604
unsigned short classId() const
Definition blpapi_correlationid.h:627
ValueType valueType() const
Definition blpapi_correlationid.h:622
void * asPointer() const
Definition blpapi_correlationid.h:629
TYPE asSmartPointer() const
Definition blpapi_correlationid.h:634
~CorrelationId()
Definition blpapi_correlationid.h:582
CorrelationId()
Definition blpapi_correlationid.h:522
long long asInteger() const
Definition blpapi_correlationid.h:648
ValueType
Definition blpapi_correlationid.h:344
@ AUTOGEN_VALUE
The CorrelationId was created internally by API.
Definition blpapi_correlationid.h:354
@ UNSET_VALUE
Definition blpapi_correlationid.h:345
@ INT_VALUE
Definition blpapi_correlationid.h:348
@ POINTER_VALUE
Definition blpapi_correlationid.h:351
CorrelationId & operator=(const CorrelationId &rhs)
Definition blpapi_correlationid.h:611
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
constexpr const char * to_string(CorrelationId::ValueType valueType)
Definition blpapi_correlationid.h:830
Definition blpapi_correlationid.h:499
Definition blpapi_abstractsession.h:448
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:749
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition blpapi_correlationid.h:792
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:772
bool operator<(const CorrelationId &lhs, const CorrelationId &rhs)
Definition blpapi_correlationid.h:777
Definition blpapi_abstractsession.h:447