From 6ce9b0beeb0a9c8dee0246f4fae79c6d5c8219af Mon Sep 17 00:00:00 2001 From: pixel Date: Wed, 9 May 2007 07:12:33 +0000 Subject: First new bricks of a more global domain system. --- lib/Domain.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/Domain.cc (limited to 'lib/Domain.cc') diff --git a/lib/Domain.cc b/lib/Domain.cc new file mode 100644 index 0000000..8b06bdd --- /dev/null +++ b/lib/Domain.cc @@ -0,0 +1,50 @@ +#include "Domain.h" + +Domain * Domain::head = 0; + +Domain::Domain(const Regex & _pattern) : pattern(_pattern) { + prev = 0; + next = head; + head = this; + next->prev = this; +} + +Domain::~Domain() { + if (head == this) + head = next; + if (next) + next->prev = prev; + if (prev) + prev->next = next; +} + +void Domain::OnTop() { + if (next) + next->prev = prev; + if (prev) + prev->next = next; + + prev = 0; + next = head; + head = this; + next->prev = this; +} + +Domain * Domain::find_domain(const String & url) { + Domain * r = 0; + + if (head) + r = head->find_domain_r(url); + + return r; +} + +Domain * Domain::find_domain_r(const String & url) { + if (pattern.Match(url)) + return this; + + if (next) + return next->find_domain_r(url); + + return 0; +} -- cgit v1.2.3