Exemplo n.º 1
0
/***********************************************************************
 * The converter functions
 **********************************************************************/
convert::function_type convert::get_converter(
    const id_type &id,
    const priority_type prio
){
    if (not get_table().has_key(id)) throw uhd::key_error(
        "Cannot find a conversion routine for " + id.to_pp_string());

    //find a matching priority
    priority_type best_prio = -1;
    for(priority_type prio_i:  get_table()[id].keys()){
        if (prio_i == prio) {
            //----------------------------------------------------------------//
            UHD_LOGGER_DEBUG("CONVERT") << "get_converter: For converter ID: " << id.to_pp_string()
                                        << " Using prio: " << prio;
            ;
            //----------------------------------------------------------------//
            return get_table()[id][prio];
        }
        best_prio = std::max(best_prio, prio_i);
    }

    //wanted a specific prio, didnt find
    if (prio != -1) throw uhd::key_error(
        "Cannot find a conversion routine [with prio] for " + id.to_pp_string());

    //----------------------------------------------------------------//
    UHD_LOGGER_DEBUG("CONVERT") << "get_converter: For converter ID: " << id.to_pp_string()
                                << " Using prio: " << best_prio;
    //----------------------------------------------------------------//

    //otherwise, return best prio
    return get_table()[id][best_prio];
}
Exemplo n.º 2
0
/***********************************************************************
 * The registry functions
 **********************************************************************/
void shd::convert::register_converter(
    const id_type &id,
    const function_type &fcn,
    const priority_type prio
){
    //get a reference to the function table
    fcn_table_type &table = get_table();

    //register the function if higher priority
    if (not table.has_key(id) or table[id].prio < prio){
        table[id].fcn = fcn;
        table[id].prio = prio;
    }

    //----------------------------------------------------------------//
    SHD_LOGV(always) << "register_converter: " << id.to_pp_string() << std::endl
        << "    prio: " << prio << std::endl
        << std::endl
    ;
    //----------------------------------------------------------------//
}
Exemplo n.º 3
0
/***********************************************************************
 * The converter functions
 **********************************************************************/
convert::function_type convert::get_converter(const id_type &id){
    if (get_table().has_key(id)) return get_table()[id].fcn;
    throw shd::key_error("Cannot find a conversion routine for " + id.to_pp_string());
}