IBR-DTNSuite
0.8
|
00001 /* 00002 * ExtensionBlock.h 00003 * 00004 * Created on: 26.05.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef EXTENSIONBLOCK_H_ 00009 #define EXTENSIONBLOCK_H_ 00010 00011 #include "ibrdtn/data/Block.h" 00012 #include <ibrcommon/data/BLOB.h> 00013 #include <map> 00014 00015 namespace dtn 00016 { 00017 namespace data 00018 { 00019 class ExtensionBlock : public Block 00020 { 00021 public: 00022 class Factory 00023 { 00024 public: 00025 virtual dtn::data::Block* create() = 0; 00026 00027 static Factory& get(char type) throw (ibrcommon::Exception); 00028 00029 protected: 00030 Factory(char type); 00031 virtual ~Factory(); 00032 00033 private: 00034 char _type; 00035 }; 00036 00037 ExtensionBlock(); 00038 ExtensionBlock(ibrcommon::BLOB::Reference ref); 00039 virtual ~ExtensionBlock(); 00040 00041 ibrcommon::BLOB::Reference getBLOB() const; 00042 00043 virtual size_t getLength() const; 00044 virtual std::ostream &serialize(std::ostream &stream, size_t &length) const; 00045 virtual std::istream &deserialize(std::istream &stream, const size_t length); 00046 00047 protected: 00048 class FactoryList 00049 { 00050 public: 00051 FactoryList(); 00052 virtual ~FactoryList(); 00053 00054 Factory& get(char type) throw (ibrcommon::Exception); 00055 void add(char type, Factory *f) throw (ibrcommon::Exception); 00056 void remove(char type); 00057 00058 static void initialize(); 00059 00060 private: 00061 std::map<char, Factory*> fmap; 00062 }; 00063 00064 static FactoryList *factories; 00065 00066 private: 00067 ibrcommon::BLOB::Reference _blobref; 00068 }; 00069 } 00070 } 00071 00072 #endif /* EXTENSIONBLOCK_H_ */