Commit 05e21dac authored by Steve Lhomme's avatar Steve Lhomme

libebml2: add a Copy operator to base EBML classes

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@370 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent 21820403
......@@ -137,6 +137,7 @@ typedef struct ebml_element_vmt
bool_t (*DefaultIsSet)(const void*);
filepos_t (*UpdateSize)(void*, bool_t bWithDefault, bool_t bForceRender);
int (*Cmp)(const void*, const void*);
ebml_element *(*Copy)(const void*, const void *Cookie);
// internal call only
void (*PostCreate)(void*);
......@@ -149,6 +150,7 @@ typedef struct ebml_element_vmt
#define EBML_ElementIsDefaultValue(p) VMT_FUNC(p,ebml_element_vmt)->IsDefaultValue(p)
#define EBML_ElementUpdateSize(p,k,f) VMT_FUNC(p,ebml_element_vmt)->UpdateSize(p,k,f)
#define EBML_ElementCmp(p,e) VMT_FUNC(p,ebml_element_vmt)->Cmp(p,e)
#define EBML_ElementCopy(p,c) VMT_FUNC(p,ebml_element_vmt)->Copy(p,c)
typedef struct ebml_string
{
......
......@@ -92,6 +92,22 @@ static bool_t ValidateSize(const ebml_element *p)
return EBML_ElementIsFiniteSize(p);
}
static ebml_binary *Copy(const ebml_binary *Element, const void *Cookie)
{
ebml_binary *Result = (ebml_binary*)EBML_ElementCreate(Element,Element->Base.Context,0,Cookie);
if (Result)
{
ArrayCopy(&Result->Data,&Element->Data);
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
}
return Result;
}
META_START(EBMLBinary_Class,EBML_BINARY_CLASS)
META_CLASS(SIZE,sizeof(ebml_binary))
META_CLASS(DELETE,Delete)
......@@ -103,6 +119,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
META_END(EBML_ELEMENT_CLASS)
err_t EBML_BinarySetData(ebml_binary *Element, const uint8_t *Data, size_t DataSize)
......
......@@ -355,11 +355,39 @@ static err_t RenderData(ebml_element *Element, stream *Output, bool_t bForceRend
}
#endif
static ebml_element *Copy(const ebml_element *Element, const void *Cookie)
{
ebml_element *i, *Elt;
ebml_element *Result = EBML_ElementCreate(Element,Element->Context,0,Cookie);
if (Result)
{
EBML_MasterClear(Result);
Result->bValueIsSet = Element->bValueIsSet;
Result->bDefaultIsSet = Element->bDefaultIsSet;
Result->DataSize = Element->DataSize;
Result->ElementPosition = Element->ElementPosition;
Result->SizeLength = Element->SizeLength;
Result->SizePosition = Element->SizePosition;
for (i=EBML_MasterChildren(Element);i;i=EBML_MasterNext(i))
{
Elt = EBML_ElementCopy(i,Cookie);
if (!Elt || EBML_MasterAppend(Result, Elt)!=ERR_NONE)
{
NodeDelete((node*)Result);
Result = NULL;
break;
}
}
}
return Result;
}
META_START(EBMLMaster_Class,EBML_MASTER_CLASS)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreate)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
......
......@@ -358,6 +358,37 @@ static void PostCreateFloat(ebml_element *Element)
}
}
static ebml_integer *CopyInt(const ebml_integer *Element, const void *Cookie)
{
ebml_integer *Result = (ebml_integer*)EBML_ElementCreate(Element,Element->Base.Context,0,Cookie);
if (Result)
{
Result->Value = Element->Value;
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
}
return Result;
}
static ebml_float *CopyFloat(const ebml_float *Element, const void *Cookie)
{
ebml_float *Result = (ebml_float*)EBML_ElementCreate(Element,Element->Base.Context,0,Cookie);
if (Result)
{
Result->Value = Element->Value;
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
}
return Result;
}
META_START(EBMLInteger_Class,EBML_INTEGER_CLASS)
META_CLASS(SIZE,sizeof(ebml_integer))
......@@ -369,6 +400,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataInt)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,CopyInt)
META_END_CONTINUE(EBML_ELEMENT_CLASS)
META_START_CONTINUE(EBML_SINTEGER_CLASS)
......@@ -381,6 +413,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataSignedInt)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,CopyInt)
META_END_CONTINUE(EBML_ELEMENT_CLASS)
META_START_CONTINUE(EBML_BOOLEAN_CLASS)
......@@ -396,6 +429,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeFloat)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataFloat)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,CopyFloat)
META_END(EBML_ELEMENT_CLASS)
err_t EBML_IntegerSetValue(ebml_integer *Element, int64_t Value)
......
......@@ -191,6 +191,22 @@ static void PostCreateUniString(ebml_element *Element)
}
}
static ebml_string *Copy(const ebml_string *Element, const void *Cookie)
{
ebml_string *Result = (ebml_string*)EBML_ElementCreate(Element,Element->Base.Context,0,Cookie);
if (Result)
{
Result->Buffer = strdup(Element->Buffer);
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
}
return Result;
}
META_START(EBMLString_Class,EBML_STRING_CLASS)
META_CLASS(SIZE,sizeof(ebml_string))
META_CLASS(DELETE,Delete)
......@@ -201,6 +217,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateString)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
META_END_CONTINUE(EBML_ELEMENT_CLASS)
META_START_CONTINUE(EBML_UNISTRING_CLASS)
......@@ -213,4 +230,5 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateUniString)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
META_END(EBML_ELEMENT_CLASS)
......@@ -62,6 +62,21 @@ static err_t RenderData(ebml_element *Element, stream *Output, bool_t bForceRend
}
#endif
static ebml_element *Copy(const ebml_element *Element, const void *Cookie)
{
ebml_element *Result = EBML_ElementCreate(Element,Element->Context,0,Cookie);
if (Result)
{
Result->bValueIsSet = Element->bValueIsSet;
Result->bDefaultIsSet = Element->bDefaultIsSet;
Result->DataSize = Element->DataSize;
Result->ElementPosition = Element->ElementPosition;
Result->SizeLength = Element->SizeLength;
Result->SizePosition = Element->SizePosition;
}
return Result;
}
META_START(EBMLVoid_Class,EBML_VOID_CLASS)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
......@@ -69,6 +84,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
META_END(EBML_ELEMENT_CLASS)
#if defined(CONFIG_EBML_WRITING)
......
......@@ -3,7 +3,7 @@
GROUP ebml2_group
{
PROJECT_NAME "libebml2"
PROJECT_VERSION 0.9.7
PROJECT_VERSION 0.9.8
PROJECT_VENDOR "Matroska Foundation"
EXPDEFINE HAS_EBML2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment