Skip to content

Commit

Permalink
Implemented Ansi/Unicode ValueSpace values. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 7, 2024
1 parent 0e66b32 commit 6eea3b6
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Source/BoldDefaultStreamNames.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface

var
BoldContentName_String: string;
BoldContentName_AnsiString: string;
BoldContentName_UnicodeString: string;
BoldContentName_Integer: string;
BoldContentName_Float: string;
BoldContentName_Currency: string;
Expand All @@ -46,6 +48,8 @@ initialization
BoldContentName_ObjectIdListRef := BoldSharedStringManager.GetSharedString('ObjectIdListRef');
BoldContentName_ObjectIdListRefPair := BoldSharedStringManager.GetSharedString('ObjectIdListRefPair');
BoldContentName_String := BoldSharedStringManager.GetSharedString('String');
BoldContentName_AnsiString := BoldSharedStringManager.GetSharedString('AnsiString');
BoldContentName_UnicodeString := BoldSharedStringManager.GetSharedString('UnicodeString');
BoldContentName_Integer := BoldSharedStringManager.GetSharedString('Integer');
BoldContentName_Float := BoldSharedStringManager.GetSharedString('Float');
BoldContentName_Currency := BoldSharedStringManager.GetSharedString('Currency');
Expand Down
205 changes: 183 additions & 22 deletions Source/BoldFreeStandingValues.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ TBoldFSObjectContentList = class;

TBoldFreeStandingValue = class;
TBFSString = class;
TBFSAnsiString = class;
TBFSUnicodeString = class;
TBFSInteger = class;
TBFSFloat = class;
TBFSCurrency = class;
Expand Down Expand Up @@ -219,6 +221,42 @@ TBFSString = class(TBoldFreeStandingNullableValue, IBoldStringContent)
property AsString: String read GetContentAsString write SetContentAsString;
end;

{ TBFSAnsiString }
TBFSAnsiString = class(TBoldFreeStandingNullableValue, IBoldAnsiStringContent)
private
fDataValue: AnsiString;
procedure SetContentAsAnsiString(const NewValue: TBoldAnsiString);
function GetContentAsAnsiString: TBoldAnsiString;
procedure SetContentAsString(const NewValue: String);
protected
function GetContentAsString: String; override;
function GetStreamName: string; override;
procedure AssignContentValue(const Source: IBoldValue); override;
function GetValueAsVariant: Variant; override;
public
class function ContentType: TBoldValueContentType; override;
function IsEqualToValue(const Value: IBoldValue): Boolean; override;
property AsAnsiString: AnsiString read GetContentAsAnsiString write SetContentAsAnsiString;
end;

{ TBFSUnicodeString }
TBFSUnicodeString = class(TBoldFreeStandingNullableValue, IBoldUnicodeStringContent)
private
fDataValue: UnicodeString;
procedure SetContentAsUnicodeString(const NewValue: TBoldUnicodeString);
function GetContentAsUnicodeString: TBoldUnicodeString;
procedure SetContentAsString(const NewValue: String);
protected
function GetContentAsString: String; override;
function GetStreamName: string; override;
procedure AssignContentValue(const Source: IBoldValue); override;
function GetValueAsVariant: Variant; override;
public
class function ContentType: TBoldValueContentType; override;
function IsEqualToValue(const Value: IBoldValue): Boolean; override;
property AsUnicodeString: UnicodeString read GetContentAsUnicodeString write SetContentAsUnicodeString;
end;

{ TBFSCurrency }
TBFSCurrency = class(TBoldFreeStandingNullableValue, IBoldCurrencyContent)
private
Expand Down Expand Up @@ -862,6 +900,151 @@ procedure TBFSString.SetContentAsString(const NewValue: String);
SetToNonNull;
end;

procedure TBFSString.AssignContentValue(const Source: IBoldValue);
var
s: IBoldStringContent;
begin
if source.QueryInterface(IBoldStringContent, S) = S_OK then
if s.IsNull then
SetContentToNull
else
SetContentAsString(s.AsString)
else
raise EBold.CreateFmt(sUnknownTypeOfSource, [classname, sAssignContentValue]);
end;

function TBFSString.IsEqualToValue(const Value: IBoldValue): Boolean;
var
aStringValue: IBoldStringContent;
begin
Result := inherited IsEqualToValue(Value) and
(Value.QueryInterface(IBoldStringContent, aStringValue) = S_OK) and
(AsString = aStringValue.asString);
end;

{ TBFSAnsiString }

procedure TBFSAnsiString.AssignContentValue(const Source: IBoldValue);
var
s: IBoldAnsiStringContent;
begin
if source.QueryInterface(IBoldAnsiStringContent, S) = S_OK then
if s.IsNull then
SetContentToNull
else
SetContentAsAnsiString(s.asAnsiString)
else
raise EBold.CreateFmt(sUnknownTypeOfSource, [classname, sAssignContentValue]);
end;

class function TBFSAnsiString.ContentType: TBoldValueContentType;
begin
result := bctAnsiString;
end;

function TBFSAnsiString.GetContentAsAnsiString: TBoldAnsiString;
begin
result := fDataValue;
end;

function TBFSAnsiString.GetContentAsString: String;
begin
result := String(fDataValue);
end;

function TBFSAnsiString.GetStreamName: string;
begin
result := BoldContentName_AnsiString;
end;

function TBFSAnsiString.GetValueAsVariant: Variant;
begin
result := AsAnsiString;
end;

function TBFSAnsiString.IsEqualToValue(const Value: IBoldValue): Boolean;
var
aAnsiStringValue: IBoldAnsiStringContent;
begin
Result := inherited IsEqualToValue(Value) and
(Value.QueryInterface(IBoldAnsiStringContent, aAnsiStringValue) = S_OK) and
(AsAnsiString = aAnsiStringValue.asAnsiString);
end;

procedure TBFSAnsiString.SetContentAsAnsiString(const NewValue: TBoldAnsiString);
begin
fDataValue := NewValue; // Use BoldSharedStringManager ?
SetToNonNull;
end;

procedure TBFSAnsiString.SetContentAsString(const NewValue: String);
begin
fDataValue := AnsiString(NewValue); // Use BoldSharedStringManager ?
SetToNonNull;
end;

{ TBFSUnicodeString }

procedure TBFSUnicodeString.AssignContentValue(const Source: IBoldValue);
var
s: IBoldUnicodeStringContent;
begin
if source.QueryInterface(IBoldUnicodeStringContent, S) = S_OK then
if s.IsNull then
SetContentToNull
else
SetContentAsUnicodeString(s.asUnicodeString)
else
raise EBold.CreateFmt(sUnknownTypeOfSource, [classname, sAssignContentValue]);
end;

class function TBFSUnicodeString.ContentType: TBoldValueContentType;
begin
result := bctUnicodeString;
end;

function TBFSUnicodeString.GetContentAsString: String;
begin
result := fDataValue;
end;

function TBFSUnicodeString.GetContentAsUnicodeString: TBoldUnicodeString;
begin
result := fDataValue;
end;

function TBFSUnicodeString.GetStreamName: string;
begin
result := BoldContentName_UnicodeString;
end;

function TBFSUnicodeString.GetValueAsVariant: Variant;
begin
result := AsUnicodeString;
end;

function TBFSUnicodeString.IsEqualToValue(const Value: IBoldValue): Boolean;
var
aUnicodeStringValue: IBoldUnicodeStringContent;
begin
Result := inherited IsEqualToValue(Value) and
(Value.QueryInterface(IBoldUnicodeStringContent, aUnicodeStringValue) = S_OK) and
(AsUnicodeString = aUnicodeStringValue.asUnicodeString);
end;

procedure TBFSUnicodeString.SetContentAsString(const NewValue: String);
begin
fDataValue := NewValue; // Use BoldSharedStringManager ?
SetToNonNull;
end;

procedure TBFSUnicodeString.SetContentAsUnicodeString(
const NewValue: TBoldUnicodeString);
begin
fDataValue := NewValue; // Use BoldSharedStringManager ?
SetToNonNull;
end;

{---TBFSCurrency---}

function TBFSCurrency.GetStreamName: String;
Expand Down Expand Up @@ -1436,28 +1619,6 @@ function TBFSInteger.IsEqualToValue(const Value: IBoldValue): Boolean;
(AsInteger = aIntegerValue.asInteger);
end;

procedure TBFSString.AssignContentValue(const Source: IBoldValue);
var
s: IBoldStringContent;
begin
if source.QueryInterface(IBoldStringContent, S) = S_OK then
if s.IsNull then
SetContentToNull
else
SetContentAsString(s.AsString)
else
raise EBold.CreateFmt(sUnknownTypeOfSource, [classname, sAssignContentValue]);
end;

function TBFSString.IsEqualToValue(const Value: IBoldValue): Boolean;
var
aStringValue: IBoldStringContent;
begin
Result := inherited IsEqualToValue(Value) and
(Value.QueryInterface(IBoldStringContent, aStringValue) = S_OK) and
(AsString = aStringValue.asString);
end;

procedure TBFSCurrency.AssignContentValue(const Source: IBoldValue);
var
s: IBoldCurrencyContent;
Expand Down
2 changes: 2 additions & 0 deletions Source/BoldValueInterfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ interface
bctValueSpace,
bctObject,
bctString,
bctAnsiString,
bctUnicodeString,
bctCurrency,
bctFloat,
bctInteger,
Expand Down

0 comments on commit 6eea3b6

Please sign in to comment.