示例#1
0
/*!
 *  \brief Evaluate the individual fitness for the spambase problem.
 *  \param inIndividual Individual to evaluate.
 *  \param ioContext Evolutionary context.
 *  \return Handle to the fitness measure,
 */
Fitness::Handle SpambaseEvalOp::evaluate(GP::Individual& inIndividual, GP::Context& ioContext)
{
	// Get reference to data set
	DataSetClassification::Handle lDataSet =
	    castHandleT<DataSetClassification>(ioContext.getSystem().getComponent("DataSet"));
	if(lDataSet == NULL) {
		throw Beagle_RunTimeExceptionM("Data set is not present in the system, could not proceed further!");
	}

	// Generate indices used as data subset for fitness evaluation
	std::vector<unsigned int> lSubSet(lDataSet->size());
	for(unsigned int i=0; i<lSubSet.size(); ++i) lSubSet[i] = i;
	std::random_shuffle(lSubSet.begin(), lSubSet.end(),
	                    ioContext.getSystem().getRandomizer());
	if(Spambase_TestSize < lSubSet.size()) {
		lSubSet.resize(Spambase_TestSize);
	}

	// Evaluate sampled test cases
	unsigned int lCorrectCount = 0;
	for(unsigned int i=0; i<Spambase_TestSize; ++i) {
		const bool lPositiveID = ((*lDataSet)[lSubSet[i]].first == 1);
		const Beagle::Vector& lData = (*lDataSet)[lSubSet[i]].second;
		for(unsigned int j=0; j<lData.size(); ++j) {
			std::ostringstream lOSS;
			lOSS << "IN" << j;
			setValue(lOSS.str(), Double(lData[j]), ioContext);
		}
		Bool lResult;
		inIndividual.run(lResult, ioContext);
		if(lResult.getWrappedValue() == lPositiveID) ++lCorrectCount;
	}
	double lFitness = double(lCorrectCount) / Spambase_TestSize;
	return new EC::FitnessSimple(lFitness);
}
示例#2
0
void
CIMQualifierType::readObject(istream &istrm)
{
	CIMName name;
	CIMDataType dataType(CIMNULL);
	CIMScopeArray scope;
	CIMFlavorArray flavor;
	CIMValue defaultValue(CIMNULL);
	CIMBase::readSig( istrm, OW_CIMQUALIFIERTYPESIG );
	name.readObject(istrm);
	dataType.readObject(istrm);
	BinarySerialization::readArray(istrm, scope);
	BinarySerialization::readArray(istrm, flavor);
	Bool isValue;
	isValue.readObject(istrm);
	if (isValue)
	{
		defaultValue.readObject(istrm);
	}
	if (!m_pdata)
	{
		m_pdata = new QUALTData;
	}
	m_pdata->m_name = name;
	m_pdata->m_dataType = dataType;
	m_pdata->m_scope = scope;
	m_pdata->m_flavor = flavor;
	m_pdata->m_defaultValue = defaultValue;
}
	inline Bool readBool(std::istream& istrm)
	{
		BinarySerialization::verifySignature(istrm, BINSIG_BOOL);
		Bool b;
		b.readObject(istrm);
		return b;
	}
示例#4
0
Bool* not_has_element(Variable* A, Variable* B)
{
    Bool* b = has_element(A, B);
    if(b == NULL)
        return NULL;
    b->setValue(!b->getValue());
    return b;
}
示例#5
0
TEST(VersionTest, InitWithVarRequiringCast) {
    Bool a = any_bool("A");
    Char b = any_char("B");
    Int c = b;

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
}
示例#6
0
TEST(VersionTest, InitWithAny) {
    Bool a = any_bool("A");
    Char b = any_char("B");
    Int c = any_int("C");

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
}
示例#7
0
TEST(VersionTest, InitWithConcrete) {
    Bool a = true;
    Bool b = true;
    Char c = 'a';
    Int d = 3;

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
    EXPECT_EQ(0, d.get_version());
}
示例#8
0
//-----------------------------------------------------------------------------
bool DataType::GetBool() const
{
    HRESULT hr;
    Bool b;
    
    hr = b.Cast( *this );
    if( FAILED(hr) )
        return 0;

    return b.Get();
}
示例#9
0
Bool* has_element(Variable* A, Variable* B)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in has_element operation.\n");
        return NULL;
    }
    TypeEnum a = A->getType();
    TypeEnum b = B->getType();
    if(a != ARRAY && b != ARRAY)
    {
        interpreter.error("Error: Has_element not defined for types '%s' and '%s'\n", getTypeString(a).c_str(), getTypeString(b).c_str());
        return NULL;
    }

    Array* C;
    Variable* other;
    TypeEnum otherType;
    if(a == ARRAY)
    {
        C = static_cast<Array*>(A);
        other = B;
        otherType = b;
    }
    else
    {
        C = static_cast<Array*>(B);
        other = A;
        otherType = a;
    }

    if(otherType != C->getValueType())
    {
        interpreter.error("Error: Has_element not defined for types '%s' and '%s'\n", getTypeString(ARRAY).c_str(), getTypeString(otherType).c_str());
        return NULL;
    }

    vector<Variable*>& v = C->getValue();
    for(vector<Variable*>::iterator e = v.begin(); e != v.end(); e++)
    {
        Bool* test = comparison(other, *e, EQUALS);
        if(test->getValue() == true)
            return test;
        delete test;
    }

    return new Bool(false);
}
示例#10
0
文件: mexlib.cpp 项目: scitao/scilab
mxLogical *mxGetLogicals(const mxArray *ptr)
{
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return NULL;
    }

    Bool *pB = pIT->getAs<Bool>();
    if (pB == NULL)
    {
        return NULL;
    }

    return (mxLogical *)pB->get();
}
/*!
 *  \brief Evaluate the individual fitness for the even-6 parity problem.
 *  \param inIndividual Individual to evaluate.
 *  \param ioContext Evolutionary context.
 *  \return Handle to the fitness measure,
 */
Fitness::Handle ParityEvalOp::evaluate(GP::Individual& inIndividual, GP::Context& ioContext)
{
	unsigned int lGood = 0;
	for(unsigned int i=0; i<ParitySizeM; i++) {
		for(unsigned int j=0; j<ParityFanInM; j++) {
			std::string lName = "IN";
			lName += uint2str(j);
			setValue(lName, mInputs[i][j], ioContext);
		}
		Bool lResult;
		inIndividual.run(lResult, ioContext);
		if(lResult.getWrappedValue() == mOutputs[i].getWrappedValue()) lGood++;
	}
	double lFitness = double(lGood) / ParitySizeM;
	return new FitnessSimple(lFitness);
}
示例#12
0
Bool *Bool::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    Bool *result = nullptr;
    switch (constructor) {
        case 0x997275b5:
            result = new TL_boolTrue();
            break;
        case 0xbc799737:
            result = new TL_boolFalse();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in Bool", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
示例#13
0
/*!
 *  \brief Evaluate the individual fitness for the boolean 11-multiplexer problem.
 *  \param inIndividual Individual to evaluate.
 *  \param ioContext Evolutionary context.
 *  \return Handle to the fitness measure,
 */
Fitness::Handle MultiplexerEvalOp::evaluate(GP::Individual& inIndividual, GP::Context& ioContext)
{
	unsigned int lNbGood = 0;
	for(unsigned int i=0; i<2048; ++i) {
		setValue("A0", mInputs[i][0], ioContext);
		setValue("A1", mInputs[i][1], ioContext);
		setValue("A2", mInputs[i][2], ioContext);
		setValue("D0", mInputs[i][3], ioContext);
		setValue("D1", mInputs[i][4], ioContext);
		setValue("D2", mInputs[i][5], ioContext);
		setValue("D3", mInputs[i][6], ioContext);
		setValue("D4", mInputs[i][7], ioContext);
		setValue("D5", mInputs[i][8], ioContext);
		setValue("D6", mInputs[i][9], ioContext);
		setValue("D7", mInputs[i][10], ioContext);
		Bool lResult;
		inIndividual.run(lResult, ioContext);
		if(lResult.getWrappedValue() == mOutputs[i].getWrappedValue()) ++lNbGood;
	}
	double lFitness = double(lNbGood) / 2048.;
	return new EC::FitnessSimple(lFitness);
}
示例#14
0
void BoolAttribute::onSettingSpecialization(const std::vector<std::string> &specialization) {
    Bool *boolVal = outValue();

    boolVal->setIsArray(false);
    if(boolVal->size() == 0) {
        boolVal->resize(1);
        boolVal->setBoolValueAt(0, false);
    }

    if(specialization.size() == 1) {
        if(specialization[0] == "BoolArray") {
            boolVal->setIsArray(true);
        }
    }
}
示例#15
0
std::string BoolAttribute::shortDebugInfo() {
    std::string info = Attribute::shortDebugInfo() + "\n";

    Bool *val = value();
    int slices = val->slices();

    bool isArray = val->isArray();

    info += "slices: " + stringUtils::intToString(slices) + "\n";
    for(int i = 0; i < val->slices(); ++i) {
        info += "slice: " + 	stringUtils::intToString(i) + ", ";
        if(isArray) {
            info += "size: " + stringUtils::intToString(val->sizeSlice(i)) + ", ";
        }

        std::string valStr = val->sliceAsString(i);
        std::vector<std::string> split;
        stringUtils::split(valStr, split, " ");
        valStr = split[0];

        std::string trimmedValStr;
        if(valStr.size() < 100) {
            trimmedValStr = valStr;
        }
        else {
            for(int i = 0; i < 100; ++i) {
                trimmedValStr += valStr[i];
            }
            trimmedValStr += " ...]";
        }

        info += trimmedValStr + "\n";

        if(i > 3) {
            info += "(trimming remaining slices)\n";
            break;
        }
    }

    return info;
}
示例#16
0
Bool* comparison(Variable* A, Variable* B, OperatorEnum oper)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in assignment.\n");
        return NULL;
    }
    TypeEnum a = A->getType();
    TypeEnum b = B->getType();


    bool mismatch = false;
    if(a == STRING)
    {
        if(b != STRING)
            mismatch = true;
        else
        {
            String* C = static_cast<String*>(A);
            String* D = static_cast<String*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == INT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Int* C = static_cast<Int*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
        }
    }
    else if(a == FLOAT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Float* C = static_cast<Float*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
        }
    }
    else if(a == BOOL)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Bool* C = static_cast<Bool*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
        }
    }
    else if(a == MACRO)
    {
        if(b != MACRO)
            mismatch = true;
        else
        {
            Macro* C = static_cast<Macro*>(A);
            Macro* D = static_cast<Macro*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == ARRAY)
    {
        if(b != ARRAY)
            mismatch = true;
        else
        {
            Array* C = static_cast<Array*>(A);
            Array* D = static_cast<Array*>(B);
            a = C->getValueType();
            b = C->getValueType();
            if(a != b)
            {
                interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
                return NULL;
            }

            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == LIST)
    {
        if(b != LIST)
            mismatch = true;
        else
        {
            List* C = static_cast<List*>(A);
            List* D = static_cast<List*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == FUNCTION)
    {
        if(b != FUNCTION)
            mismatch = true;
        else
        {
            Function* C = static_cast<Function*>(A);
            Function* D = static_cast<Function*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == PROCEDURE)
    {
        if(b != PROCEDURE)
            mismatch = true;
        else
        {
            Procedure* C = static_cast<Procedure*>(A);
            Procedure* D = static_cast<Procedure*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }

    //if(mismatch)
    {
        interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    return NULL;
}
示例#17
0
	inline void writeBool(std::ostream& ostrm,
		Bool arg)
	{
		BinarySerialization::write(ostrm, BINSIG_BOOL);
		arg.writeObject(ostrm);
	}
示例#18
0
文件: mexlib.cpp 项目: scitao/scilab
void *mxGetImagData(const mxArray *ptr)
{
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return NULL;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabDouble:
        {
            Double *pD = pIT->getAs<Double>();
            return pD->getImg();
        }
        case InternalType::ScilabBool:
        {
            Bool *pB = pIT->getAs<Bool>();
            return pB->getImg();
        }
        case InternalType::ScilabInt8:
        {
            Int8 *pI = pIT->getAs<Int8>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt8:
        {
            UInt8 *pI = pIT->getAs<UInt8>();
            return pI->getImg();
        }
        case InternalType::ScilabInt16:
        {
            Int16 *pI = pIT->getAs<Int16>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt16:
        {
            UInt16 *pI = pIT->getAs<UInt16>();
            return pI->getImg();
        }
        case InternalType::ScilabInt32:
        {
            Int32 *pI = pIT->getAs<Int32>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt32:
        {
            UInt32 *pI = pIT->getAs<UInt32>();
            return pI->getImg();
        }
        case InternalType::ScilabInt64:
        {
            Int64 *pI = pIT->getAs<Int64>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt64:
        {
            UInt64 *pI = pIT->getAs<UInt64>();
            return pI->getImg();
        }
        default:
            return NULL;
    }
}
示例#19
0
文件: bool.hpp 项目: groonga/grnxx
 constexpr Bool operator!=(Bool rhs) const {
   return (is_na() || rhs.is_na()) ? na() :
          Bool(static_cast<uint8_t>(raw_ ^ rhs.raw_));
 }
示例#20
0
Variable* assign(Variable* A, Variable* B)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in assignment.\n");
        return NULL;
    }
    if(!A->reference)
    {
        interpreter.error("Error: Assigning value to a non-reference variable.\n");
        return NULL;
    }

    TypeEnum a = A->getType();
    TypeEnum b = B->getType();

    bool mismatch = false;
    if(a == STRING)
    {
        if(b != STRING)
            mismatch = true;
        else
        {
            String* C = static_cast<String*>(A);
            String* D = static_cast<String*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == INT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Int* C = static_cast<Int*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(D->getValue());
            }
        }
    }
    else if(a == FLOAT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Float* C = static_cast<Float*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(D->getValue());
            }
        }
    }
    else if(a == BOOL)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Bool* C = static_cast<Bool*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(D->getValue());
            }
        }
    }
    else if(a == MACRO)
    {
        if(b != MACRO)
            mismatch = true;
        else
        {
            Macro* C = static_cast<Macro*>(A);
            Macro* D = static_cast<Macro*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == ARRAY)
    {
        if(b != ARRAY)
            mismatch = true;
        else
        {
            Array* C = static_cast<Array*>(A);
            Array* D = static_cast<Array*>(B);
            a = C->getValueType();
            b = D->getValueType();
            if(a != b)
            {
                interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
                return NULL;
            }
            C->setValue(D->getValue());
        }
    }
    else if(a == LIST)
    {
        if(b != LIST)
            mismatch = true;
        else
        {
            List* C = static_cast<List*>(A);
            List* D = static_cast<List*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == FUNCTION)
    {
        if(b != FUNCTION)
            mismatch = true;
        else
        {
            Function* C = static_cast<Function*>(A);
            Function* D = static_cast<Function*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == PROCEDURE)
    {
        if(b != PROCEDURE)
            mismatch = true;
        else
        {
            Procedure* C = static_cast<Procedure*>(A);
            Procedure* D = static_cast<Procedure*>(B);
            C->setValue(D->getValue());
        }
    }

    if(mismatch)
    {
        interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    return A;
}
示例#21
0
文件: mexlib.cpp 项目: scitao/scilab
double mxGetScalar(const mxArray *ptr)
{
    // TODO: review spec
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return 0;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabDouble:
        {
            Double *pD = pIT->getAs<Double>();
            return pD->get(0);
        }
        case InternalType::ScilabBool:
        {
            Bool *pB = pIT->getAs<Bool>();
            return (double)pB->get(0);
        }
        case InternalType::ScilabInt8:
        {
            Int8 *pI = pIT->getAs<Int8>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt8:
        {
            UInt8 *pI = pIT->getAs<UInt8>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabInt16:
        {
            Int16 *pI = pIT->getAs<Int16>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt16:
        {
            UInt16 *pI = pIT->getAs<UInt16>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabInt32:
        {
            Int32 *pI = pIT->getAs<Int32>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt32:
        {
            UInt32 *pI = pIT->getAs<UInt32>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabInt64:
        {
            Int64 *pI = pIT->getAs<Int64>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt64:
        {
            UInt64 *pI = pIT->getAs<UInt64>();
            return (double)pI->get(0);
        }
        default:
            return 0;
    }
}
示例#22
0
InternalType* or_M_E<Bool, Double, Bool>(Bool* _pL, Double* /* _pR */)
{
    Bool* pOut = new Bool(_pL->getDims(), _pL->getDimsArray());
    pOut->setTrue();
    return pOut;
}
示例#23
0
String::String(Bool parm) :
	m_buf(parm.toString().m_buf)
{
}
示例#24
0
InternalType* or_E_M<Double, Bool, Bool>(Double* /* _pL */, Bool*  _pR)
{
    Bool* pOut = new Bool(_pR->getDims(), _pR->getDimsArray());
    pOut->setTrue();
    return pOut;
}
示例#25
0
Variable* add_assign(Variable* A, Variable* B)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in assignment.\n");
        return NULL;
    }
    if(!A->reference)
    {
        interpreter.error("Error: Assigning value to a non-reference variable.\n");
        return NULL;
    }

    TypeEnum a = A->getType();
    TypeEnum b = B->getType();

    bool mismatch = false;
    if(a == STRING)
    {
        if(b != STRING)
            mismatch = true;
        else
        {
            String* C = static_cast<String*>(A);
            String* D = static_cast<String*>(B);
            C->setValue(C->getValue() + D->getValue());
        }
    }
    else if(a == INT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Int* C = static_cast<Int*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
        }
    }
    else if(a == FLOAT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Float* C = static_cast<Float*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
        }
    }
    else if(a == BOOL)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Bool* C = static_cast<Bool*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
        }
    }
    else if(a == MACRO)
    {
        interpreter.error("Error: Addition operation not defined for type 'macro'.\n");
        return NULL;
    }
    else if(a == ARRAY)
    {
        if(b == ARRAY)
        {
            Array* C = static_cast<Array*>(A);
            Array* D = static_cast<Array*>(B);
            a = C->getValueType();
            b = C->getValueType();
            if(a != b)
            {
                interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
                return NULL;
            }
            C->push_back(D->getValue());
        }
        else
        {
            Array* C = static_cast<Array*>(A);
            if(b == C->getValueType())
            {
                C->push_back(B);
            }
            else
                mismatch = true;
        }
    }
    else if(a == LIST)
    {
        // Lists must be concatenated a different way...
        List* C = static_cast<List*>(A);
        C->push_back(B);
    }
    else if(a == FUNCTION)
    {
        interpreter.error("Error: Addition operation not defined for type 'function'.\n");
        return NULL;
    }
    else if(a == PROCEDURE)
    {
        interpreter.error("Error: Addition operation not defined for type 'procedure'.\n");
        return NULL;
    }

    if(mismatch)
    {
        interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    return A;
}
int main( int argc, char **argv )
{
    if (boost::ends_with(argv[0], "syncevo-local-sync")) {
        return LocalTransportMain(argc, argv);
    }

    // Intercept stderr and route it through our logging.
    // stdout is printed normally. Deconstructing it when
    // leaving main() does one final processing of pending
    // output.
    LogRedirect redirect(false);
    setvbuf(stderr, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

    SyncContext::initMain("syncevolution");

    // Expand PATH to cover the directory we were started from?
    // This might be needed to find normalize_vcard.
    char *exe = strdup(argv[0]);
    if (strchr(exe, '/') ) {
        char *dir = dirname(exe);
        string path;
        char *oldpath = getenv("PATH");
        if (oldpath) {
            path += oldpath;
            path += ":";
        }
        path += dir;
        setenv("PATH", path.c_str(), 1);
    }
    free(exe);

    try {
        if (getenv("SYNCEVOLUTION_DEBUG")) {
            LoggerBase::instance().setLevel(Logger::DEBUG);
        }

        SyncEvo::KeyringSyncCmdline cmdline(argc, argv);
        vector<string> parsedArgs;
        if(!cmdline.parse(parsedArgs)) {
            return 1;
        }

        if (cmdline.dontRun()) {
            return 0;
        }

        Bool useDaemon = cmdline.useDaemon();

        if(cmdline.monitor()) {

#ifdef DBUS_SERVICE
            // monitor a session
            RemoteDBusServer server;
            if(server.checkStarted() && server.monitor(cmdline.getConfigName())) {
                return 0;
            }
            return 1;
#else
            SE_LOG_ERROR(NULL, NULL, "this syncevolution binary was compiled without support for monitoring a background sync");
            return 1;
#endif
        } else if(cmdline.status() && 
                  cmdline.getConfigName().empty()) {

#ifdef DBUS_SERVICE
            // '--status' and no server name, try to get running sessions 
            RemoteDBusServer server;
            if(server.checkStarted()) {
                server.runningSessions();
                return 0;
            }
            return 1;
#else
            SE_LOG_SHOW(NULL, NULL, "this syncevolution binary was compiled without support for monitoring a background sync");
            return 1;
#endif
        } else if (useDaemon ||
                   !useDaemon.wasSet()) {
#ifdef DBUS_SERVICE
            RemoteDBusServer server;

            // Running execute() without the server available will print errors.
            // Avoid that unless the user explicitly asked for the daemon.
            bool result = server.checkStarted(false);
            if (useDaemon.wasSet() || result) {
                return !server.execute(parsedArgs, cmdline.getConfigName(), cmdline.isSync());
            } else {
                // User didn't select --use-daemon and thus doesn't need to know about it
                // not being available.
                // SE_LOG_SHOW(NULL, NULL, "WARNING: cannot run syncevolution as daemon. "
                //             "Trying to run it without daemon.");
            }
#else
            if (useDaemon.wasSet()) {
                SE_LOG_SHOW(NULL, NULL, "ERROR: this syncevolution binary was compiled without support of daemon. "
                            "Either run syncevolution with '--use-daemon=no' or without that option."); 
                return 1;
            }
#endif
        } 

        // if forcing not using daemon or trying to use daemon with failures,
        // run arguments in the process
        if (!useDaemon.wasSet() ||
            !useDaemon) {
            EDSAbiWrapperInit();

            /*
             * don't log errors to cerr: LogRedirect cannot distinguish
             * between our valid error messages and noise from other
             * libs, therefore it would get suppressed (logged at
             * level DEVELOPER, while output is at most INFO)
             */
            if (cmdline.run()) {
                return 0;
            } else {
                return 1;
            }
        }
    } catch ( const std::exception &ex ) {
        SE_LOG_ERROR(NULL, NULL, "%s", ex.what());
    } catch (...) {
        SE_LOG_ERROR(NULL, NULL, "unknown error");
    }

    return 1;
}