예제 #1
0
void camiaoi_modifica(MainTreePt camioes, TabelaHashPTR localidades){
    char *matricula=NULL, *local=NULL, vazia[1]={'\0'};
    LinkedListPTR localidade=NULL;
    double custo, peso;

    printf("Introduza a matricula do camiao a modificar > ");
    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( (localidade = procuraTabelaHash( localidades, crialocalidade(local) ) ) == NULL && strcmp(local,vazia) != 0 ){
        printf("Erro: Localidade não foi encontrada. Para cancelar apenas pressione [ENTER].\nLocalidade actual > ");
        lerStr( &local );
    }
    free(localidade);
    if( strcmp(local,vazia) == 0 ){
        printf("Cancelou a introdução.\n");
        free(matricula);
        free(local);
    }else{
        camiao_substituiPelaMatricula( camioes, matricula, custo, peso, local );
        printf("Modificado!");
    }
}
예제 #2
0
void TScannerParameters::loadData(TIStream &is) {
  std::string tagName;
  while (is.matchTag(tagName)) {
    if (tagName == "dpi") {
      std::string s                  = is.getTagAttribute("value");
      if (isDouble(s)) m_dpi.m_value = std::stof(s);
    } else if (tagName == "brightness") {
      std::string s                         = is.getTagAttribute("value");
      if (isDouble(s)) m_brightness.m_value = std::stof(s);
    } else if (tagName == "threshold") {
      std::string s                        = is.getTagAttribute("value");
      if (isDouble(s)) m_threshold.m_value = std::stof(s);
    } else if (tagName == "contrast") {
      std::string s                       = is.getTagAttribute("value");
      if (isDouble(s)) m_contrast.m_value = std::stof(s);
    } else if (tagName == "autoFeeder") {
      m_paperFeeder.m_value = 1.0;
    } else if (tagName == "reverseOrder") {
      m_reverseOrder = true;
    } else if (tagName == "mode") {
      std::string scanTypeString = is.getTagAttribute("value");
      m_scanType                 = None;
      if (scanTypeString == BlackAndWhite)
        m_scanType = BW;
      else if (scanTypeString == Graytones)
        m_scanType = GR8;
      else if (scanTypeString == Rgbcolors)
        m_scanType = RGB24;
    } else if (tagName == "paper") {
      std::string paperFormat = is.getTagAttribute("fmt");
      if (paperFormat != "") setPaperFormat(paperFormat);
    }
  }
  m_validatedByCurrentScanner = false;
}
예제 #3
0
void AstNodeDType::dumpSmall(ostream& str) {
    str<<"("
       <<(generic()?"G/":"")
       <<((isSigned()&&!isDouble())?"s":"")
       <<(isNosign()?"n":"")
       <<(isDouble()?"d":"")
       <<"w"<<(widthSized()?"":"u")<<width();
    if (!widthSized()) str<<"/"<<widthMin();
    str<<")";
}
예제 #4
0
bool GenericType::can_cast_to(opt_type other) const {
  switch (other) {
      case OT_BOOLEAN:
        return isBool() || isInt() || isDouble();
      case OT_BOOLVECTOR:
        return isIntVector() || isDoubleVector();
      case OT_INTEGER: case OT_REAL:
        return isInt() || isDouble();
      case OT_INTEGERVECTOR: case OT_REALVECTOR:
        return isDoubleVector() || isIntVector();
      default:
        return type_ == other;
  }
}
예제 #5
0
long long TVar::asInteger() const
{
	long long ret = 0;

	if (isInteger())
	{
		ret = inum;
	}
	else if (isDouble())
	{
		ret = static_cast<long long>(dnum);
	}
	else if (isString())
	{
		try
		{
			ret = std::stoll(str);
		}
		catch (std::exception&)
		{
			// TODO: log
		}
	}
	else
	{
		// TODO: log
	}
	return ret;
};
예제 #6
0
파일: mexutil.c 프로젝트: Junjun2016/SIFT3D
/* Set the units of an image to the data stored in an mxArray,
 *
 * Parameters:
 *  -mx: An array of IM_NDIMS dimensions, type double.
 *  -im: The Image struct to which the units are written.
 *
 * Return: SIFT3D_SUCCESS on success, SIFT3D_FAILURE otherwise. */
int mx2units(const mxArray *const mx, Image *const im) {

        const mwSize *mxDims;
        double *mxData;
        mwIndex mxNDims;
        int i;

        // Verify inputs
        mxNDims = (int) mxGetNumberOfDimensions(mx);
	if (mxNDims != 2 || !isDouble(mx))
                return SIFT3D_FAILURE;

        // Verify the dimensions
        mxDims = mxGetDimensions(mx);
        if (mxDims[0] != IM_NDIMS || mxDims[1] != 1)
                return SIFT3D_FAILURE; 

        // Get the data
        if ((mxData = mxGetData(mx)) == NULL)
                return SIFT3D_FAILURE;

        // Copy the data to im
        for (i = 0; i < IM_NDIMS; i++) {

                mwIndex idx;

                const mwIndex subs[] = {i, 0};
                const mwIndex nSubs = sizeof(subs) / sizeof(mwIndex);

                idx = mxCalcSingleSubscript(mx, nSubs, subs);
                SIFT3D_IM_GET_UNITS(im)[i] = mxData[idx];
        }

        return SIFT3D_SUCCESS;
}
예제 #7
0
bool GenericType::operator!=(const GenericType& op2) const{
  if(isString() && op2.isString()){
    return toString().compare(op2.toString()) != 0;
  }

  if(isInt() && op2.isInt()){
    return toInt() != op2.toInt();
  }

  if(isDouble() && op2.isDouble()){
    return toDouble() != op2.toDouble();
  }

  if(isDoubleVector() && op2.isDoubleVector()){
    const vector<double> &v1 = toDoubleVector();
    const vector<double> &v2 = op2.toDoubleVector();
    if(v1.size() != v2.size()) return true;
    for(int i=0; i<v1.size(); ++i)
      if(v1[i] != v2[i]) return true;
    return false;
  }

  if(isIntVector() && op2.isIntVector()){
    const vector<int> &v1 = toIntVector();
    const vector<int> &v2 = op2.toIntVector();
    if(v1.size() != v2.size()) return true;
    for(int i=0; i<v1.size(); ++i)
      if(v1[i] != v2[i]) return true;
    return false;
  }
  
  // Different types
  return true;
}
예제 #8
0
double TVar::asDouble() const
{
	double ret = 0;

	if (isDouble())
	{
		ret = dnum;
	}
	else if (isInteger())
	{
		ret = static_cast<double>(inum);
	}
	else if (isString())
	{
		try
		{
			ret = std::stod(str);
		}
		catch (std::exception&)
		{
			// TODO: log
		}
	}
	else
	{
		// TODO: log
	}

	return ret;
};
예제 #9
0
char* JSValue::description()
{
    static const size_t size = 32;
    static char description[size];

    if (!*this)
        snprintf(description, size, "<JSValue()>");
    else if (isInt32())
        snprintf(description, size, "Int32: %d", asInt32());
    else if (isDouble())
        snprintf(description, size, "Double: %lf", asDouble());
    else if (isCell())
        snprintf(description, size, "Cell: %p", asCell());
    else if (isTrue())
        snprintf(description, size, "True");
    else if (isFalse())
        snprintf(description, size, "False");
    else if (isNull())
        snprintf(description, size, "Null");
    else {
        ASSERT(isUndefined());
        snprintf(description, size, "Undefined");
    }

    return description;
}
예제 #10
0
/**jsdoc
 * A material or set of materials such as may be used by a {@link Entities.EntityType|Material} entity.
 * @typedef {object} MaterialResource
 * @property {number} materialVersion=1 - The version of the material. <em>Currently not used.</em>
 * @property {Material|Material[]} materials - The details of the material or materials.
 */
NetworkMaterialResource::ParsedMaterials NetworkMaterialResource::parseJSONMaterials(const QJsonDocument& materialJSON, const QUrl& baseUrl) {
    ParsedMaterials toReturn;
    if (!materialJSON.isNull() && materialJSON.isObject()) {
        QJsonObject materialJSONObject = materialJSON.object();
        for (auto& key : materialJSONObject.keys()) {
            if (key == "materialVersion") {
                auto value = materialJSONObject.value(key);
                if (value.isDouble()) {
                    toReturn.version = (uint)value.toInt();
                }
            } else if (key == "materials") {
                auto materialsValue = materialJSONObject.value(key);
                if (materialsValue.isArray()) {
                    QJsonArray materials = materialsValue.toArray();
                    for (auto material : materials) {
                        if (!material.isNull() && material.isObject()) {
                            auto parsedMaterial = parseJSONMaterial(material.toObject(), baseUrl);
                            toReturn.networkMaterials[parsedMaterial.first] = parsedMaterial.second;
                            toReturn.names.push_back(parsedMaterial.first);
                        }
                    }
                } else if (materialsValue.isObject()) {
                    auto parsedMaterial = parseJSONMaterial(materialsValue.toObject(), baseUrl);
                    toReturn.networkMaterials[parsedMaterial.first] = parsedMaterial.second;
                    toReturn.names.push_back(parsedMaterial.first);
                }
            }
        }
    }

    return toReturn;
}
예제 #11
0
파일: Value.cpp 프로젝트: eric-casellas/vle
const Double&
Value::toDouble() const
{
    if (not isDouble()) {
        throw utils::CastError(_("Value is not a double"));
    }
    return static_cast<const Double&>(*this);
}
예제 #12
0
double GenericType::toDouble() const{
  if(isInt()){
    return double(toInt());
  } else {
    casadi_assert_message(isDouble(),"type mismatch");
    return static_cast<const DoubleType*>(get())->d_;
  }
}
예제 #13
0
void RepoQuery::getDouble(int iCol, double& val) {
  if (!isDouble(iCol)) {
    throw RepoExc(
      "RepoQuery::%s(repo=%p) error: Column %d is not a double in '%s'",
      __func__, &m_stmt.repo(), iCol, m_stmt.sql().c_str());
  }
  val = sqlite3_column_double(m_stmt.get(), iCol);
}
	bool SequenceBinomialDistribution::validateValues(){
		if (!isDouble(form->getTextBoxValue("txtExperimentsNumber")))
			return false;
		// Zahl der Versuche muss ganzzahlig und >0 sein
		double expNum = Double::Parse(form->getTextBoxValue("txtExperimentsNumber"));
		if (Math::Ceiling(expNum) != expNum || expNum <= 0)
			return false;
		
		if (!isDouble(form->getTextBoxValue("txtSuccessProbability")))
			return false;
		// Erfolgswahrscheinlichkeit soll zwischen 0 und 1 liegen
		double succProb = Double::Parse(form->getTextBoxValue("txtSuccessProbability"));
		if (succProb < 0 || succProb > 1)
			return false;
		
		return SequenceDistribution::validateValues();
	}
예제 #15
0
    bool AsmJsType::isSubType(AsmJsType type) const
    {
        switch (type.which_)
        {
        case Js::AsmJsType::Double:
            return isDouble();
            break;

        case Js::AsmJsType::MaybeDouble:
            return isMaybeDouble();
            break;
        case Js::AsmJsType::DoubleLit:
            return isDoubleLit();
            break;
        case Js::AsmJsType::Float:
            return isFloat();
            break;
        case Js::AsmJsType::MaybeFloat:
            return isMaybeFloat();
            break;
        case Js::AsmJsType::Floatish:
            return isFloatish();
            break;
        case Js::AsmJsType::FloatishDoubleLit:
            return isFloatishDoubleLit();
            break;
        case Js::AsmJsType::Fixnum:
            return which_ == Fixnum;
            break;
        case Js::AsmJsType::Int:
            return isInt();
            break;
        case Js::AsmJsType::Signed:
            return isSigned();
            break;
        case Js::AsmJsType::Unsigned:
            return isUnsigned();
            break;
        case Js::AsmJsType::Intish:
            return isIntish();
            break;
        case Js::AsmJsType::Void:
            return isVoid();
            break;
        case AsmJsType::Int32x4:
            return isSIMDInt32x4();
            break;
        case AsmJsType::Float32x4:
            return isSIMDFloat32x4();
            break;
        case AsmJsType::Float64x2:
            return isSIMDFloat64x2();
            break;
        default:
            break;
        }
        return false;
    }
예제 #16
0
	bool SequenceDouble::validateValues(){
		if (!isDouble(form->getTextBoxValue("txtCount")))
			return false;
		// Anzahl muss ganzzahlig und >0 sein
		double cnt = Double::Parse(form->getTextBoxValue("txtCount"));
		if (Math::Ceiling(cnt) != cnt || cnt <= 0)
			return false;
		return true;
	}
예제 #17
0
uint32_t
VFPRegister::getRegisterDumpOffsetInBytes()
{
    if (isSingle())
        return id() * sizeof(float);
    if (isDouble())
        return id() * sizeof(double);
    MOZ_ASSUME_UNREACHABLE();
}
예제 #18
0
int32_t CppVariant::toInt32() const
{
    if (isInt32())
        return value.intValue;
    if (isDouble())
        return static_cast<int32_t>(value.doubleValue);
    BLINK_ASSERT_NOT_REACHED();
    return 0;
}
예제 #19
0
double CppVariant::toDouble() const
{
    if (isInt32())
        return static_cast<double>(value.intValue);
    if (isDouble())
        return value.doubleValue;
    WEBKIT_ASSERT_NOT_REACHED();
    return 0;
}
예제 #20
0
double JSValue::toNumberSlowCase(ExecState* exec) const
{
    ASSERT(!isInt32() && !isDouble());
    if (isCell())
        return asCell()->toNumber(exec);
    if (isTrue())
        return 1.0;
    return isUndefined() ? PNaN : 0; // null and false both convert to 0.
}
예제 #21
0
uint32_t
FloatRegister::getRegisterDumpOffsetInBytes()
{
    if (isSingle())
        return id() * sizeof(float);
    if (isDouble())
        return id() * sizeof(double);
    MOZ_CRASH();
}
예제 #22
0
파일: eqml.cpp 프로젝트: krant/eqml
	double toScalar() const
	{
		if (isInteger())
			return toInteger();
		if (isDouble())
			return toDouble();

		qWarning("can't cast term to scalar");
		return 0.0;
	}
예제 #23
0
파일: signals.cpp 프로젝트: EBone/faust-1
Tree  sigIntCast(Tree t)						
{ 
	Node n = t->node();
	
	int i; 		if (isInt(n, &i)) 			return t; 
	double x;	if (isDouble(n, &x)) 		return tree(int(x));
				if (isSigIntCast(t))		return t;
	 
	return tree(SIGINTCAST, t);   
}
예제 #24
0
파일: signals.cpp 프로젝트: EBone/faust-1
Tree  sigFloatCast(Tree t)						
{ 
	Node n = t->node();
	
	int i; 		if (isInt(n, &i)) 			return tree(double(i)); 
	double x;	if (isDouble(n, &x)) 		return t;
				if (isSigFloatCast(t))		return t;
                if (isSigInput(t, &i))      return t;
	 
	return tree(SIGFLOATCAST, t);   
}
예제 #25
0
파일: tvar.cpp 프로젝트: landswellsong/FAR
__int64 TVar::getInteger() const
{
	__int64 ret = inum;

	if (isString())
		ret = str ? _wtoi64(str) : 0;
	else if (isDouble())
		ret=(__int64)dnum;

	return ret;
};
예제 #26
0
JSObject* JSValue::toThisObjectSlowCase(ExecState* exec) const
{
    ASSERT(!isCell());

    if (isInt32() || isDouble())
        return constructNumber(exec, asValue());
    if (isTrue() || isFalse())
        return constructBooleanFromImmediateBoolean(exec, asValue());
    ASSERT(isUndefinedOrNull());
    return exec->globalThisValue();
}
예제 #27
0
void OSCServerThread::run()
{
        oscpkt::UdpSocket server;
        server.bindTo(this->port);
        if (!server.isOk()) {
                std::cerr << "Error opening OSC server at " << port
                          << std::endl;
                return;
        }

        std::cout << "Started OSC Server at " << port << std::endl;

        oscpkt::PacketReader reader;
        oscpkt::PacketWriter writer;
        while (server.isOk() && !mustQuit) {
                if (server.receiveNextPacket(30)) {
                        reader.init(server.packetData(), server.packetSize());
                        oscpkt::Message *msg;
                        while (reader.isOk() &&
                               (msg = reader.popMessage()) != 0) {
                                QVariantList message;
                                message.append(QString::fromStdString(
                                    msg->addressPattern()));
                                auto args = msg->arg();
                                while (!args.isOkNoMoreArgs()) {
                                        if (args.isInt32()) {
                                                int32_t i;
                                                args = args.popInt32(i);
                                                message.append(i);
                                        } else if (args.isInt64()) {
                                                int64_t i;
                                                args = args.popInt64(i);
                                                message.append(
                                                    static_cast<qlonglong>(i));
                                        } else if (args.isFloat()) {
                                                float f;
                                                args = args.popFloat(f);
                                                message.append(f);
                                        } else if (args.isDouble()) {
                                                double d;
                                                args = args.popDouble(d);
                                                message.append(d);
                                        } else if (args.isStr()) {
                                                std::string s;
                                                args = args.popStr(s);
                                                message.append(
                                                    QString::fromStdString(s));
                                        }
                                }
                                emit messageIn(message);
                        }
                }
        }
}
예제 #28
0
void ParamWrapper::setValue(double value)
{
    if(isDouble())
    {
        *double_param = value;
    }
    else
    {
        crusde_error("ParamWrapper::setValue : try setting double when param is not double\n");
    }
}
예제 #29
0
void TPaperFormatManager::readPaperFormat(const TFilePath &path) {
  if (path.getType() != "pap") return;
  Tifstream is(path);
  std::string name;
  TDimensionD size(0, 0);
  while (is) {
    char buffer[1024];
    is.getline(buffer, sizeof buffer);

    // i e' il carattere successivo alla fine della linea
    unsigned int i = 0;
    for (i = 0; i < sizeof buffer && buffer[i]; i++) {
    }
    if (i > 0 && buffer[i - 1] == '\n') i--;
    while (i > 0 && buffer[i - 1] == ' ') i--;
    unsigned int j = 0;
    unsigned int k = 0;
    // j e' il carattere successivo alla fine del primo token
    for (j = 0; j < i && buffer[j] != ' '; j++) {
    }

    // k e' l'inizio del secondo token (se c'e', altrimenti == i)
    for (k = j; k < i && buffer[k] == ' '; k++) {
    }

    std::string value;
    if (k < i) value = std::string(buffer + k, i - k);

    if (buffer[0] == '#') {
      if (k < i && name == "") name = value;
    } else if (std::string(buffer).find("WIDTH") == 0) {
      if (isDouble(value)) size.lx = std::stod(value);
    } else if (std::string(buffer).find("LENGTH") == 0) {
      if (isDouble(value)) size.ly = std::stod(value);
    }
  }
  if (name == "" || size.lx == 0 || size.ly == 0) {
    // TMessage::error("Error reading paper format file : %1",path);
  } else
    m_formats[name] = Format(size);
}
예제 #30
0
int GenericType::toInt() const{
  if(isDouble()){
    double v = toDouble();
    casadi_assert_message(v == std::floor(v),"The value is not an integer");
    return int(v);
  } else if (isBool()) {
    return int(toBool());
  } else {
    casadi_assert_message(isInt(),"type mismatch");
    return static_cast<const IntType*>(get())->d_;
  }
}