Example #1
0
bool Value::isConvertibleTo(ValueType other) const {
  switch (other) {
  case nullValue:
    return (isNumeric() && asDouble() == 0.0) ||
           (type_ == booleanValue && value_.bool_ == false) ||
           (type_ == stringValue && asString() == "") ||
           (type_ == arrayValue && value_.map_->size() == 0) ||
           (type_ == objectValue && value_.map_->size() == 0) ||
           type_ == nullValue;
  case intValue:
    return isInt() ||
           (type_ == realValue && InRange(value_.real_, minInt, maxInt)) ||
           type_ == booleanValue || type_ == nullValue;
  case uintValue:
    return isUInt() ||
           (type_ == realValue && InRange(value_.real_, 0, maxUInt)) ||
           type_ == booleanValue || type_ == nullValue;
  case realValue:
    return isNumeric() || type_ == booleanValue || type_ == nullValue;
  case booleanValue:
    return isNumeric() || type_ == booleanValue || type_ == nullValue;
  case stringValue:
    return isNumeric() || type_ == booleanValue || type_ == stringValue ||
           type_ == nullValue;
  case arrayValue:
    return type_ == arrayValue || type_ == nullValue;
  case objectValue:
    return type_ == objectValue || type_ == nullValue;
  }
  JSON_ASSERT_UNREACHABLE;
  return false;
}
Example #2
0
bool Value::isIntegral() const {
#if defined(JSON_HAS_INT64)
  return isInt64() || isUInt64();
#else
  return isInt() || isUInt();
#endif
}
Example #3
0
RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, uint32_t* roomId)
{
	MS_TRACE();

	static const Json::StaticString k_roomId("roomId");

	auto json_roomId = request->internal[k_roomId];

	if (!json_roomId.isUInt())
		MS_THROW_ERROR("Request has not numeric internal.roomId");

	// If given, fill roomId.
	if (roomId)
		*roomId = json_roomId.asUInt();

	auto it = this->rooms.find(json_roomId.asUInt());
	if (it != this->rooms.end())
	{
		RTC::Room* room = it->second;

		return room;
	}
	else
	{
		return nullptr;
	}
}
Example #4
0
Value::UInt Value::asUInt() const {
  switch (type_) {
  case intValue:
    JSON_ASSERT_MESSAGE(isUInt(), "LargestInt out of UInt range");
    return UInt(value_.int_);
  case uintValue:
    JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range");
    return UInt(value_.uint_);
  case realValue:
    JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt),
                        "double out of UInt range");
    return UInt(value_.real_);
  case nullValue:
    return 0;
  case booleanValue:
    return value_.bool_ ? 1 : 0;
  default:
    break;
  }
  JSON_FAIL_MESSAGE("Value is not convertible to UInt.");
}
Example #5
0
void clientei_remove(MainTreePt clientes){
    unsigned int nif;
    ClientePt tmp=NULL;
    printf("NIF do cliente > ");
    while( isUInt(nif = readUInt()) == 0 )
        printf("Erro: NIF inválido.");
    
    tmp = cliente_novo( nif, NULL, NULL, NULL );

    tree_remove(clientes, tmp, 0);
    free(tmp);
    printf("Foi removido\n");
}
Example #6
0
void clientei_modifica(MainTreePt clientes){
    char *morada=NULL;
    unsigned int nif;

    printf("Introduza o nif do cliente > ");
    while( isUInt( nif = readUInt() ) == 0 )
        printf("Número inválido.");

    printf("Introduza a nova morada > ");
    lerStr( &morada );


    cliente_substituiPeloNif( clientes, nif, morada );
    printf("Modificado!\n");
}
Example #7
0
void clientei_insere(MainTreePt clientes){
    unsigned int nif;
    char *nome=NULL, *morada=NULL;

    printf("NIF > ");
    while( isUInt(nif = readUInt()) == 0 )
        printf("Erro: Valor inválido (veja as instruções acima)"); //erro

    printf("Nome > ");
    lerStr( &nome);
    
    printf("Morada > ");
    lerStr( &morada );

        if( tree_insert( clientes, cliente_novo(nif, nome, morada, criaListaLigada( cliente_comparaServico )) ) == 1 )
            printf("Dados introduzidos com sucesso!");
        else
            printf("Já existe um Cliente com esse NIF ou Nome");
}
Example #8
0
void insereServicoInput(TabelaHashPTR localidades, MainTreePt clientesPt, MainTreePt camioes)
{
    char *localidadeorigem, *localidadedestino, *inserir;
    int nif;CamiaoPt camiao;
    LocalidadePTR localidadeA, localidadeB;

    printf("\nIntroduza o NIF do Cliente > ");
    while( isUInt (nif=readUInt())==0);
    printf("Introduza a localidade de carregamento da carga > ");
    lerStr(&localidadeorigem);
    printf("Introduza a localidade de descarregamento da carga > ");
    lerStr(&localidadedestino);

    if(((localidadeA=(crialocalidade(localidadeorigem)))==NULL)||((localidadeB=(crialocalidade(localidadedestino)))==NULL))
    {
       errorMessage(ERROR_MEMALOC);
       freeLocalidade(localidadeA);freeLocalidade(localidadeB);
       return;
    }
    if((procuraTabelaHash(localidades, localidadeA)==NULL)||(procuraTabelaHash(localidades, localidadeB)==NULL))
    {
    freeLocalidade(localidadeA);freeLocalidade(localidadeB);
       errorMessage(ERROR_LOCNOTEXIST);
       return;
    }
    if ((camiao= (CamiaoPt)camiaoMaisBarato(camioes, localidadeorigem ))==NULL) {errorMessage(ERROR_NOCAMLOC); return;}
    double custo = costCheapestPath(localidades, localidadeorigem, localidadedestino, 1);
    if (custo==-1) {errorMessage(ERROR_NOPATH);return;}
    printf("\nCusto transporte: %.2f€\nPretende registar o seviços? (sim ou [NAO]) > ", custo);
    lerStr(&inserir);
    if((strcmp(inserir,"SIM")==0)||(strcmp(inserir,"Sim")==0)||(strcmp(inserir,"sim")==0)) {
    switch(cliente_insereServico(clientesPt, nif, camiao->matricula, custo, 0, localidadeorigem,"", localidadedestino)){
        case -2: errorMessage(ERROR_MEMALOC); break;
        case 0:  errorMessage(ERROR_MEMALOC);break; 
        case -1:  errorMessage(ERROR_MEMALOC);break;
        case 1: errorMessage(ERROR_SUCCESS);
    }} 
    else errorMessage(ERROR_CANCEL);
    freeLocalidade(localidadeA);freeLocalidade(localidadeB);
}
Example #9
0
void camiaoi_insere(MainTreePt camioes, TabelaHashPTR localidades){
    unsigned int id;
    char *matricula=NULL, *local=NULL, vazia[1]={'\0'};
    LocalidadePTR aux_local=NULL;
    double custo, peso;

    printf("Introduza o ID > ");
    while( isUInt(id = readUInt()) == 0 )
        printf("Erro: Valor inválido (veja as instruções acima)"); //erro

    printf("Introduza a matrícula > ");
    lerStr( &matricula);
    printf("Custo (por Km) > ");
    if( isDouble(custo = readDouble()) == 0 )
        printf("Erro: Valor inválido (veja as instruções acima)"); //erro
    printf("Peso máximo da carga > ");
    if( isDouble(peso = readDouble()) == 0 )
        printf("Erro: Valor inválido (veja as instruções acima)"); //erro
    
    printf("Localidade actual > ");
    lerStr( &local );

    while( (procuraTabelaHash( localidades, aux_local = crialocalidade(local) ) ) == NULL && strcmp(local,vazia) != 0 ){
        printf("Erro: Localidade não foi encontrada. Para cancelar apenas pressione [ENTER].\nLocalidade actual > ");
        free(aux_local);
        lerStr( &local );
    }
    if( strcmp(local,vazia) == 0 ){
        printf("Cancelou a introdução.\n");
        free(matricula);
        free(local);
    }else
        if( tree_insert( camioes, camiao_novo(id, matricula, custo, peso, local) ) == 1 )
            printf("Dados introduzidos com sucesso!");
        else
            printf("Já existe um Camião com esse ID ou Matrícula");
}
Example #10
0
void servicosi_lista(MainTreePt clientes){
    unsigned int nif;
    TreePt cliente = NULL;
    ClientePt caux=NULL;
    LinkedListPTR list = NULL;
    ServicoPt servico = NULL;
    printf("Introduza o nif do cliente > ");
    while( isUInt( nif = readUInt() ) == 0 )
        printf("Número inválido");
    
    caux = cliente_novo( nif, NULL, NULL, NULL );
    cliente = tree_search( clientes, caux, 0);
    free(caux);
    
    if( cliente == NULL ) return;
    
    if( ((ClientePt)cliente->node)->servicos->nelems == 0 ){
        printf("O cliente não tem histórico de serviços anteriores.");
        return;
    }

    list = ((ClientePt)cliente->node)->servicos->elems;
    printf("[AAAA-MM-DD hh:mm:ss] Matrícula  Peso  Custo  <Origem> <Carga> <Destino>\n");
    while( list ){
        servico = (ServicoPt)list->extdata;
        printf("[%s] %s %gKg %g€ <%s> <%s> <%s>\n",
                servico->datahora,
                servico->camiao,
                servico->peso,
                servico->custo,
                servico->origem,
                servico->carga,
                servico->destino);
        list = list->prox;
    }
}
Example #11
0
uint Parser::getUIntToken() {
  string token;
  if (!(isUInt(token = getToken()))) throw UnexpectedInputException(filename, line_num, line_pos, token, "type uint");
  return atoi(token.c_str());
}
Example #12
0
const pyuint* pybase::asUInt() const {
	assert(isUInt());
	return (reinterpret_cast<const pyuint*>(this));
}