Unverified Commit 80eac335 authored by hasankandemir1993's avatar hasankandemir1993 Committed by GitHub

Update cookie.h

parent ce27e753
...@@ -43,67 +43,67 @@ struct Cookie { ...@@ -43,67 +43,67 @@ struct Cookie {
class CookieJar { class CookieJar {
public: public:
typedef std::unordered_map<std::string, Cookie> HashMapCookies; // "value" -> Cookie using HashMapCookies = std::unordered_map<std::string, Cookie>; // "value" -> Cookie
typedef std::unordered_map<std::string, HashMapCookies> Storage; // "name" -> Hashmap("value" -> Cookie) using Storage = std::unordered_map<std::string, HashMapCookies>; // "name" -> Hashmap("value" -> Cookie)
struct iterator : std::iterator<std::bidirectional_iterator_tag, Cookie> { struct iterator : std::iterator<std::bidirectional_iterator_tag, Cookie> {
iterator(const Storage::const_iterator& _iterator) iterator(const Storage::const_iterator& _iterator)
: it_(_iterator) : iter_storage(_iterator)
{ {
} }
iterator(const Storage::const_iterator& _iterator, const Storage::const_iterator& end) iterator(const Storage::const_iterator& _iterator, const Storage::const_iterator& end)
: it_(_iterator),end_(end) : iter_storage(_iterator),iter_storage_end(end)
{ {
if(it_ != end_) { if(iter_storage != iter_storage_end) {
it_2 = it_->second.begin(); iter_cookie_values = iter_storage->second.begin();
} }
} }
Cookie operator*() const { Cookie operator*() const {
return it_2->second; // return it_->second; return iter_cookie_values->second; // return iter_storage->second;
} }
iterator operator++() { iterator operator++() {
++it_2; ++iter_cookie_values;
if(it_2 == it_->second.end()) { if(iter_cookie_values == iter_storage->second.end()) {
++it_; ++iter_storage;
if(it_ != end_) if(iter_storage != iter_storage_end)
it_2 = it_->second.begin(); iter_cookie_values = iter_storage->second.begin();
} }
return iterator(it_,end_); return iterator(iter_storage,iter_storage_end);
} }
iterator operator++(int) { iterator operator++(int) {
iterator ret(it_,end_); iterator ret(iter_storage,iter_storage_end);
++it_2; ++iter_cookie_values;
if(it_2 == it_->second.end()) { if(iter_cookie_values == iter_storage->second.end()) {
++it_; ++iter_storage;
if(it_ != end_) // this check is important if(iter_storage != iter_storage_end) // this check is important
it_2 = it_->second.begin(); iter_cookie_values = iter_storage->second.begin();
} }
return ret; return ret;
} }
bool operator !=(iterator other) const { bool operator !=(iterator other) const {
return it_ != other.it_; return iter_storage != other.iter_storage;
} }
bool operator==(iterator other) const { bool operator==(iterator other) const {
return it_ == other.it_; return iter_storage == other.iter_storage;
} }
private: private:
Storage::const_iterator it_; Storage::const_iterator iter_storage;
HashMapCookies::const_iterator it_2; HashMapCookies::const_iterator iter_cookie_values;
Storage::const_iterator end_; // we need to know where main hashmap ends. Storage::const_iterator iter_storage_end; // we need to know where main hashmap ends.
}; };
CookieJar(); CookieJar();
void add(const Cookie& cookie); void add(const Cookie& cookie);
void removeCookie(const std::string& name); // ADDED LATER void removeCookie(const std::string& name); // Unimplemented
void addFromRaw(const char *str, size_t len); void addFromRaw(const char *str, size_t len);
Cookie get(const std::string& name) const; Cookie get(const std::string& name) const;
...@@ -111,7 +111,7 @@ public: ...@@ -111,7 +111,7 @@ public:
bool has(const std::string& name) const; bool has(const std::string& name) const;
iterator begin() const { iterator begin() const {
return iterator(cookies.begin(),cookies.end()); return iterator(cookies.begin(), cookies.end());
} }
iterator end() const { iterator end() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment