Fixed macro expansion
This commit is contained in:
@@ -63,10 +63,6 @@ type
|
||||
class operator Implicit(const AValue: String): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: TDataValue.TFunc): TDataValue; overload; inline;
|
||||
|
||||
// atomic operations
|
||||
function CompareAndSet(const Expected, NewValue: TDataValue): Boolean;
|
||||
function Reset(const NewValue: TDataValue): TDataValue;
|
||||
|
||||
class function FromIntf<T: IInterface>(const AValue: T): TDataValue; static;
|
||||
function AsIntf<T: IInterface>: T; inline;
|
||||
|
||||
@@ -229,53 +225,6 @@ begin
|
||||
Result := (FInterface as TVal<String>).Value;
|
||||
end;
|
||||
|
||||
function TDataValue.CompareAndSet(const Expected, NewValue: TDataValue): Boolean;
|
||||
|
||||
function IntfCompareExchange(var VTarget: IInterface; const AValue, Compare: IInterface): IInterface; inline;
|
||||
begin
|
||||
if AValue <> nil then
|
||||
AValue._AddRef;
|
||||
|
||||
Result := IInterface(TInterlocked.CompareExchange(Pointer(VTarget), Pointer(AValue), Pointer(Compare)));
|
||||
|
||||
if (AValue <> nil) and (Pointer(Result) <> Pointer(Compare)) then
|
||||
AValue._Release;
|
||||
end;
|
||||
|
||||
begin
|
||||
Result := false;
|
||||
if FKind <> Expected.Kind then
|
||||
exit;
|
||||
if FKind <> NewValue.Kind then
|
||||
raise EArgumentException.Create('Value kinds have to match');
|
||||
|
||||
if FKind = vkVoid then
|
||||
raise EArgumentException.Create('Value is void');
|
||||
|
||||
case FKind of
|
||||
vkScalar:
|
||||
case FScalar.Kind of
|
||||
TScalar.TKind.Ordinal, TScalar.TKind.Keyword:
|
||||
Result :=
|
||||
TInterlocked
|
||||
.CompareExchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64, Expected.AsScalar.Value.AsInt64)
|
||||
= Expected.AsScalar.Value.AsInt64;
|
||||
TScalar.TKind.Float:
|
||||
Result :=
|
||||
TInterlocked
|
||||
.CompareExchange(FScalar.Value.AsDouble, NewValue.AsScalar.Value.AsDouble, Expected.AsScalar.Value.AsDouble)
|
||||
= Expected.AsScalar.Value.AsDouble;
|
||||
end;
|
||||
vkPointer:
|
||||
Result :=
|
||||
TInterlocked.CompareExchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64, Expected.AsScalar.Value.AsInt64)
|
||||
= Expected.AsScalar.Value.AsInt64;
|
||||
|
||||
vkText, vkSeries, vkRecordSeries, vkRecord, vkGenericRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric:
|
||||
Result := IntfCompareExchange(FInterface, NewValue.FInterface, Expected.FInterface) = Expected.FInterface;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TDataValue.FromIntf<T>(const AValue: T): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkInterface;
|
||||
@@ -345,43 +294,6 @@ begin
|
||||
Result := TMapSeries.Create(SourceSeries, MapperFunc);
|
||||
end;
|
||||
|
||||
function TDataValue.Reset(const NewValue: TDataValue): TDataValue;
|
||||
|
||||
function IntfExchange(var VTarget: IInterface; const AValue: IInterface): IInterface; inline;
|
||||
begin
|
||||
if AValue <> nil then
|
||||
AValue._AddRef;
|
||||
|
||||
Result := IInterface(TInterlocked.Exchange(Pointer(VTarget), Pointer(AValue)));
|
||||
|
||||
if AValue <> nil then
|
||||
AValue._Release;
|
||||
end;
|
||||
|
||||
begin
|
||||
if FKind <> NewValue.Kind then
|
||||
raise EArgumentException.Create('Value kinds have to match');
|
||||
|
||||
if FKind = vkVoid then
|
||||
raise EArgumentException.Create('Value is void');
|
||||
|
||||
case FKind of
|
||||
vkScalar:
|
||||
case FScalar.Kind of
|
||||
TScalar.TKind.Ordinal, TScalar.TKind.Keyword:
|
||||
Result := TInterlocked.Exchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64);
|
||||
TScalar.TKind.Float: Result := TInterlocked.Exchange(FScalar.Value.AsDouble, NewValue.AsScalar.Value.AsDouble);
|
||||
end;
|
||||
vkPointer: Result := TInterlocked.Exchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64);
|
||||
|
||||
vkText, vkSeries, vkRecordSeries, vkRecord, vkGenericRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric:
|
||||
begin
|
||||
Result.FKind := FKind;
|
||||
Result.FInterface := IntfExchange(FInterface, NewValue.FInterface);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDataValue.ToString: String;
|
||||
var
|
||||
sb: TStringBuilder;
|
||||
|
||||
Reference in New Issue
Block a user