MCPcopy Create free account
hub / github.com/FoundationDB/fdb-document-layer / doubleDispatchArithmetic

Function doubleDispatchArithmetic

src/ExtOperator.actor.cpp:327–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325
326template <class Op>
327DataValue doubleDispatchArithmetic(DataValue valueInDatabase, DataValue valueToAdd, Op op) {
328 switch (valueInDatabase.getBSONType()) {
329 case bson::BSONType::NumberDouble: {
330 switch (valueToAdd.getBSONType()) {
331 case bson::BSONType::NumberDouble:
332 return DataValue((double)op(valueInDatabase.getDouble(), valueToAdd.getDouble()));
333 case bson::BSONType::NumberLong:
334 return DataValue((double)op(valueInDatabase.getDouble(), valueToAdd.getLong()));
335 case bson::BSONType::NumberInt:
336 return DataValue((double)op(valueInDatabase.getDouble(), valueToAdd.getInt()));
337 default:
338 break;
339 }
340 break;
341 }
342 case bson::BSONType::NumberLong: {
343 switch (valueToAdd.getBSONType()) {
344 case bson::BSONType::NumberDouble:
345 return DataValue((double)op(valueInDatabase.getLong(), valueToAdd.getDouble()));
346 case bson::BSONType::NumberLong:
347 return DataValue((long long)op(valueInDatabase.getLong(), valueToAdd.getLong()));
348 case bson::BSONType::NumberInt:
349 return DataValue((long long)op(valueInDatabase.getLong(), valueToAdd.getInt()));
350 default:
351 break;
352 }
353 break;
354 }
355 case bson::BSONType::NumberInt: {
356 switch (valueToAdd.getBSONType()) {
357
358 case bson::BSONType::NumberDouble:
359 return DataValue((double)op(valueInDatabase.getInt(), valueToAdd.getDouble()));
360 case bson::BSONType::NumberLong:
361 return DataValue((long long)op(valueInDatabase.getInt(), valueToAdd.getLong()));
362 case bson::BSONType::NumberInt:
363 return DataValue((int)op(valueInDatabase.getInt(), valueToAdd.getInt()));
364 default:
365 break;
366 }
367 break;
368 }
369 default:
370 break;
371 }
372 TraceEvent(SevError, "BD_doubleDispatchArithmeticError").error(internal_error());
373 throw internal_error();
374}
375
376ACTOR static Future<Void> getValueAndAdd(Reference<IReadWriteContext> cx,
377 Standalone<StringRef> path,

Callers 2

Calls 5

DataValueClass · 0.85
getBSONTypeMethod · 0.80
getDoubleMethod · 0.80
getLongMethod · 0.80
getIntMethod · 0.80

Tested by

no test coverage detected