33 lines
1.5 KiB
C
33 lines
1.5 KiB
C
|
|
#include "project_internal.h"
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
xtc_result xtc_project_marker_count(const xtc_project *p,size_t *out)
|
||
|
|
{
|
||
|
|
if(!p || !out)return XTC_ERR_INVALID_ARGUMENT;
|
||
|
|
*out=p->marker_count;return XTC_OK;
|
||
|
|
}
|
||
|
|
xtc_result xtc_project_get_marker(const xtc_project *p,size_t index,xtc_marker *out)
|
||
|
|
{
|
||
|
|
if(!p || !out)return XTC_ERR_INVALID_ARGUMENT;
|
||
|
|
if(index>=p->marker_count)return XTC_ERR_NOT_FOUND;
|
||
|
|
*out=p->markers[index];return XTC_OK;
|
||
|
|
}
|
||
|
|
xtc_result xtc_project_set_marker(xtc_project *p,uint64_t tick,const char *name)
|
||
|
|
{
|
||
|
|
size_t i;xtc_marker marker;
|
||
|
|
if(!p || tick>XTC_PROJECT_MAX_TICK || !xtc_project_valid_name(name))return XTC_ERR_INVALID_ARGUMENT;
|
||
|
|
memset(&marker,0,sizeof(marker));marker.tick=tick;memcpy(marker.name,name,strlen(name)+1);
|
||
|
|
for(i=0;i<p->marker_count && p->markers[i].tick<tick;++i){}
|
||
|
|
if(i<p->marker_count && p->markers[i].tick==tick){p->markers[i]=marker;return XTC_OK;}
|
||
|
|
if(p->marker_count==XTC_PROJECT_MAX_MARKERS)return XTC_ERR_CAPACITY;
|
||
|
|
memmove(p->markers+i+1,p->markers+i,(p->marker_count-i)*sizeof(marker));
|
||
|
|
p->markers[i]=marker;++p->marker_count;return XTC_OK;
|
||
|
|
}
|
||
|
|
xtc_result xtc_project_remove_marker(xtc_project *p,uint64_t tick)
|
||
|
|
{
|
||
|
|
size_t i;if(!p)return XTC_ERR_INVALID_ARGUMENT;
|
||
|
|
for(i=0;i<p->marker_count;++i)if(p->markers[i].tick==tick)break;
|
||
|
|
if(i==p->marker_count)return XTC_ERR_NOT_FOUND;
|
||
|
|
memmove(p->markers+i,p->markers+i+1,(p->marker_count-i-1)*sizeof(*p->markers));
|
||
|
|
--p->marker_count;return XTC_OK;
|
||
|
|
}
|