Skip to content
Snippets Groups Projects
Commit 76e06eec authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

NodeFragment: added remove_attr methods

Two alternatives are provided: remove_attr and pop_attr. While the
former free's the Attr's data, the latter allocates a new Attr, to store
and return the data. Both functionality is provided by a single
(internal) static method.
parent 29c275e5
No related branches found
No related tags found
No related merge requests found
......@@ -43,8 +43,8 @@ FILE_NAME_10=1550;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_11=1562;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment.h;0;8
FILE_NAME_12=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_data.c;0;8
FILE_NAME_13=2558;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8
FILE_NAME_14=20283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8
FILE_NAME_15=6032;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_14=23169;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8
FILE_NAME_15=6811;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_16=5204;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_17=3030;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_18=3044;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_static.c;0;8
......@@ -63,7 +63,7 @@ FILE_NAME_30=555;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2
FILE_NAME_31=218;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Fno_test.sh.in;0;8
FILE_NAME_32=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_33=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_34=34187;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_34=109525;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_35=15195;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_36=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_37=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
......
......@@ -898,6 +898,130 @@ SH_NodeFragment_append_attr_copy (struct SH_NodeFragment * fragment,
status);
}
static inline
bool
remove_attr (struct SH_NodeFragment * fragment, size_t position,
/*@out@*/ /*@null@*/ SH_Attr * attr_ptr,
/*@out@*/ /*@null@*/ struct SH_Status * status)
/*@modifies fragment->attrs@*/
/*@modifies fragment->attr_s@*/
/*@modifies fragment->attr_n@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
size_t index;
size_t new_size;
typeof (fragment->attrs) new_attrs;
SH_Attr attr;
Attr_move (&attr, &(fragment->attrs[position]));
for (index = position+1; index < fragment->attr_n; index++)
{
fragment->attrs[index-1] = fragment->attrs[index];
}
new_size = get_attr_alloc_size (fragment->attr_n - 1);
if (new_size < fragment->attr_s)
{
new_attrs = realloc (fragment->attrs, new_size
* sizeof (*new_attrs));
if ((0 != new_size) && (NULL == new_attrs))
{
for (index = fragment->attr_n-1;
index > position;
index--)
{
fragment->attrs[index] =
fragment->attrs[index-1];
}
fragment->attrs[position] = attr;
set_status (status, E_ALLOC, 4,
"realloc failed.\n");
return FALSE;
}
fragment->attrs = new_attrs;
fragment->attr_s = new_size;
}
fragment->attr_n--;
if (NULL == attr_ptr)
{
Attr_free (&attr);
}
else
{
*attr_ptr = attr;
}
set_success (status);
return TRUE;
}
bool
SH_NodeFragment_remove_attr (struct SH_NodeFragment * fragment,
size_t position,
/*@out@*/ /*@null@*/
struct SH_Status * status)
/*@modifies fragment->attrs@*/
/*@modifies fragment->attr_s@*/
/*@modifies fragment->attr_n@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
if (position >= fragment->attr_n)
{
set_status (status, E_VALUE, 2,
"index out of range.\n");
return FALSE;
}
return remove_attr (fragment, position, NULL, status);
}
/*@null@*/
/*@only@*/
SH_Attr *
SH_NodeFragment_pop_attr (struct SH_NodeFragment * fragment,
size_t position,
/*@out@*/ /*@null@*/
struct SH_Status * status)
/*@modifies fragment->attrs@*/
/*@modifies fragment->attr_s@*/
/*@modifies fragment->attr_n@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
SH_Attr * attr;
if (position >= fragment->attr_n)
{
set_status (status, E_VALUE, 2,
"index out of range.\n");
return NULL;
}
attr = malloc (sizeof (SH_Attr));
if (NULL == attr)
{
set_status (status, E_ALLOC, 3, "malloc failed");
return NULL;
}
if (!remove_attr (fragment, position, attr, status))
{
return NULL;
}
return attr;
}
size_t
SH_NodeFragment_count_childs (const struct SH_NodeFragment * fragment)
/*@*/
......
......@@ -197,6 +197,28 @@ SH_NodeFragment_append_attr_copy (SH_NodeFragment * fragment,
/*@modifies fileSystem@*/
/*@modifies status@*/;
bool
SH_NodeFragment_remove_attr (SH_NodeFragment * fragment,
size_t position,
/*@out@*/ /*@null@*/
struct SH_Status * status)
/*@modifies fragment@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/;
/*@null@*/
/*@only@*/
SH_Attr *
SH_NodeFragment_pop_attr (SH_NodeFragment * fragment,
size_t position,
/*@out@*/ /*@null@*/
struct SH_Status * status)
/*@modifies fragment@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/;
/*@null@*/
/*@only@*/
char *
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment