Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef void(*FileChunkCaseFunc)(od::StreamData&);
- template<unsigned Magic, FileChunkCaseFunc Func>
- struct FileChunkCase
- {
- static constexpr std::pair<unsigned, FileChunkCaseFunc> pair = std::make_pair(Magic, Func);
- };
- template<class...Args>
- class FileChunkReader
- {
- public:
- void operator()(od::StreamData & s);
- };
- template<class...Args>
- void FileChunkReader<Args...>::operator()(od::StreamData & s)
- {
- unsigned chunk, len;
- do
- {
- s >> chunk >> len;
- for(auto& pair: {Args::pair...})
- {
- if(pair.first == chunk) {
- pair.second(s);
- break;
- }
- }
- s.seek(len-4, od::StreamData::Cursor);
- }
- while(!s.eof());
- }
- void readBiom(od::StreamData & s)
- {
- printf("Biom\n");
- }
- void readBloc(od::StreamData & s)
- {
- printf("Bloc\n");
- }
- void SerializeWorld::load(const std::string & fname)
- {
- od::StreamData s;
- s.load(fname);
- FileChunkReader<
- FileChunkCase<stringMagic("BIOM"), readBiom>,
- FileChunkCase<stringMagic("BLOC"), readBloc>
- >()(s);
- }
Advertisement
Add Comment
Please, Sign In to add comment