diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index fd7cea4..fcb2758 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -103,6 +103,8 @@ class PVScalarArray; class PVStructure; + +template class PVScalarValue; template class PVValueArray; @@ -397,6 +399,10 @@ std::ostream& operator<<(std::ostream& o, const PVField& f); * PVScalar is the base class for each scalar field. */ class PVScalar : public PVField { + // friend our child class(s) so that it + // can call protected methods of other + // PVScalar instances. + template friend class PVScalarValue; public: POINTER_DEFINITIONS(PVScalar); /** @@ -427,7 +433,9 @@ public: this->getAs((void*)&result, ID); return result; } +protected: virtual void getAs(void *, ScalarType) const = 0; +public: /** * Convert and assign the provided value. @@ -443,7 +451,9 @@ public: inline void putFrom(typename ScalarTypeTraits::type val) { this->putFrom((const void*)&val, ID); } +protected: virtual void putFrom(const void *, ScalarType) = 0; +public: virtual void assign(const PVScalar&) = 0; @@ -498,6 +508,19 @@ public: put(value); } + template + inline typename ScalarTypeTraits::type getAs() const { + typedef typename ScalarTypeTraits::type to_t; + to_t result(castUnsafe(get())); + return result; + } + + template + inline void putFrom(typename ScalarTypeTraits::type val) { + typedef typename ScalarTypeTraits::type from_t; + put(castUnsafe(val)); + } + protected: PVScalarValue(ScalarConstPtr const & scalar) : PVScalar(scalar) {}