J
jason.cipriani
I'm in a rather strange situation. I have a class that does some stuff
and uses a buffer to hold some data in; the details aren't important
but the buffer is an std::vector:
class Something {
...
private:
std::vector<unsigned char> buffer_;
...
};
The class is rather complex and has a lot of code that relies on
buffer_ being an std::vector. Now I'm in a position where I have to
add the ability for a client to use some external buffer. However, I
want to modify the minimum amount of code possible. So I want an
interface like this:
class Something {
...
void attachExternalBuffer (unsigned char *buf);
private:
std::vector<unsigned char> buffer_;
...
};
And I'd like to be able to use the supplied external buffer as the
"backing" for the buffer_ vector. I know for a fact that buffer_ is
never resize()'d so I don't have to worry about dealing with that. I
just want to be able to have the existing code in the class remain
unchanged, but modify the client-supplied buffer through "buffer_". Is
there some way I can make this work?
Thanks,
Jason
and uses a buffer to hold some data in; the details aren't important
but the buffer is an std::vector:
class Something {
...
private:
std::vector<unsigned char> buffer_;
...
};
The class is rather complex and has a lot of code that relies on
buffer_ being an std::vector. Now I'm in a position where I have to
add the ability for a client to use some external buffer. However, I
want to modify the minimum amount of code possible. So I want an
interface like this:
class Something {
...
void attachExternalBuffer (unsigned char *buf);
private:
std::vector<unsigned char> buffer_;
...
};
And I'd like to be able to use the supplied external buffer as the
"backing" for the buffer_ vector. I know for a fact that buffer_ is
never resize()'d so I don't have to worry about dealing with that. I
just want to be able to have the existing code in the class remain
unchanged, but modify the client-supplied buffer through "buffer_". Is
there some way I can make this work?
Thanks,
Jason