Network Cookie Jar: implement assignment operator.

This change is needed for implementing cookie persistence in Web+ using
the network kit backend.

The current implementation requires the user to unarchive the cookie
jar, then hand it over to the BUrlContext which will copy it to its own
field. This makes the code simpler, but maybe doing a complete copy
(with all the cookies) is an heavy operation and could be avoided.
This commit is contained in:
Adrien Destugues
2013-10-28 17:29:19 +01:00
parent c157484a81
commit b7617ddd68
2 changed files with 29 additions and 0 deletions
+3
View File
@@ -58,10 +58,13 @@ public:
virtual status_t Unflatten(type_code code,
const void* buffer, ssize_t size);
BNetworkCookieJar& operator=(const BNetworkCookieJar& other);
// Iterators
Iterator GetIterator() const;
UrlIterator GetUrlIterator(const BUrl& url) const;
private:
void _DoFlatten() const;
@@ -71,6 +71,8 @@ BNetworkCookieJar::~BNetworkCookieJar()
{
for (Iterator it = GetIterator(); it.Next() != NULL;)
delete it.Remove();
delete fCookieHashMap;
}
@@ -356,6 +358,30 @@ BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
}
BNetworkCookieJar&
BNetworkCookieJar::operator=(const BNetworkCookieJar& other)
{
if(&other == this)
return *this;
BArchivable::operator=(other);
BFlattenable::operator=(other);
fFlattened = other.fFlattened;
delete fCookieHashMap;
fCookieHashMap = new PrivateHashMap();
for (Iterator it = other.GetIterator(); it.HasNext();)
{
BNetworkCookie* cookie = it.Next();
AddCookie(*cookie); // Pass by reference so the cookie is copied.
}
return *this;
}
// #pragma mark Iterators