Created
October 21, 2008 03:55
-
-
Save bdonlan/18246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef UNPACKER_H | |
#define UNPACKER_H 1 | |
#include <iostream> | |
#include <boost/function.hpp> | |
class Unpacker { | |
protected: | |
Unpacker() { } | |
public: | |
virtual ~Unpacker() { } | |
virtual bool recognizable() = 0; | |
virtual std::map<std::string, std::string> metadata() = 0; | |
virtual void unpack( | |
boost::function< | |
void (const std::string &, std::istream &) | |
> callback | |
) = 0; | |
}; | |
/* for registration in a master list somewhere in the agent injector */ | |
class UnpackerFactory { | |
public: | |
UnpackerFactory() { } | |
virtual Unpacker *build(std::istream *s) = 0; | |
}; | |
template <class T> | |
class UnpackerFactoryImpl : public UnpackerFactory { | |
public: | |
UnpackerFactoryImpl() { } | |
Unpacker *build(std::istream *s) { | |
Unpacker *u = new T(s); | |
if (u->recognizable()) | |
return u; | |
delete u; | |
return NULL; | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment