reordering and misc cleaning
git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@9 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
parent
02bd471dcf
commit
377e111038
@ -58,61 +58,61 @@ enum endianess {
|
||||
template<class TYPE, endianess ENDIAN> class Endian
|
||||
{
|
||||
public:
|
||||
Endian() {}
|
||||
Endian() {}
|
||||
|
||||
Endian(const TYPE value)
|
||||
{
|
||||
memcpy(&platform_value, &value, sizeof(TYPE));
|
||||
process_endian();
|
||||
}
|
||||
Endian(const TYPE value)
|
||||
{
|
||||
memcpy(&platform_value, &value, sizeof(TYPE));
|
||||
process_endian();
|
||||
}
|
||||
|
||||
inline Endian & Eval(const binary *endian_buffer)
|
||||
{
|
||||
//endian_value = *(TYPE *)(endian_buffer);
|
||||
memcpy(&endian_value, endian_buffer, sizeof(TYPE)); // Some (all?) RISC processors do not allow reading objects bigger than 1 byte from non-aligned addresses, and endian_buffer may point to a non-aligned address.
|
||||
process_platform();
|
||||
return *this;
|
||||
}
|
||||
inline Endian & Eval(const binary *endian_buffer)
|
||||
{
|
||||
//endian_value = *(TYPE *)(endian_buffer);
|
||||
memcpy(&endian_value, endian_buffer, sizeof(TYPE)); // Some (all?) RISC processors do not allow reading objects bigger than 1 byte from non-aligned addresses, and endian_buffer may point to a non-aligned address.
|
||||
process_platform();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Fill(binary *endian_buffer) const
|
||||
{
|
||||
//*(TYPE*)endian_buffer = endian_value;
|
||||
memcpy(endian_buffer, &endian_value, sizeof(TYPE)); // See above.
|
||||
}
|
||||
inline void Fill(binary *endian_buffer) const
|
||||
{
|
||||
//*(TYPE*)endian_buffer = endian_value;
|
||||
memcpy(endian_buffer, &endian_value, sizeof(TYPE)); // See above.
|
||||
}
|
||||
|
||||
inline operator const TYPE&() const { return platform_value; }
|
||||
// inline TYPE endian() const { return endian_value; }
|
||||
inline const TYPE &endian() const { return endian_value; }
|
||||
inline size_t size() const { return sizeof(TYPE); }
|
||||
inline bool operator!=(const binary *buffer) const {return *((TYPE*)buffer) == platform_value;}
|
||||
inline operator const TYPE&() const { return platform_value; }
|
||||
// inline TYPE endian() const { return endian_value; }
|
||||
inline const TYPE &endian() const { return endian_value; }
|
||||
inline size_t size() const { return sizeof(TYPE); }
|
||||
inline bool operator!=(const binary *buffer) const {return *((TYPE*)buffer) == platform_value;}
|
||||
|
||||
protected:
|
||||
TYPE platform_value;
|
||||
TYPE endian_value;
|
||||
TYPE platform_value;
|
||||
TYPE endian_value;
|
||||
|
||||
inline void process_endian()
|
||||
{
|
||||
endian_value = platform_value;
|
||||
inline void process_endian()
|
||||
{
|
||||
endian_value = platform_value;
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
if (ENDIAN == little_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
|
||||
if (ENDIAN == little_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
|
||||
#else // _ENDIANESS_
|
||||
if (ENDIAN == big_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
|
||||
if (ENDIAN == big_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
|
||||
#endif // _ENDIANESS_
|
||||
}
|
||||
}
|
||||
|
||||
inline void process_platform()
|
||||
{
|
||||
platform_value = endian_value;
|
||||
inline void process_platform()
|
||||
{
|
||||
platform_value = endian_value;
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
if (ENDIAN == little_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
|
||||
if (ENDIAN == little_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
|
||||
#else // _ENDIANESS_
|
||||
if (ENDIAN == big_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
|
||||
if (ENDIAN == big_endian)
|
||||
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
|
||||
#endif // _ENDIANESS_
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
END_LIBEBML_NAMESPACE
|
||||
|
@ -45,9 +45,6 @@ START_LIBEBML_NAMESPACE
|
||||
*/
|
||||
class EBML_DLL_API EbmlId {
|
||||
public:
|
||||
uint32 Value;
|
||||
unsigned int Length;
|
||||
|
||||
EbmlId(const binary aValue[4], const unsigned int aLength)
|
||||
:Length(aLength)
|
||||
{
|
||||
@ -77,6 +74,9 @@ class EBML_DLL_API EbmlId {
|
||||
Buffer[i] = (Value >> (8*(Length-i-1))) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 Value;
|
||||
size_t Length;
|
||||
};
|
||||
|
||||
END_LIBEBML_NAMESPACE
|
||||
|
@ -60,7 +60,7 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement {
|
||||
/*!
|
||||
Set the default size of the integer (usually 1,2,4 or 8)
|
||||
*/
|
||||
void SetDefaultSize(const int nDefaultSize = DEFAULT_INT_SIZE) {Size = nDefaultSize;}
|
||||
void SetDefaultSize(int nDefaultSize = DEFAULT_INT_SIZE) {Size = nDefaultSize;}
|
||||
|
||||
bool ValidateSize() const {return (Size <= 8);}
|
||||
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
|
||||
@ -76,7 +76,7 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement {
|
||||
|
||||
void SetDefaultValue(int64 aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
|
||||
|
||||
const int64 DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
|
||||
int64 DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
|
||||
|
||||
bool IsDefaultValue() const {
|
||||
return (DefaultISset() && Value == DefaultValue);
|
||||
|
@ -61,6 +61,7 @@ class EBML_DLL_API EbmlStream {
|
||||
EbmlElement * FindNextElement(const EbmlSemanticContext & Context, int & UpperLevel, const uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
|
||||
|
||||
inline IOCallback & I_O() {return Stream;}
|
||||
operator IOCallback &() {return Stream;}
|
||||
|
||||
protected:
|
||||
IOCallback & Stream;
|
||||
|
Loading…
x
Reference in New Issue
Block a user