I'm implementing a fancy pointer type which wraps a parallel memory controller, for pointer-like reading to and writing from external SDRAM. The usage requirements are somewhat as following:
// High level overview of class definition:
class extern_pointer {
class extern_value; // Used as temporary for *e_ptr = ...; etc.
{...}
};
auto e_ptr = hwstl::extern_pointer<struct_in_external_memory>(...);
// set pointer to point to 0x0010000
// extern_pointer&::operator= (e_ptr::address_type); sets internal ptr value
e_ptr = 0x0010000;
// extern_value&::operator= (e_ptr::char_type);
// note: char_type is the minimum size of addressable set of bits,
// variations for extern_value&::operator= are allowed for wider databusses
*e_ptr = 0x60;
// invokes const extern_pointer&::operator*,
// obtains a copy and implicitly converts to
// struct_in_external_memory
struct_in_external_memory v = *e_ptr;
Now as I've been implementing operator* for extern_pointer, I realized operator-> is also a thing.
For operator*, I could just return a temporary extern_value, which overloads some operators to give the pointer-like feeling.
But for -> that isn't the case, since it would require extern_value to contain all the members and methods which refers to the external memory instead.
Is there anything I can do other than deleting extern_value* operator->()
?
Edit:
with the declaration of:
class struct_in_external_memory {
void MyMethod() { /* changes some internal stuff */ }
};
Essentially what I want to be able to do is:
e_ptr->MyMethod()
Normally, MyMethod is a member of struct_in_external_memory, but -> needs to return an 'extern_value*'`