Skip to content

Instantly share code, notes, and snippets.

@bdonlan
Created October 21, 2008 03:55
Show Gist options
  • Save bdonlan/18246 to your computer and use it in GitHub Desktop.
Save bdonlan/18246 to your computer and use it in GitHub Desktop.
#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