📄 reader.h
字号:
//// Copyright (c) 2003 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef IFODUMP_READER_H#define IFODUMP_READER_H//------------------------------------------------------------------------------#include "config.h"#include "util/FileReader.h"#include <cstdlib>extern "C" {#include <libmpdvdkit/ifo_types.h>}//------------------------------------------------------------------------------namespace ifodump {//------------------------------------------------------------------------------/** * Base class for readers. */template <class Leaf>class Reader : public FileReader{protected: /** * The version. */ unsigned version;public: /** * Construct the reader */ Reader(FILE* file, unsigned version = 0); /** * Get the version */ unsigned getVersion() const; /** * Read a byte. If 0, assign 0 to the given pointer. If 1, allocate * memory for the pointed structure, and read into it. */ template <typename T> void readPointer(T*& ptr); /** * Read the size of an array. If 0, initialize the given pointer * to 0. Otherwise, allocate the array and read the members. * * @return the size of the array */ template <typename T> uint32_t readArray(T*& ptr); /** * Read a fixed array. */ template <typename T> void readFixedArray(size_t size, T* ptr); /** * Read an array whose size is determined by a "last byte" * variable. * * @return the last byte */ template <typename T> uint32_t readLastArray(T*& ptr); /** * Read a VM command. */ void read(vm_cmd_t& cmd); /** * Read a user operations structure. */ void read(user_ops_t& userOperations);};//------------------------------------------------------------------------------// Inline and template definitions//------------------------------------------------------------------------------template <class Leaf>inline Reader<Leaf>::Reader(FILE* file, unsigned version) : FileReader(file), version(version){}//------------------------------------------------------------------------------template <class Leaf>inline unsigned Reader<Leaf>::getVersion() const{ return version;}//------------------------------------------------------------------------------template <class Leaf>template <typename T>void Reader<Leaf>::readPointer(T*& ptr){ uint8_t ptrValid; FileReader::read(ptrValid); if (ptrValid) { ptr = (T*)malloc(sizeof(T)); static_cast<Leaf*>(this)->read(*ptr); } else { ptr = 0; }}//------------------------------------------------------------------------------template <class Leaf>template <typename T>uint32_t Reader<Leaf>::readArray(T*& ptr){ uint32_t size; FileReader::read(size); if (size==0) { ptr = 0; } else { ptr = (T*)malloc(sizeof(T)*size); for(size_t i = 0; i<size; ++i) { static_cast<Leaf*>(this)->read(ptr[i]); } } return size;}//------------------------------------------------------------------------------template <class Leaf>template <typename T>void Reader<Leaf>::readFixedArray(size_t size, T* ptr){ size_t numEntries = size / sizeof(T); for(size_t i = 0; i<numEntries; ++i) { static_cast<Leaf*>(this)->read(ptr[i]); }}//------------------------------------------------------------------------------template <class Leaf>template <typename T>uint32_t Reader<Leaf>::readLastArray(T*& ptr){ uint32_t lastByte; FileReader::read(lastByte); size_t numEntries = lastByte / sizeof(T); ptr = (T*)malloc(sizeof(T)*numEntries); for(size_t i = 0; i<numEntries; ++i) { static_cast<Leaf*>(this)->read(ptr[i]); } return lastByte;}//------------------------------------------------------------------------------template <class Leaf>inline void Reader<Leaf>::read(vm_cmd_t& cmd){ FileReader::read(cmd.bytes, sizeof(cmd.bytes));}//------------------------------------------------------------------------------template <class Leaf>inline void Reader<Leaf>::read(user_ops_t& userOperations){ FileReader::read(&userOperations, sizeof(userOperations));}//------------------------------------------------------------------------------} /* namespace ifodump *///------------------------------------------------------------------------------#endif // IFODUMP_READER_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -