Esempio n. 1
0
NGS_String* SRA_StatisticsGetAsString ( const SRA_Statistics * self, ctx_t ctx, const char * path )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    
    assert ( self );
    
    if ( path == NULL )
        INTERNAL_ERROR ( xcParamNull, "path is NULL" );
    else
    {
        DictionaryEntry * node = ( DictionaryEntry * ) 
            BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind );
        if ( node == NULL )
        {
            INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path );
        }
        else
        {
            switch ( node -> type )
            {
            case NGS_StatisticValueType_UInt64: 
                {
                    char buf[1024];
                    size_t num_writ;
                    string_printf ( buf, sizeof(buf), &num_writ, "%lu", node -> value . u64 );
                    return NGS_StringMakeCopy ( ctx, buf, num_writ );
                }
                break;
                
            case NGS_StatisticValueType_Int64:  
                {
                    char buf[1024];
                    size_t num_writ;
                    string_printf ( buf, sizeof(buf), &num_writ, "%li", node -> value . i64 );
                    return NGS_StringMakeCopy ( ctx, buf, num_writ );
                }
                
            case NGS_StatisticValueType_Real:   
                {
                    char buf[1024];
                    size_t num_writ;
                    string_printf ( buf, sizeof(buf), &num_writ, "%f", node -> value . real );
                    return NGS_StringMakeCopy ( ctx, buf, num_writ );
                }
                
            case NGS_StatisticValueType_String: 
                return NGS_StringDuplicate ( node -> value . str, ctx );
                
            default :
                INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path );
                break;
            }
        }
    }
    
    return NULL;
}
Esempio n. 2
0
/* Substr
 *  create a new allocation
 *  returns a substring, either at a simple offset
 *  or at an offset with length
 */
NGS_String * NGS_StringSubstrOffset ( const NGS_String * self, ctx_t ctx, uint64_t offset )
{
    FUNC_ENTRY ( ctx, rcSRA, rcString, rcAccessing );

    if ( self == NULL )
        INTERNAL_ERROR ( xcSelfNull, "attempt to access NULL NGS_String" );
    else if ( offset == 0 )
        return NGS_StringDuplicate ( self, ctx );
    else
    {
        NGS_String * dup;

        if ( offset > ( uint64_t ) self -> size )
            offset = self -> size;

        TRY ( dup = NGS_StringMake ( ctx, self -> str + offset, self -> size - ( size_t ) offset ) )
        {
            dup -> orig = NGS_StringDuplicate ( self, ctx );
            return dup;
        }
    }
Esempio n. 3
0
void SRA_StatisticsAddString ( SRA_Statistics * self, ctx_t ctx, const char * path, const NGS_String * value )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    
    assert ( self );
    
    if ( path == NULL )
        INTERNAL_ERROR ( xcParamNull, "path is NULL" );
    else
    {
        TRY ( DictionaryEntry * node = MakeNode ( self, ctx, path ) )
        {
            node -> type = NGS_StatisticValueType_String;
            node -> value . str = NGS_StringDuplicate ( value, ctx );
        }
    }
Esempio n. 4
0
static
NGS_String * SRA_DB_ReadCollectionGetName ( SRA_DB_ReadCollection * self, ctx_t ctx )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    return NGS_StringDuplicate ( self -> run_name, ctx );
}