void CMdbPara::SetNumber(register uint32 nFieldNo, register void* pVal, register uint32 nOperator) { switch(GetType(nFieldNo)) { case MDB_INT8_FIELD: SetInt8(nFieldNo, *(int8*)pVal, nOperator); break; case MDB_INT16_FIELD: SetInt16(nFieldNo, *(int16*)pVal, nOperator); break; case MDB_INT32_FIELD: SetInt32(nFieldNo, *(int32*)pVal, nOperator); break; case MDB_INT64_FIELD: SetInt64(nFieldNo, *(int64*)pVal, nOperator); break; case MDB_UINT8_FIELD: SetUInt8(nFieldNo, *(uint8*)pVal, nOperator); break; case MDB_UINT16_FIELD: SetUInt16(nFieldNo, *(uint16*)pVal, nOperator); break; case MDB_UINT32_FIELD: SetUInt32(nFieldNo, *(uint32*)pVal, nOperator); break; case MDB_UINT64_FIELD: SetUInt64(nFieldNo, *(uint64*)pVal, nOperator); break; case MDB_FLOAT_FIELD: SetFloat(nFieldNo, *(float*)pVal, nOperator); break; case MDB_DOUBLE_FIELD: SetDouble(nFieldNo, *(double*)pVal, nOperator); break; case MDB_DATE_FIELD: SetDate(nFieldNo, *(CDate*)pVal, nOperator); break; case MDB_TIME_FIELD: SetTime(nFieldNo, *(CTime*)pVal, nOperator); break; case MDB_DATETIME_FIELD: SetDateTime(nFieldNo, *(CDateTime*)pVal, nOperator); break; } }
bool Pb2Json::Json2Message(const Json& json, ProtobufMsg& message, bool str2enum) { auto descriptor = message.GetDescriptor(); auto reflection = message.GetReflection(); if (nullptr == descriptor || nullptr == reflection) return false; auto count = descriptor->field_count(); for (auto i = 0; i < count; ++i) { const auto field = descriptor->field(i); if (nullptr == field) continue; auto& value = json[field->name()]; if (value.is_null()) continue; if (field->is_repeated()) { if (!value.is_array()) { return false; } else { Json2RepeatedMessage(value, message, field, reflection, str2enum); continue; } } switch (field->type()) { case ProtobufFieldDescriptor::TYPE_BOOL: { if (value.is_boolean()) reflection->SetBool(&message, field, value.get<bool>()); else if (value.is_number_integer()) reflection->SetBool(&message, field, value.get<uint32_t>() != 0); else if (value.is_string()) { if (value.get<std::string>() == "true") reflection->SetBool(&message, field, true); else if (value.get<std::string>() == "false") reflection->SetBool(&message, field, false); } } break; case ProtobufFieldDescriptor::TYPE_ENUM: { auto const* pedesc = field->enum_type(); const ::google::protobuf::EnumValueDescriptor* pevdesc = nullptr; if (str2enum) { pevdesc = pedesc->FindValueByName(value.get<std::string>()); } else { pevdesc = pedesc->FindValueByNumber(value.get<int>()); } if (nullptr != pevdesc) { reflection->SetEnum(&message, field, pevdesc); } } break; case ProtobufFieldDescriptor::TYPE_INT32: case ProtobufFieldDescriptor::TYPE_SINT32: case ProtobufFieldDescriptor::TYPE_SFIXED32: { if (value.is_number()) reflection->SetInt32(&message, field, value.get<int32_t>()); } break; case ProtobufFieldDescriptor::TYPE_UINT32: case ProtobufFieldDescriptor::TYPE_FIXED32: { if (value.is_number()) reflection->SetUInt32(&message, field, value.get<uint32_t>()); } break; case ProtobufFieldDescriptor::TYPE_INT64: case ProtobufFieldDescriptor::TYPE_SINT64: case ProtobufFieldDescriptor::TYPE_SFIXED64: { if (value.is_number()) reflection->SetInt64(&message, field, value.get<int64_t>()); } break; case ProtobufFieldDescriptor::TYPE_UINT64: case ProtobufFieldDescriptor::TYPE_FIXED64: { if (value.is_number()) reflection->SetUInt64(&message, field, value.get<uint64_t>()); } break; case ProtobufFieldDescriptor::TYPE_FLOAT: { if (value.is_number()) reflection->SetFloat(&message, field, value.get<float>()); } break; case ProtobufFieldDescriptor::TYPE_DOUBLE: { if (value.is_number()) reflection->SetDouble(&message, field, value.get<double>()); } break; case ProtobufFieldDescriptor::TYPE_STRING: case ProtobufFieldDescriptor::TYPE_BYTES: { if (value.is_string()) reflection->SetString(&message, field, value.get<std::string>()); } break; case ProtobufFieldDescriptor::TYPE_MESSAGE: { if (value.is_object()) Json2Message(value, *reflection->MutableMessage(&message, field)); } break; default: break; } } return true; }
//============================================================================ // NNumber::SetValue : Set the value. //---------------------------------------------------------------------------- bool NNumber::SetValue(const NVariant &theValue) { UInt8 valueUInt8; UInt16 valueUInt16; UInt32 valueUInt32; UInt64 valueUInt64; SInt8 valueSInt8; SInt16 valueSInt16; SInt32 valueSInt32; SInt64 valueSInt64; Float32 valueFloat32; Float64 valueFloat64; int valueInt; long valueLong; NString valueString; // Set the value // // NVariant treats some unsized types as numeric, to support literal constants. if (theValue.GetValue(*this)) ; // Assigned to this else if (theValue.GetValue(valueUInt8)) SetUInt8(valueUInt8); else if (theValue.GetValue(valueUInt16)) SetUInt16(valueUInt16); else if (theValue.GetValue(valueUInt32)) SetUInt32(valueUInt32); else if (theValue.GetValue(valueUInt64)) SetUInt64(valueUInt64); else if (theValue.GetValue(valueSInt8)) SetSInt8(valueSInt8); else if (theValue.GetValue(valueSInt16)) SetSInt16(valueSInt16); else if (theValue.GetValue(valueSInt32)) SetSInt32(valueSInt32); else if (theValue.GetValue(valueSInt64)) SetSInt64(valueSInt64); else if (theValue.GetValue(valueFloat32)) SetFloat32(valueFloat32); else if (theValue.GetValue(valueFloat64)) SetFloat64(valueFloat64); else if (theValue.GetValue(valueInt)) SetSInt64(valueInt); else if (theValue.GetValue(valueLong)) SetSInt64(valueLong); else if (theValue.GetValue(valueString)) return(SetValue(valueString)); else return(false); return(true); }
bool Cx_CfgRecord::SetRGB(const wchar_t* pszEntry, DWORD crValue) { return SetUInt32(pszEntry, crValue); }