summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-08-06 19:03:38 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-08-06 19:03:38 +0200
commit58cd91cf08696e64bf3840fe625b4c66eac7f208 (patch)
treeabe317adcae8ea753fdb8289cec7a42e423845d9
parent01bcb80ac096de72694135dff37e2ff70c2ab572 (diff)
downloadcrawler-58cd91cf08696e64bf3840fe625b4c66eac7f208.tar.gz
crawler-58cd91cf08696e64bf3840fe625b4c66eac7f208.tar.bz2
using typeinfo to find correct destruction function for loadable module objects
-rw-r--r--src/ModuleLoader.hpp19
-rw-r--r--src/crawlingwolf.cpp2
-rw-r--r--src/modules/urlnormalizer/googleurl/GoogleURLNormalizer.cpp4
-rw-r--r--src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.cpp7
-rw-r--r--src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.hpp6
-rw-r--r--tests/url/GNUmakefile4
6 files changed, 33 insertions, 9 deletions
diff --git a/src/ModuleLoader.hpp b/src/ModuleLoader.hpp
index c4b73dc..0e3fe3d 100644
--- a/src/ModuleLoader.hpp
+++ b/src/ModuleLoader.hpp
@@ -5,6 +5,7 @@
#include <map>
#include <string>
#include <stdexcept>
+#include <typeinfo>
#include <dlfcn.h>
@@ -46,7 +47,7 @@ class ModuleLoader {
throw std::runtime_error( "missing module registry" );
}
- m_modules[m.registry->name] = m;
+ m_modules.insert( std::make_pair( m.registry->name, m ) );
}
}
@@ -57,19 +58,27 @@ class ModuleLoader {
}
}
- Interface *create( std::string subclass ) const
+ Interface *create( std::string subclass )
{
typename mapType::const_iterator it = m_modules.find( subclass );
if( it == m_modules.end( ) ) {
throw std::runtime_error( "calling unknown constructor" );
}
- return (*it).second.registry->create( );
+ Interface *obj = (*it).second.registry->create( );
+
+ std::string clazz = typeid( *obj ).name( );
+
+ m_modules.insert( std::make_pair( clazz, (*it).second ) );
+
+ return obj;
}
- void destroy( std::string subclass, Interface *obj ) const
+ void destroy( Interface *obj )
{
- typename mapType::const_iterator it = m_modules.find( subclass );
+ std::string clazz = typeid( *obj ).name( );
+
+ typename mapType::const_iterator it = m_modules.find( clazz );
if( it == m_modules.end( ) ) {
throw std::runtime_error( "calling unknown destructor" );
}
diff --git a/src/crawlingwolf.cpp b/src/crawlingwolf.cpp
index 213f9a5..b322994 100644
--- a/src/crawlingwolf.cpp
+++ b/src/crawlingwolf.cpp
@@ -64,7 +64,7 @@ int main( void )
}
delete processor;
- urlNormalizers.destroy( "google", normalizer );
+ urlNormalizers.destroy( normalizer );
delete urlSeen;
delete deduper;
delete fetcher;
diff --git a/src/modules/urlnormalizer/googleurl/GoogleURLNormalizer.cpp b/src/modules/urlnormalizer/googleurl/GoogleURLNormalizer.cpp
index e5810d6..69d3e77 100644
--- a/src/modules/urlnormalizer/googleurl/GoogleURLNormalizer.cpp
+++ b/src/modules/urlnormalizer/googleurl/GoogleURLNormalizer.cpp
@@ -2,6 +2,8 @@
#include <string>
+#include <iostream>
+
#include "url_util.h"
#include "url_canon_stdstring.h"
#include "url_parse.h"
@@ -14,11 +16,13 @@ using namespace url_parse;
GoogleURLNormalizer::GoogleURLNormalizer( )
{
Initialize( );
+ cout << "Creating Google Normalizer" << endl;
}
GoogleURLNormalizer::~GoogleURLNormalizer( )
{
Shutdown( );
+ cout << "Destroying Google Normalizer" << endl;
}
static string componentString( const string &s, const Component &comp )
diff --git a/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.cpp b/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.cpp
index 328a82b..47dd7a3 100644
--- a/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.cpp
+++ b/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.cpp
@@ -1,5 +1,6 @@
#include <string>
#include <algorithm>
+#include <iostream>
#include "SimpleURLNormalizer.hpp"
@@ -7,6 +8,12 @@ using namespace std;
SimpleURLNormalizer::SimpleURLNormalizer( )
{
+ cout << "Creating simple normalizer" << endl;
+}
+
+SimpleURLNormalizer::~SimpleURLNormalizer( )
+{
+ cout << "Destroying simple normalizer" << endl;
}
URL SimpleURLNormalizer::parseUrl( const string s )
diff --git a/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.hpp b/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.hpp
index 1badaef..a037aff 100644
--- a/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.hpp
+++ b/src/modules/urlnormalizer/simpleurl/SimpleURLNormalizer.hpp
@@ -7,10 +7,12 @@
class SimpleURLNormalizer : public URLNormalizer {
public:
SimpleURLNormalizer( );
+
+ virtual ~SimpleURLNormalizer( );
- URL parseUrl( const std::string s );
+ virtual URL parseUrl( const std::string s );
- URL normalize( const URL url, const std::string s );
+ virtual URL normalize( const URL url, const std::string s );
private:
void normalizePath( std::string &path );
diff --git a/tests/url/GNUmakefile b/tests/url/GNUmakefile
index 38645c9..62ca063 100644
--- a/tests/url/GNUmakefile
+++ b/tests/url/GNUmakefile
@@ -3,7 +3,9 @@ TOPDIR = ../..
SUBDIRS =
INCLUDE_DIRS = \
- -I$(TOPDIR)/src
+ -I$(TOPDIR)/src \
+ -I$(TOPDIR)/src/modules/urlnormalizer/simpleurl \
+ -I$(TOPDIR)/src/modules/urlnormalizer/googleurl
INCLUDE_LDFLAGS =