Open
Description
At present there is one method of TPJResourceFile
that can be used to find resources:
function FindEntry(const ResType, ResName: PChar;
const LangID: Word = $FFFF): TPJResourceEntry;
But this method only finds the first matching resource and the ability to specify search criteria is limited.
Searching would be improved if:
- All resources matching a criteria could be found.
- The user could specify the search criteria by means of a callback closure.
- Methods could check whether some or all entries match a condition.
- Methods could find sets of resource types & language ids matching certain criteria.
An iterator function and possibly a map function would also be useful.
Possible methods would be:
type
TPJResourceFile = class
public
// ...
function SelectEntries(Predicate: TPredicate<TPJResourceEntry>): TArray<TPJResourceEntry>;
function SomeEntries(Predicate: TPredicate<TPJResourceEntry>): Boolean;
function EveryEntry(Predicate: TPredicate<TPJResourceEntry>): Boolean;
procedure ForEachEntry(Callback: TProc<TPJResourceEntry>); overload;
procedure ForEachEntry(Predicate: TPredicate<TPJResourceEntry>; Callback: TProc<TPJResourceEntry>); overload;
function MapEntries<T>(Callback: TFunc<TPJResourceEntry,T>): TArray<T>; overload;
function MapEntries<T>(Predicate: TPredicate<TPJResourceEntry>; Callback: TFunc<TPJResourceEntry,T>): TArray<T>; overload;
function FindEntry(Predicate: TPredicate<TPJResourceEntry>): TPJResourceEntry; overload;
function FindEntryIndex(Predicate: TPredicate<TPJResourceEntry>): Boolean; overload;
function FindUniqueResTypes(Predicate: TPredicate<TPJResourceEntry>): TArray<string>;
function FindUniqueLanguageIDs(Predicate: TPredicate<TPJResourceEntry>): TArray<Word>;
// ...
end;
Descriptions:
SelectEntries
- Selects the resource entries matching the given predicate and returns an array of selected entries.SomeEntries
- Returns true if one or more resource entries match the given predicate else false. This is a generalised version of the existingEntryExists
method.EveryEntry
- Returns true if all resource entries match the given predicate else false.ForEachEntry
- Two overloaded methods. The first unconditionally calls the given callback for each resource entry. The 2nd only calls the callback if the given criteria are satisfied.MapEntries<T>
- Two overloaded methods that map resource entries onto some other type and returns an array of the new type. The first overload maps every resource while the second includes maps only entries that match the given criteria.FindEntry
- Overload of the existing method that finds and returns the first resource entry that matches the given predicate. Returns nil if there is no match.FindEntryIndex
- Overload of the existing method that finds the index of the first resource entry that matches the given predicate. Returns -1 if there is no match.FindUniqueResTypes
- Returns an array containing the set of string representations of the resource types of resource entries that match the given criteria.FindUniqueLanguageIDs
- Returns an array containing the set language IDs of resource entries that match the given criteria.