void cShortcut::attribChanged (const QString &name) { if (name == "command") { d->command = strVal ("command"); updateVisibleName (); return; } if (name == "key") { d->key = intVal ("key"); updateVisibleName (); return; } if (name == "modifiers") { d->modifiers = intVal ("modifiers"); updateVisibleName (); return; } if (name == "send") { d->send = boolVal ("send"); return; } if (name == "overwrite") { d->overwrite = boolVal ("overwrite"); return; } if (name == "script") updateVisibleName (); }
Variant SSATmp::variantVal() const { switch (type().toDataType()) { case KindOfUninit: case KindOfNull: // Upon return both will converted to KindOfNull anyway. return init_null(); case KindOfBoolean: return boolVal(); case KindOfInt64: return intVal(); case KindOfDouble: return dblVal(); case KindOfStaticString: case KindOfString: return Variant(const_cast<StringData*>(strVal())); case KindOfArray: return const_cast<ArrayData*>(arrVal()); case KindOfObject: case KindOfResource: case KindOfRef: case KindOfClass: break; } not_reached(); }
void idpSetInternalOption(_TCHAR *name, _TCHAR *value) { string key = toansi(_tcslwr(name)); if (key.compare("allowcontinue") == 0) ui.allowContinue = boolVal(value); else if(key.compare("retrybutton") == 0) ui.hasRetryButton = boolVal(value); else if(key.compare("useragent") == 0) userAgent = value; else if(key.compare("invalidcert") == 0) { string val = toansi(_tcslwr(value)); if (val.compare("showdlg") == 0) internetOptions.invalidCert = INVC_SHOWDLG; else if(val.compare("stop") == 0) internetOptions.invalidCert = INVC_STOP; else if(val.compare("ignore") == 0) internetOptions.invalidCert = INVC_IGNORE; } else if(key.compare("connecttimeout") == 0) internetOptions.connectTimeout = timeoutVal(value); else if(key.compare("sendtimeout") == 0) internetOptions.sendTimeout = timeoutVal(value); else if(key.compare("receivetimeout") == 0) internetOptions.receiveTimeout = timeoutVal(value); }
int dlgVal(_TCHAR *value) { string val = toansi(tstrlower(STR(value))); if(val.compare("none") == 0) return DLG_NONE; if(val.compare("simple") == 0) return DLG_SIMPLE; if(val.compare("filelist") == 0) return DLG_FILELIST; if(val.compare("urllist") == 0) return DLG_URLLIST; return boolVal(value) ? DLG_NONE : DLG_SIMPLE; }
void idpSetInternalOption(_TCHAR *name, _TCHAR *value) { if(!name) return; TRACE(_T("idpSetInternalOption(%s, %s)"), name, value); string key = toansi(tstrlower(name)); if(key.compare("allowcontinue") == 0) { ui.allowContinue = boolVal(value); downloader.stopOnError = !ui.allowContinue; } else if(key.compare("stoponerror") == 0) downloader.stopOnError = boolVal(value); else if(key.compare("preserveftpdirs") == 0) downloader.preserveFtpDirs = boolVal(value); else if(key.compare("readbuffersize") == 0) downloader.readBufferSize = bufSizeVal(value); else if(key.compare("retrybutton") == 0) ui.hasRetryButton = boolVal(value); else if(key.compare("redrawbackground") == 0) ui.redrawBackground = boolVal(value); else if(key.compare("errordialog") == 0) ui.errorDlgMode = dlgVal(value); else if(key.compare("errordlg") == 0) ui.errorDlgMode = dlgVal(value); else if(key.compare("useragent") == 0) internetOptions.userAgent = STR(value); else if(key.compare("referer") == 0) internetOptions.referer = STR(value); else if(key.compare("invalidcert") == 0) internetOptions.invalidCert = invCertVal(value); else if(key.compare("oninvalidcert") == 0) internetOptions.invalidCert = invCertVal(value); else if(key.compare("connecttimeout") == 0) internetOptions.connectTimeout = timeoutVal(value); else if(key.compare("sendtimeout") == 0) internetOptions.sendTimeout = timeoutVal(value); else if(key.compare("receivetimeout") == 0) internetOptions.receiveTimeout = timeoutVal(value); else if(key.compare("username") == 0) internetOptions.login = STR(value); else if(key.compare("password") == 0) internetOptions.password = STR(value); else if(key.compare("proxymode") == 0) internetOptions.accessType = proxyVal(value); else if(key.compare("proxyusername") == 0) internetOptions.proxyLogin = STR(value); else if(key.compare("proxypassword") == 0) internetOptions.proxyPassword = STR(value); else if(key.compare("proxyname") == 0) { internetOptions.proxyName = STR(value); if(!internetOptions.proxyName.empty()) internetOptions.accessType = INTERNET_OPEN_TYPE_PROXY; } }
int64_t Func_if::getIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&) { if (boolVal(parm[0], row, isNull) && !isNull) { return parm[1]->data()->getIntVal(row, isNull); } else { isNull = false; return parm[2]->data()->getIntVal(row, isNull); } }
IDB_Decimal Func_if::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&) { if (boolVal(parm[0], row, isNull)) { isNull = false; return parm[1]->data()->getDecimalVal(row, isNull); } else { isNull = false; return parm[2]->data()->getDecimalVal(row, isNull); } }
TEST(Type, Const) { auto five = Type::cns(5); EXPECT_LT(five, Type::Int); EXPECT_NE(five, Type::Int); EXPECT_TRUE(five.isConst()); EXPECT_EQ(5, five.intVal()); EXPECT_TRUE(five.isConst(Type::Int)); EXPECT_TRUE(five.isConst(5)); EXPECT_FALSE(five.isConst(5.0)); EXPECT_TRUE(Type::Gen.maybe(five)); EXPECT_EQ(Type::Int, five | Type::Int); EXPECT_EQ(Type::Int, five | Type::cns(10)); EXPECT_EQ(five, five | Type::cns(5)); EXPECT_EQ(five, Type::cns(5) & five); EXPECT_EQ(five, five & Type::Int); EXPECT_EQ(five, Type::Gen & five); EXPECT_EQ("Int<5>", five.toString()); EXPECT_EQ(five, five - Type::Arr); EXPECT_EQ(five, five - Type::cns(1)); EXPECT_EQ(Type::Bottom, five - Type::Int); EXPECT_EQ(Type::Bottom, five - five); EXPECT_EQ(Type::Int, five.dropConstVal()); EXPECT_TRUE(five.not(Type::cns(2))); auto True = Type::cns(true); EXPECT_EQ("Bool<true>", True.toString()); EXPECT_LT(True, Type::Bool); EXPECT_NE(True, Type::Bool); EXPECT_TRUE(True.isConst()); EXPECT_EQ(true, True.boolVal()); EXPECT_TRUE(Type::Uncounted.maybe(True)); EXPECT_FALSE(five <= True); EXPECT_FALSE(five > True); EXPECT_TRUE(five.not(True)); EXPECT_EQ(Type::Int | Type::Bool, five | True); EXPECT_EQ(Type::Bottom, five & True); EXPECT_TRUE(Type::Uninit.isConst()); EXPECT_TRUE(Type::InitNull.isConst()); EXPECT_FALSE(Type::Null.isConst()); EXPECT_FALSE((Type::Uninit | Type::Bool).isConst()); EXPECT_FALSE(Type::Int.isConst()); }
Variant SSATmp::variantVal() const { switch (type().toDataType()) { case KindOfUninit: case KindOfNull: // Upon return both will converted to KindOfNull anyway. return init_null(); case KindOfBoolean: return boolVal(); case KindOfInt64: return intVal(); case KindOfDouble: return dblVal(); case KindOfString: case KindOfStaticString: return Variant(const_cast<StringData*>(strVal())); case KindOfArray: return const_cast<ArrayData*>(arrVal()); default: always_assert(false); } }
TEST(Type, Const) { auto five = Type::cns(5); EXPECT_LT(five, Type::Int); EXPECT_NE(five, Type::Int); EXPECT_TRUE(five.isConst()); EXPECT_EQ(5, five.intVal()); EXPECT_TRUE(five.isConst(Type::Int)); EXPECT_TRUE(five.isConst(5)); EXPECT_FALSE(five.isConst(5.0)); EXPECT_TRUE(Type::Gen.maybe(five)); EXPECT_EQ(Type::Int, five | Type::Int); EXPECT_EQ(Type::Int, five | Type::cns(10)); EXPECT_EQ(five, five | Type::cns(5)); EXPECT_EQ(five, Type::cns(5) & five); EXPECT_EQ(five, five & Type::Int); EXPECT_EQ(five, Type::Gen & five); EXPECT_EQ("Int<5>", five.toString()); EXPECT_EQ(five, five - Type::Arr); EXPECT_EQ(five, five - Type::cns(1)); EXPECT_EQ(Type::Int, Type::Int - five); // conservative EXPECT_EQ(Type::Bottom, five - Type::Int); EXPECT_EQ(Type::Bottom, five - five); EXPECT_EQ(Type::PtrToGen, (Type::PtrToGen|Type::Nullptr) - Type::Nullptr); EXPECT_EQ(Type::Int, five.dropConstVal()); EXPECT_TRUE(five.not(Type::cns(2))); auto True = Type::cns(true); EXPECT_EQ("Bool<true>", True.toString()); EXPECT_LT(True, Type::Bool); EXPECT_NE(True, Type::Bool); EXPECT_TRUE(True.isConst()); EXPECT_EQ(true, True.boolVal()); EXPECT_TRUE(Type::Uncounted.maybe(True)); EXPECT_FALSE(five <= True); EXPECT_FALSE(five > True); EXPECT_TRUE(five.not(True)); EXPECT_EQ(Type::Int | Type::Bool, five | True); EXPECT_EQ(Type::Bottom, five & True); EXPECT_TRUE(Type::Uninit.isConst()); EXPECT_TRUE(Type::InitNull.isConst()); EXPECT_FALSE(Type::Null.isConst()); EXPECT_FALSE((Type::Uninit | Type::Bool).isConst()); EXPECT_FALSE(Type::Int.isConst()); auto array = make_packed_array(1, 2, 3, 4); auto arrData = ArrayData::GetScalarArray(array.get()); auto constArray = Type::cns(arrData); auto packedArray = Type::Arr.specialize(ArrayData::kPackedKind); auto mixedArray = Type::Arr.specialize(ArrayData::kMixedKind); EXPECT_TRUE(constArray <= packedArray); EXPECT_TRUE(constArray < packedArray); EXPECT_FALSE(packedArray <= constArray); EXPECT_TRUE(constArray <= constArray); EXPECT_FALSE(packedArray <= mixedArray); EXPECT_FALSE(mixedArray <= packedArray); EXPECT_FALSE(constArray <= mixedArray); EXPECT_EQ(constArray, constArray & packedArray); ArrayTypeTable::Builder ratBuilder; auto rat1 = ratBuilder.packedn(RepoAuthType::Array::Empty::No, RepoAuthType(RepoAuthType::Tag::Str)); auto ratArray1 = Type::Arr.specialize(rat1); auto rat2 = ratBuilder.packedn(RepoAuthType::Array::Empty::No, RepoAuthType(RepoAuthType::Tag::Int)); auto ratArray2 = Type::Arr.specialize(rat2); EXPECT_EQ(Type::Arr, ratArray1 & ratArray2); EXPECT_TRUE(ratArray1 < Type::Arr); EXPECT_TRUE(ratArray1 <= ratArray1); EXPECT_TRUE(ratArray1 < (Type::Arr|Type::Obj)); EXPECT_FALSE(ratArray1 < ratArray2); EXPECT_NE(ratArray1, ratArray2); auto packedRat = packedArray & ratArray1; EXPECT_EQ("Arr=PackedKind:N([Str])", packedRat.toString()); EXPECT_TRUE(packedRat <= packedArray); EXPECT_TRUE(packedRat < packedArray); EXPECT_TRUE(packedRat <= ratArray1); EXPECT_TRUE(packedRat < ratArray1); EXPECT_EQ(packedRat, packedRat & packedArray); EXPECT_EQ(packedRat, packedRat & ratArray1); }
Type Type::operator-(Type rhs) const { auto lhs = *this; if (rhs == TBottom) return lhs; if (lhs <= rhs) return TBottom; if (lhs.hasConstVal()) return lhs; // not covered by rhs. // If `rhs' has a constant value, but `lhs' doesn't, conservatively return // `lhs', rather than trying to represent things like "everything except // Int<24>". Boolean is a special case. if (rhs.m_hasConstVal) { if (rhs <= TBool && lhs <= TBool) { auto const res = !rhs.boolVal(); if (lhs.hasConstVal() && lhs.boolVal() != res) return TBottom; return cns(res); } return lhs; } // For each component C, we should subtract C_rhs from C_lhs iff every other // component of lhs that can intersect with C is subsumed by the // corresponding component of rhs. This prevents us from removing members of // lhs that weren't present in rhs, but would be casualties of removing // certain bits in lhs. // // As an example, consider PtrToRMembInt - PtrToRefStr. Simple subtraction of // each component would yield PtrToMembInt, but that would mean we removed // PtrToRefInt from the lhs despite it not being in rhs. Checking if Int is a // subset of Str shows us that removing Ref from lhs would erase types not // present in rhs. // // In practice, it's more concise to eagerly do each subtraction, then check // for components that went to Bottom as a way of seeing which components of // lhs were subsets of the corresponding components in rhs. When we find a // component that we weren't supposed to subtract, just restore lhs's // original value. auto bits = lhs.m_bits & ~rhs.m_bits; auto ptr = lhs.ptrKind() - rhs.ptrKind(); auto arrSpec = lhs.arrSpec() - rhs.arrSpec(); auto clsSpec = lhs.clsSpec() - rhs.clsSpec(); auto const have_gen_bits = (bits & kGen) != 0; auto const have_arr_bits = supports(bits, SpecKind::Array); auto const have_cls_bits = supports(bits, SpecKind::Class); auto const have_ptr = ptr != Ptr::Bottom; auto const have_arr_spec = arrSpec != ArraySpec::Bottom; auto const have_cls_spec = clsSpec != ClassSpec::Bottom; // ptr can only interact with clsSpec if lhs.m_bits has at least one kGen // member of kClsSpecBits. auto const have_ptr_cls = supports(lhs.m_bits & kGen, SpecKind::Class); // bits if (have_ptr) bits |= lhs.m_bits & kGen; if (have_arr_spec) bits |= lhs.m_bits & kArrSpecBits; if (have_cls_spec) bits |= lhs.m_bits & kClsSpecBits; // ptr if (have_gen_bits || have_arr_spec || (have_cls_spec && have_ptr_cls)) { ptr = lhs.ptrKind(); } // specs if (have_ptr || have_arr_bits) arrSpec = lhs.arrSpec(); if ((have_ptr && have_ptr_cls) || have_cls_bits) clsSpec = lhs.clsSpec(); return Type{bits, ptr}.specialize({arrSpec, clsSpec}); }
static void yaz_xml2query_operator(const xmlNode *ptr, Z_Operator **op, ODR odr, int *error_code, const char **addinfo) { const char *type = yaz_xml_get_prop((xmlNodePtr) ptr, "type"); if (!type) { *error_code = 1; *addinfo = "no operator type"; return; } *op = (Z_Operator*) odr_malloc(odr, sizeof(Z_Operator)); if (!strcmp(type, "and")) { (*op)->which = Z_Operator_and; (*op)->u.op_and = odr_nullval(); } else if (!strcmp(type, "or")) { (*op)->which = Z_Operator_or; (*op)->u.op_or = odr_nullval(); } else if (!strcmp(type, "not")) { (*op)->which = Z_Operator_and_not; (*op)->u.and_not = odr_nullval(); } else if (!strcmp(type, "prox")) { struct _xmlAttr *attr; Z_ProximityOperator *pop = (Z_ProximityOperator *) odr_malloc(odr, sizeof(*pop)); (*op)->which = Z_Operator_prox; (*op)->u.prox = pop; /* default values */ pop->exclusion = 0; pop->ordered = odr_booldup(odr, 1); pop->relationType = odr_intdup(odr, Z_ProximityOperator_Prox_lessThanOrEqual); pop->which = Z_ProximityOperator_known; pop->u.known = odr_intdup(odr, Z_ProxUnit_word); pop->distance = odr_intdup(odr, 1); for (attr = ptr->properties; attr; attr = attr->next) { const char *value = (const char *) attr->children->content; if (!xmlStrcmp(attr->name, BAD_CAST "type")) ; else if (!xmlStrcmp(attr->name, BAD_CAST "exclusion")) pop->exclusion = boolVal(odr, value); else if (!xmlStrcmp(attr->name, BAD_CAST "distance")) pop->distance = intVal(odr, value); else if (!xmlStrcmp(attr->name, BAD_CAST "ordered")) pop->ordered = boolVal(odr, value); else if (!xmlStrcmp(attr->name, BAD_CAST "relationType")) pop->relationType = intVal(odr, value); else if (!xmlStrcmp(attr->name, BAD_CAST "knownProximityUnit")) { pop->which = Z_ProximityOperator_known; pop->u.known = intVal(odr, value); } else if (!xmlStrcmp(attr->name, BAD_CAST "privateProximityUnit")) { pop->which = Z_ProximityOperator_private; pop->u.known = intVal(odr, value); } else { *error_code = 1; *addinfo = "bad proximity attribute"; break; } } } else { *error_code = 1; *addinfo = "bad operator type"; } }