added support for ptr to const GDD
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
//
|
||||
// smartGDDPointer::set()
|
||||
//
|
||||
void smartGDDPointer::set (gdd *pNewValue)
|
||||
void smartConstGDDPointer::set (const gdd *pNewValue)
|
||||
{
|
||||
int gddStatus;
|
||||
//
|
||||
@@ -20,16 +20,16 @@ void smartGDDPointer::set (gdd *pNewValue)
|
||||
// potentially unref a gdd that we are
|
||||
// still using if the pointer isnt changing
|
||||
//
|
||||
if (this->pValue==pNewValue) {
|
||||
if ( this->pConstValue == pNewValue ) {
|
||||
return;
|
||||
}
|
||||
if (this->pValue!=NULL) {
|
||||
gddStatus = this->pValue->unreference();
|
||||
assert (!gddStatus);
|
||||
if ( this->pConstValue != NULL ) {
|
||||
gddStatus = this->pConstValue->unreference();
|
||||
assert ( ! gddStatus );
|
||||
}
|
||||
this->pValue = pNewValue;
|
||||
if (this->pValue!=NULL) {
|
||||
gddStatus = this->pValue->reference();
|
||||
assert (!gddStatus);
|
||||
this->pConstValue = pNewValue;
|
||||
if ( this->pConstValue != NULL ) {
|
||||
gddStatus = this->pConstValue->reference();
|
||||
assert ( ! gddStatus );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,77 +13,139 @@
|
||||
#include "shareLib.h"
|
||||
|
||||
//
|
||||
// smartGDDPointer
|
||||
// smartConstGDDPointer
|
||||
//
|
||||
// smart pointer class which auto ref/unrefs the GDD
|
||||
// smart pointer class which auto ref/unrefs a const GDD
|
||||
//
|
||||
class epicsShareClass smartGDDPointer {
|
||||
class epicsShareClass smartConstGDDPointer {
|
||||
public:
|
||||
|
||||
smartGDDPointer () :
|
||||
pValue (0) {}
|
||||
smartConstGDDPointer () :
|
||||
pConstValue (0) {}
|
||||
|
||||
smartGDDPointer (gdd &valueIn) :
|
||||
pValue (&valueIn)
|
||||
smartConstGDDPointer (const gdd &valueIn) :
|
||||
pConstValue (&valueIn)
|
||||
{
|
||||
int gddStatus;
|
||||
gddStatus = this->pValue->reference();
|
||||
assert(!gddStatus);
|
||||
gddStatus = this->pConstValue->reference ();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
|
||||
smartGDDPointer (gdd *pValueIn) :
|
||||
pValue (pValueIn)
|
||||
smartConstGDDPointer (const gdd *pValueIn) :
|
||||
pConstValue (pValueIn)
|
||||
{
|
||||
if (this->pValue!=NULL) {
|
||||
if ( this->pConstValue != NULL ) {
|
||||
int gddStatus;
|
||||
gddStatus = this->pValue->reference();
|
||||
assert(!gddStatus);
|
||||
}
|
||||
}
|
||||
|
||||
smartGDDPointer (const smartGDDPointer &ptrIn) :
|
||||
pValue (ptrIn.pValue)
|
||||
{
|
||||
if (this->pValue!=NULL) {
|
||||
int gddStatus;
|
||||
gddStatus = this->pValue->reference();
|
||||
assert(!gddStatus);
|
||||
}
|
||||
}
|
||||
|
||||
~smartGDDPointer ()
|
||||
{
|
||||
if (this->pValue!=NULL) {
|
||||
int gddStatus;
|
||||
gddStatus = this->pValue->unreference();
|
||||
gddStatus = this->pConstValue->reference ();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void set (gdd *pNewValue);
|
||||
smartConstGDDPointer (const smartConstGDDPointer &ptrIn) :
|
||||
pConstValue (ptrIn.pConstValue)
|
||||
{
|
||||
if ( this->pConstValue != NULL ) {
|
||||
int gddStatus;
|
||||
gddStatus = this->pConstValue->reference();
|
||||
assert(!gddStatus);
|
||||
}
|
||||
}
|
||||
|
||||
~smartConstGDDPointer ()
|
||||
{
|
||||
if ( this->pConstValue != NULL ) {
|
||||
int gddStatus;
|
||||
gddStatus = this->pConstValue->unreference();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void set (const gdd *pNewValue);
|
||||
|
||||
smartConstGDDPointer operator = (const gdd *rhs)
|
||||
{
|
||||
this->set (rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
smartConstGDDPointer operator = (const smartConstGDDPointer &rhs)
|
||||
{
|
||||
this->set (rhs.pConstValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const gdd *operator -> () const
|
||||
{
|
||||
return this->pConstValue;
|
||||
}
|
||||
|
||||
const gdd & operator * () const
|
||||
{
|
||||
return *this->pConstValue;
|
||||
}
|
||||
|
||||
bool operator ! () const
|
||||
{
|
||||
if (this->pConstValue) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// see Meyers, "more effective C++", for explanation on
|
||||
// why conversion to dumb pointer is ill advised here
|
||||
//
|
||||
//operator const gdd * () const
|
||||
//{
|
||||
// return this->pConstValue;
|
||||
//}
|
||||
|
||||
protected:
|
||||
union {
|
||||
gdd *pValue;
|
||||
const gdd *pConstValue;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// smartGDDPointer
|
||||
//
|
||||
// smart pointer class which auto ref/unrefs the GDD
|
||||
//
|
||||
class epicsShareClass smartGDDPointer : public smartConstGDDPointer {
|
||||
public:
|
||||
smartGDDPointer () :
|
||||
smartConstGDDPointer () {}
|
||||
|
||||
smartGDDPointer (gdd &valueIn) :
|
||||
smartConstGDDPointer (valueIn) {}
|
||||
|
||||
smartGDDPointer (gdd *pValueIn) :
|
||||
smartConstGDDPointer (pValueIn) {}
|
||||
|
||||
smartGDDPointer (const smartGDDPointer &ptrIn) :
|
||||
smartConstGDDPointer (ptrIn) {}
|
||||
|
||||
void set (gdd *pNewValue)
|
||||
{
|
||||
this->smartConstGDDPointer::set (pNewValue);
|
||||
}
|
||||
|
||||
smartGDDPointer operator = (gdd *rhs)
|
||||
{
|
||||
set (rhs);
|
||||
this->smartGDDPointer::set (rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
smartGDDPointer operator = (const smartGDDPointer &rhs)
|
||||
{
|
||||
set (rhs.pValue);
|
||||
this->smartGDDPointer::set (rhs.pValue);
|
||||
return *this;
|
||||
}
|
||||
#if 0
|
||||
int operator == (const smartGDDPointer &rhs) const
|
||||
{
|
||||
return this->pValue==rhs.pValue;
|
||||
}
|
||||
|
||||
int operator != (const smartGDDPointer &rhs) const
|
||||
{
|
||||
return this->pValue!=rhs.pValue;
|
||||
}
|
||||
#endif
|
||||
gdd *operator -> () const
|
||||
{
|
||||
return this->pValue;
|
||||
@@ -94,13 +156,118 @@ public:
|
||||
return *this->pValue;
|
||||
}
|
||||
|
||||
operator gdd * () const
|
||||
//
|
||||
// see Meyers, "more effective C++", for explanation on
|
||||
// why conversion to dumb pointer is ill advised here
|
||||
//
|
||||
//operator gdd * () const
|
||||
//{
|
||||
// return this->pValue;
|
||||
//}
|
||||
};
|
||||
|
||||
//
|
||||
// smartConstGDDReference
|
||||
//
|
||||
// smart reference class which auto ref/unrefs a const GDD
|
||||
//
|
||||
// Notes:
|
||||
// 1) must be used with "->" operator and not "." operator
|
||||
// 2) must be used with "*" operator as an L-value
|
||||
//
|
||||
class epicsShareClass smartConstGDDReference {
|
||||
public:
|
||||
|
||||
smartConstGDDReference (const gdd *pValueIn) :
|
||||
pConstValue (pValueIn)
|
||||
{
|
||||
assert (this->pConstValue);
|
||||
int gddStatus;
|
||||
gddStatus = this->pConstValue->reference ();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
|
||||
smartConstGDDReference (const gdd &valueIn) :
|
||||
pConstValue (&valueIn)
|
||||
{
|
||||
int gddStatus;
|
||||
gddStatus = this->pConstValue->reference ();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
|
||||
smartConstGDDReference (const smartConstGDDReference &refIn) :
|
||||
pConstValue (refIn.pConstValue)
|
||||
{
|
||||
int gddStatus;
|
||||
gddStatus = this->pConstValue->reference();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
|
||||
//smartConstGDDReference (const smartConstGDDPointer &ptrIn) :
|
||||
// pConstValue (ptrIn.pConstValue)
|
||||
//{
|
||||
// assert (this->pConstValue)
|
||||
// int gddStatus;
|
||||
// gddStatus = this->pConstValue->reference();
|
||||
// assert (!gddStatus);
|
||||
//}
|
||||
|
||||
~smartConstGDDReference ()
|
||||
{
|
||||
int gddStatus;
|
||||
gddStatus = this->pConstValue->unreference();
|
||||
assert (!gddStatus);
|
||||
}
|
||||
|
||||
const gdd *operator -> () const
|
||||
{
|
||||
return this->pConstValue;
|
||||
}
|
||||
|
||||
const gdd & operator * () const
|
||||
{
|
||||
return *this->pConstValue;
|
||||
}
|
||||
protected:
|
||||
union {
|
||||
gdd *pValue;
|
||||
const gdd *pConstValue;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// smartGDDReference
|
||||
//
|
||||
// smart reference class which auto ref/unrefs a const GDD
|
||||
//
|
||||
// Notes:
|
||||
// 1) must be used with "->" operator and not "." operator
|
||||
// 2) must be used with "*" operator as an L-value
|
||||
//
|
||||
class epicsShareClass smartGDDReference : public smartConstGDDReference {
|
||||
public:
|
||||
|
||||
smartGDDReference (gdd *pValueIn) :
|
||||
smartConstGDDReference (pValueIn) {}
|
||||
|
||||
smartGDDReference (gdd &valueIn) :
|
||||
smartConstGDDReference (valueIn) {}
|
||||
|
||||
smartGDDReference (const smartGDDReference &refIn) :
|
||||
smartConstGDDReference (refIn) {}
|
||||
|
||||
//smartGDDReference (const smartGDDPointer &ptrIn) :
|
||||
// smartConstGDDReference (ptrIn)
|
||||
|
||||
gdd *operator -> () const
|
||||
{
|
||||
return this->pValue;
|
||||
}
|
||||
|
||||
private:
|
||||
gdd *pValue;
|
||||
gdd & operator * () const
|
||||
{
|
||||
return *this->pValue;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // smartGDDPointer_h
|
||||
|
||||
Reference in New Issue
Block a user