add a macro to define all the pure virtual methods in a "concrete" EBML class (that correspond to an item in EBML streams)

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@16 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
Steve Lhomme
2010-03-15 16:11:24 +00:00
parent de3185abde
commit 89abd52a34
6 changed files with 30 additions and 61 deletions

View File

@@ -56,20 +56,15 @@ class EBML_DLL_API EbmlCrc32 : public EbmlBinary {
public:
EbmlCrc32();
EbmlCrc32(const EbmlCrc32 & ElementToClone);
static EbmlElement & Create() {return *(new EbmlCrc32);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
bool ValidateSize() const {return (GetSize() == 4);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
// uint64 UpdateSize(bool bKeepIntact = false);
static const EbmlCallbacks ClassInfos;
bool IsDefaultValue() const {
return false;
}
operator const EbmlId &() const {return ClassInfos.GlobalId;}
void AddElementCRC32(EbmlElement &ElementToCRC);
bool CheckElementCRC32(EbmlElement &ElementToCRC);
@@ -104,8 +99,6 @@ class EBML_DLL_API EbmlCrc32 : public EbmlBinary {
void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; SetValueIsSet();}
EbmlElement * Clone() const;
protected:
void ResetCRC() {m_crc = CRC32_NEGL;}
void UpdateByte(binary b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
@@ -113,6 +106,8 @@ class EBML_DLL_API EbmlCrc32 : public EbmlBinary {
static const uint32 m_tab[256];
uint32 m_crc;
uint32 m_crc_final;
EBML_CONCRETE_CLASS(EbmlCrc32)
};
template <class T>

View File

@@ -45,20 +45,16 @@ class EBML_DLL_API EbmlDummy : public EbmlBinary {
EbmlDummy() :DummyId(DummyRawId) {}
EbmlDummy(const EbmlId & aId) :EbmlBinary(), DummyId(aId) {}
EbmlDummy(const EbmlDummy & ElementToClone):EbmlBinary(ElementToClone), DummyId(ElementToClone.DummyId) {}
static EbmlElement & Create() {return *(new EbmlDummy);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return DummyId;}
bool ValidateSize() const {return true;}
bool IsDummy() const {return true;}
bool IsDefaultValue() const {return true;}
EbmlElement * Clone() const {return new EbmlDummy(*this);}
protected:
const EbmlId DummyId;
static const EbmlId DummyRawId;
EBML_CONCRETE_CLASS(EbmlDummy)
};
END_LIBEBML_NAMESPACE

View File

@@ -144,6 +144,15 @@ class EBML_DLL_API EbmlSemanticContext {
const EbmlCallbacks *MasterElt;
};
#define EBML_CONCRETE_CLASS(Type) \
public: \
virtual const EbmlCallbacks & Generic() const {return ClassInfos;} \
virtual operator const EbmlId &() const {return ClassInfos.GlobalId;} \
virtual EbmlElement & CreateElement() const {return Create();} \
virtual EbmlElement * Clone() const { return new Type(*this); } \
static EbmlElement & Create() {return *(new Type);} \
static const EbmlCallbacks ClassInfos; \
#define EBML_INFO(ref) ref::ClassInfos
#define EBML_ID(ref) ref::ClassInfos.GlobalId
#define EBML_CONTEXT(e) e->Generic().Context
@@ -181,6 +190,7 @@ class EBML_DLL_API EbmlElement {
virtual operator const EbmlId &() const = 0;
/// return the generic callback to monitor a derived class
virtual const EbmlCallbacks & Generic() const = 0;
virtual EbmlElement & CreateElement() const = 0;
// by default only allow to set element as finite (override when needed)
virtual bool SetSizeInfinite(bool bIsInfinite = true) {return !bIsInfinite;}

View File

@@ -45,13 +45,8 @@ class EBML_DLL_API EbmlHead : public EbmlMaster {
public:
EbmlHead();
EbmlHead(const EbmlHead & ElementToClone) : EbmlMaster(ElementToClone) {}
static EbmlElement & Create() {return *(new EbmlHead);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
bool IsYourId(const EbmlId & TestId) const;
EbmlElement * Clone() const {return new EbmlHead(*this);}
EBML_CONCRETE_CLASS(EbmlHead)
};
END_LIBEBML_NAMESPACE

View File

@@ -47,77 +47,56 @@ class EBML_DLL_API EVersion : public EbmlUInteger {
public:
EVersion() :EbmlUInteger(1) {}
EVersion(const EVersion & ElementToClone) : EbmlUInteger(ElementToClone) {}
static EbmlElement & Create() {return *(new EVersion);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EVersion(*this);}
EBML_CONCRETE_CLASS(EVersion)
};
class EBML_DLL_API EReadVersion : public EbmlUInteger {
public:
EReadVersion() :EbmlUInteger(1) {}
EReadVersion(const EReadVersion & ElementToClone) : EbmlUInteger(ElementToClone) {}
static EbmlElement & Create() {return *(new EReadVersion);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EReadVersion(*this);}
EBML_CONCRETE_CLASS(EReadVersion)
};
class EBML_DLL_API EMaxIdLength : public EbmlUInteger {
public:
EMaxIdLength() :EbmlUInteger(4) {}
EMaxIdLength(const EMaxIdLength & ElementToClone) : EbmlUInteger(ElementToClone) {}
static EbmlElement & Create() {return *(new EMaxIdLength);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EMaxIdLength(*this);}
EBML_CONCRETE_CLASS(EMaxIdLength)
};
class EBML_DLL_API EMaxSizeLength : public EbmlUInteger {
public:
EMaxSizeLength() :EbmlUInteger(8) {}
EMaxSizeLength(const EMaxSizeLength & ElementToClone) : EbmlUInteger(ElementToClone) {}
static EbmlElement & Create() {return *(new EMaxSizeLength);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EMaxSizeLength(*this);}
EBML_CONCRETE_CLASS(EMaxSizeLength)
};
class EBML_DLL_API EDocType : public EbmlString {
public:
EDocType() {}
EDocType(const EDocType & ElementToClone) : EbmlString(ElementToClone) {}
static EbmlElement & Create() {return *(new EDocType);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EDocType(*this);}
EBML_CONCRETE_CLASS(EDocType)
};
class EBML_DLL_API EDocTypeVersion : public EbmlUInteger {
public:
EDocTypeVersion() {}
EDocTypeVersion(const EDocTypeVersion & ElementToClone) : EbmlUInteger(ElementToClone) {}
static EbmlElement & Create() {return *(new EDocTypeVersion);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EDocTypeVersion(*this);}
EBML_CONCRETE_CLASS(EDocTypeVersion)
};
class EBML_DLL_API EDocTypeReadVersion : public EbmlUInteger {
public:
EDocTypeReadVersion() {}
EDocTypeReadVersion(const EDocTypeReadVersion & ElementToClone) : EbmlUInteger(ElementToClone) {}
static EbmlElement & Create() {return *(new EDocTypeReadVersion);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
EbmlElement * Clone() const {return new EDocTypeReadVersion(*this);}
EBML_CONCRETE_CLASS(EDocTypeReadVersion)
};
END_LIBEBML_NAMESPACE

View File

@@ -45,13 +45,7 @@ class EBML_DLL_API EbmlVoid : public EbmlBinary {
public:
EbmlVoid();
EbmlVoid(const EbmlVoid & ElementToClone) :EbmlBinary(ElementToClone){}
static EbmlElement & Create() {return *(new EbmlVoid);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
bool ValidateSize() const {return true;} // any void element is accepted
static const EbmlCallbacks ClassInfos;
operator const EbmlId &() const {return ClassInfos.GlobalId;}
bool IsYourId(const EbmlId & TestId) const;
/*!
\brief Set the size of the data (not the complete size of the element)
@@ -73,7 +67,7 @@ class EBML_DLL_API EbmlVoid : public EbmlBinary {
*/
uint64 Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward = true, bool bKeepIntact = false);
EbmlElement * Clone() const {return new EbmlVoid(*this);}
EBML_CONCRETE_CLASS(EbmlVoid)
};
END_LIBEBML_NAMESPACE