Code:
class CBase {
public :
static void SetupVmeInterface(CVmeInterface *in);
protected :
static CVmeInterface *pVmeInterface;
};
template <class T> class TCVmeAccess : public CBase {
public:
TCVmeAccess(int address);
T get(); // similar to operator->
T *operator->()
{
unsigned long temp = pVmeInterface->ReadAddress(Address);
T *ret = reinterpret_cast<T*>(&temp);
return ret;
}
unsigned long asLong();
bool set(T data)
{
unsigned long write_data = *reinterpret_cast<unsigned long*>(&data);
return pVmeInterface->WriteAddress(Address, write_data);
};
// void operator->(T);
// void operator=(T)
// void operator->(int);
// void operator=(int);
private :
int Address;
};
A struct that will be used in the template (the fact that its bit-field'ed is not an issue):-
Code:
typedef struct
{
int a: 1; // 0
int b: 1; // 1
int c: 1; // 2
int d: 1; // 3
int NotUsed : 28; // 31-4
} _HVPSUControl;
Code body :-
Code:
TCVmeAccess<_HVPSUControl> HVPSUControl(constHVPSUControlBlock);
_HVPSUControl hvpsu = HVPSUControl.get(); // works - but not as nice as...
int a = HVPSUControl2.get().OperationalRequestPort; // works - but...
int b = HVPSUControl->a; // works, and is all the nicest for reads, good so far
// writes are my question :-
HVPSUControl.set(hvpsu); // works, but need a _HVPSUControl type!
HVPSUControl->a = 1; // this line does not work!
I want the assignment of the struct member to go through the set method in the template class?
Because my writes have to be Read/Modify/Write, I have to do this this code in-line everywhere on assignments :-
Code:
// HVPSUControl is predefined and used many times.
_HVPSUControl hvpsu;
hvpsu.a = 1;
HVPSUControl.set(hvpsu);
// This would save on those lines (and I can also perform extra logic in my template)
HVPSUControl.a = 1;
Cheers, Ian.