本文整理汇总了C++中Bool类的典型用法代码示例。如果您正苦于以下问题:C++ Bool类的具体用法?C++ Bool怎么用?C++ Bool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Beagle_RunTimeExceptionM
/*!
* \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: dataType
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;
}
示例3: readBool
inline Bool readBool(std::istream& istrm)
{
BinarySerialization::verifySignature(istrm, BINSIG_BOOL);
Bool b;
b.readObject(istrm);
return b;
}
示例4: not_has_element
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: TEST
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: GetBool
//-----------------------------------------------------------------------------
bool DataType::GetBool() const
{
HRESULT hr;
Bool b;
hr = b.Cast( *this );
if( FAILED(hr) )
return 0;
return b.Get();
}
示例7: has_element
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);
}
示例8: return
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();
}
示例9: uint2str
/*!
* \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);
}
示例10: switch
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;
}
示例11: setValue
/*!
* \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);
}
示例12: outValue
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);
}
}
}
示例13: value
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;
}
示例14: comparison
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());
//.........这里部分代码省略.........
示例15: writeBool
inline void writeBool(std::ostream& ostrm,
Bool arg)
{
BinarySerialization::write(ostrm, BINSIG_BOOL);
arg.writeObject(ostrm);
}