bool Value::isIntegral() const { #if defined(JSON_HAS_INT64) return isInt64() || isUInt64(); #else return isInt() || isUInt(); #endif }
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); } } } }
/// Casting operator to extract a string value Tuple::operator std::string () { auto len = length(); std::string str; str.reserve(len); for (size_t i = 0; i < len; ++i) { auto v = (*this)[i]; if (!v.isInt64()) throw RunError("tuple to string cast found non-integer element"); str += (char)(int64_t)v; } return str; }
Value::Int64 Value::asInt64() const { switch (type_) { case intValue: return Int64(value_.int_); case uintValue: JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range"); return Int64(value_.uint_); case realValue: JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64), "double out of Int64 range"); return Int64(value_.real_); case nullValue: return 0; case booleanValue: return value_.bool_ ? 1 : 0; default: break; } JSON_FAIL_MESSAGE("Value is not convertible to Int64."); }
void AttributeWriter::addElement(NwkAddr nwkAddr, EndpointID endpointID, std::shared_ptr<zigbee::Cluster> cluster, Json::Value &&value, AttributeWriterResult &results) { auto jsonId = value["id"]; if (!jsonId.isInt()) { return; } int id = jsonId.asInt(); auto jsonType = value["type"]; if (!jsonType.isString()) { return; } auto jsonData = value["data"]; auto type = jsonType.asString(); auto zigbeeDevice = singletons.getZigbeeDevice(); auto attribute = cluster->getAttribute(id); auto &rawValue = attribute->getAttributeRawValue(); if (type == "string") { if (!jsonData.isString()) { return; } rawValue(jsonData.asString()); } else if (type == "int" && jsonData.isInt64()){ rawValue(jsonData.asInt64()); } else if (type == "raw" && jsonData.isArray()){ std::vector<uint8_t > rawData; for (Json::Value::ArrayIndex i = 0; i < jsonData.size(); i++) { rawData.push_back(jsonData[i].asInt()); } rawValue(rawData); } else { return; } zigbeeDevice->writeAttribute(nwkAddr, endpointID, cluster->getId(), id, rawValue.type, rawValue.rawData.size(), &rawValue.rawData[0]); results.add(id); }
// here we use DataTime instead of QT's built-in time conversion // since the latter does not properly handle fractions of seconds // in the ISO8601 specification. QString Soprano::LiteralValue::toString() const { if ( d ) { if ( !d->stringCacheValid ) { if( isInt() ) d->stringCache = QString::number( toInt() ); else if( isInt64() ) d->stringCache = QString::number( toInt64() ); else if( isUnsignedInt() ) d->stringCache = QString::number( toUnsignedInt() ); else if( isUnsignedInt64() ) d->stringCache = QString::number( toUnsignedInt64() ); else if( isBool() ) d->stringCache = ( toBool() ? QString("true") : QString("false" ) ); else if( isDouble() ) // FIXME: decide on a proper double encoding or check if there is one in xml schema d->stringCache = QString::number( toDouble(), 'e', 10 ); else if( isDate() ) d->stringCache = DateTime::toString( toDate() ); else if( isTime() ) d->stringCache = DateTime::toString( toTime() ); else if( isDateTime() ) d->stringCache = DateTime::toString( toDateTime() ); else if ( isByteArray() ) d->stringCache = QString::fromAscii( toByteArray().toBase64() ); else d->stringCache = d->value.toString(); d->stringCacheValid = true; } return d->stringCache; } else { return QString(); } }
hkInt64 getInt64() const { return isInt64() ? m_value.i64 : (isDouble() ? (hkInt64)m_value.d : 0); }
double getDouble() const { return isDouble() ? m_value.d : (isInt64() ? (double)m_value.i64 : 0); }
hkBool isNumber() const { return isDouble() || isInt64(); }