예제 #1
0
파일: cvc_conv.cpp 프로젝트: diffblue/cbmc
void cvc_convt::convert_identifier(const std::string &identifier)
{
    for(std::string::const_iterator
            it=identifier.begin();
            it!=identifier.end();
            it++)
    {
        char ch=*it;

        if(isalnum(ch) || ch=='$' || ch=='?')
            out << ch;
        else if(ch==':')
        {
            std::string::const_iterator next_it(it);
            next_it++;
            if(next_it!=identifier.end() && *next_it==':')
            {
                out << "__";
                it=next_it;
            }
            else
            {
                out << '_';
                out << int(ch);
                out << '_';
            }
        }
        else
        {
            out << '_';
            out << int(ch);
            out << '_';
        }
    }
}
예제 #2
0
void
Color_component::
add(const double v, double color)
{
  if ( color > 1 ) { color = 1; }
  if ( color < 0 ) { color = 0; }
  
  Values::iterator next = next_it(v);
  values_.insert(next, std::make_pair(v,color));
}
예제 #3
0
double 
Color_component::
interpolate(const double v) const
{
  Values::const_iterator next = next_it(v);

  // next is just after v
  Values::const_iterator prev = --next;
  ++next;

  if ( v>=1 && next != values_.end())
    std::cerr << ".";
  
  if ( next == values_.end() )
  {
    return prev->second;
  }
  
  const double& a = prev->first;
  const double& b = next->first;
  return (b-v)/(b-a) * prev->second + (v-a)/(b-a) * next->second;
}
예제 #4
0
/**
* Funcion de hilo, donde se hacen las peticiones de gasolina a los servidores.
*/
void *pedir_gas() {

int respuesta, envio;          /*Tiempo de respuesta del centro y si enviara la gasolina*/
iterator it = NULL;            /*Iterador sobre la cola de prioridad*/
distr cent;                    /*Para el chequeo de la cola*/

    /*Itera sobre todos los centros hasta conseguir uno disponible*/
    for (cent = next_it(it = create_iterator(centros)); ; cent = next_it(it)) {

        /*Si ya reviso todos los elementos, volvemos a comenzar*/
        if (cent == NULL) {

            usleep(5 * MINUTO);
            it = create_iterator(centros);
            continue;
        }

        envio = conectar_centro('g', cent->puerto, cent->DNS);

        /*Si logro una conexion*/
        if (envio != -1) {
            /*Si se enviara la gasolina*/
            if (envio) {

                sem_wait(&semf);
                fprintf(out, "Peticion: %d, %s, Positiva\n", tiempo, cent->nombre);
                sem_post(&semf);
                break;
            /*Si NO se enviara la gasolina*/
            } else {

                sem_wait(&semf);
                fprintf(out, "Peticion: %d, %s, Negativa\n", tiempo, cent->nombre);
                sem_post(&semf);    
            }
        }
    }

    /*Tiempo de respuesta en llegar la gasolina*/
    respuesta = cent->pr;
    usleep(respuesta * MINUTO);

    /*Wait para accesar a 'gas' y 'pet'*/
    sem_wait(&sem);

    /*Agrega la carga del envio e indica que la peticion fue atendida*/
    gas += CARGA;
    --pet;

    sem_wait(&semf);
    fprintf(out, "Llegada de la gandola: %d, %d\n", tiempo, gas);

    /*Si el tanque se lleno*/
    if (gas == max) {

        fprintf(out, "Tanque full: %d\n", tiempo);
    }
    sem_post(&semf);

    /*Signal para liberar 'gas' y 'pet'*/
    sem_post(&sem);

    pthread_exit(NULL);
}