void MenuBar::applyPropertiesDict(Color*color, const Dictionary&properties) { if(color == nullptr) { return; } Any r = properties.get("r"); Any g = properties.get("g"); Any b = properties.get("b"); Any a = properties.get("a"); if(!r.empty() && r.is<Number>()) { color->r = r.as<Number>(false).asUnsignedChar(); } if(!g.empty() && g.is<Number>()) { color->g = g.as<Number>(false).asUnsignedChar(); } if(!b.empty() && b.is<Number>()) { color->b = b.as<Number>(false).asUnsignedChar(); } if(!a.empty() && a.is<Number>()) { color->a = a.as<Number>(false).asUnsignedChar(); } }
void MenuBar::applyPropertiesDict(RectD*bounds, const Dictionary&properties) { if(bounds == nullptr) { return; } Any left = properties.get("left"); Any top = properties.get("top"); Any right = properties.get("right"); Any bottom = properties.get("bottom"); if(!left.empty() && left.is<Number>()) { bounds->left = left.as<Number>(false).asDouble(); } if(!top.empty() && top.is<Number>()) { bounds->top = top.as<Number>(false).asDouble(); } if(!right.empty() && right.is<Number>()) { bounds->right = right.as<Number>(false).asDouble(); } if(!bottom.empty() && bottom.is<Number>()) { bounds->bottom = bottom.as<Number>(false).asDouble(); } }
bool Any::operator == ( const Any& rhs ) const { if( (this == &rhs) || (empty() && rhs.empty( ))) return true; if( empty() != rhs.empty() || type() != rhs.type( )) return false; return *content == *rhs.content; }
void AnyTest::testEmptyCopy() { const Any null; Any copied = null, assigned; assigned = null; assert (null.empty()); assert (copied.empty()); assert (assigned.empty()); }
void AnyTest::testDefaultCtor() { const Any value; assert (value.empty()); assert (0 == AnyCast<int>(&value)); assert (value.type() == typeid(void)); }
void AnyTest::testConvertingCtor() { std::string text = "test message"; Any value = text; assert (!value.empty()); assert (value.type() == typeid(std::string)); assert (0 == AnyCast<int>(&value)); assert (0 != AnyCast<std::string>(&value)); assert (AnyCast<std::string>(value) == text); assert (AnyCast<std::string>(&value) != &text); }
void AnyTest::testConvertingAssign() { std::string text = "test message"; Any value; Any* assignResult = &(value = text); assert (!value.empty()); assert (value.type() == typeid(std::string)); assert (0 == AnyCast<int>(&value)); assert (0 != AnyCast<std::string>(&value)); assert (AnyCast<std::string>(value) == text); assert (AnyCast<std::string>(&value) != &text); assert (assignResult == &value); }
void AnyTest::testSwap() { std::string text = "test message"; Any original = text, swapped; std::string* originalPtr = AnyCast<std::string>(&original); Any* swapResult = &original.swap(swapped); assert (original.empty()); assert (!swapped.empty()); assert (swapped.type() == typeid(std::string)); assert (text == AnyCast<std::string>(swapped)); assert (0 != originalPtr); #ifdef POCO_NO_SOO // pointers only match when heap-allocated assert (originalPtr == AnyCast<std::string>(&swapped)); #endif assert (swapResult == &original); }
void AnyTest::testInt() { Any e; assert (e.empty()); Any a = 13; assert (a.type() == typeid(int)); int* i = AnyCast<int>(&a); assert (*i == 13); Any b = a; assert (b.type() == typeid(int)); int *cpyI = AnyCast<int>(&b); assert (*cpyI == *i); *cpyI = 20; assert (*cpyI != *i); std::string* s = AnyCast<std::string>(&a); assert (s == NULL); int tmp = AnyCast<int>(a); const Any c = a; tmp = AnyCast<int>(a); }
bool is_empty(Any const& operand) { return operand.empty(); }