Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #ifndef UNPACKER_H
  2. #define UNPACKER_H 1
  3.  
  4. #include <iostream>
  5. #include <boost/function.hpp>
  6.  
  7. class Unpacker {
  8. protected:
  9. Unpacker() { }
  10. public:
  11. virtual ~Unpacker() { }
  12.  
  13. virtual bool recognizable() = 0;
  14. virtual std::map<std::string, std::string> metadata() = 0;
  15. virtual void unpack(
  16. boost::function<
  17. void (const std::string &, std::istream &)
  18. > callback
  19. ) = 0;
  20. };
  21.  
  22. /* for registration in a master list somewhere in the agent injector */
  23.  
  24. class UnpackerFactory {
  25. public:
  26. UnpackerFactory() { }
  27. virtual Unpacker *build(std::istream *s) = 0;
  28. };
  29.  
  30. template <class T>
  31. class UnpackerFactoryImpl : public UnpackerFactory {
  32. public:
  33. UnpackerFactoryImpl() { }
  34. Unpacker *build(std::istream *s) {
  35. Unpacker *u = new T(s);
  36. if (u->recognizable())
  37. return u;
  38. delete u;
  39. return NULL;
  40. }
  41. };
  42.  
  43. #endif
Add Comment
Please, Sign In to add comment