Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Latest commit

History

107 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

PascalUtils

PascalUtils is an object library for delphi and FreePascal of data structures that implements syntactic sugar similar to that of other modern languages as far as syntax allows.

Table of contents

Requirements

Library is tested for

  • Embarcadero (R) Delphi 10.3 on Windows 7 Service Pack 1 (Version 6.1, Build 7601, 64-bit Edition)
  • Embarcadero (R) Delphi 11.0 Version 28.0.42600.6491 on Windows 10 (Version 10.0, Build 19042, 64-bit Edition)
  • FreePascal Compiler (3.2.0) and Lazarus IDE (2.0.10) on Ubuntu Linux 5.8.0-33-generic x86_64

Installation

Get the sources and add the source directory to the project search path. For FPC add the source directory to the fpc.cfg file.

Usage

Clone the repository git clone https://github.com/isemenkov/pascalutils.

Add the unit you want to use to the uses clause.

Data structures

TAny

TAny class describes a type-safe container for single value.

uses
utils.any;
typegeneric TAny<T> = class

TOptional

TOptional class represents an optional value: every TOptional is contains a value, or does not, like in Rust lang.

uses
utils.optional;
typegeneric TOptional<T> = class

More details read onwiki page.

TResult

Result types typically contain either a returned value or an error, and could provide first-class encapsulation of the common (value, err) pattern ubiquitous throughout Go programs.

uses
utils.result;
typegeneric TResult<V, E> = class

More details read onwiki page.

TVoidResult

TVoidResult contains Ok flag or error type like in GO or Rust languages. It is a specialized TResult type with no value.

uses
utils.result;
typegeneric TVoidResult<E> = class

More details read onwiki page.

TDataSize

TDataSize class provide the interface to manipulate data sizes.

uses
utils.datasize;
type
TDataSize = class

More details read onwiki page.

TTimeInterval

TTimeInterval class provide the interface to manipulate time intervals.

uses
utils.timeinterval;
type
TTimeInterval = class

More details read onwiki page.

TPair

TPair class couples together a pair of values, which may be of different types (T1 and T2). The individual values can be accessed through its public members first and second, like in C++ language.

uses
utils.pair;
typegeneric TPair<T1, T2> = class

More details read onwiki page.

TTuple

TTuple is an object capable to hold a collection of elements. Each element can be of a different type, like in C++ language.

uses
utils.tuple;
typegeneric TTuple3<T1, T2, T3> = classgeneric TTuple4<T1, T2, T3, T4> = classgeneric TTuple5<T1, T2, T3, T4, T5> = classgeneric TTuple6<T1, T2, T3, T4, T5, T6> = classgeneric TTuple7<T1, T2, T3, T4, T5, T6, T7> = classgeneric TTuple8<T1, T2, T3, T4, T5, T6, T7, T8> = classgeneric TTuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = classgeneric TTuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = class

More details read onwiki page.

TVariant

TVariant is class template which represents a type-safe union. An instance of TVariant at any given time either holds a value of one of its alternative types.

uses
utils.variant;
typegeneric TVariant2<T1, T2> = classgeneric TVariant3<T1, T2, T3> = classgeneric TVariant4<T1, T2, T3, T4> = classgeneric TVariant5<T1, T2, T3, T4, T5> = classgeneric TVariant6<T1, T2, T3, T4, T5, T6> = classgeneric TVariant7<T1, T2, T3, T4, T5, T6, T7> = classgeneric TVariant8<T1, T2, T3, T4, T5, T6, T7, T8> = classgeneric TVariant9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = classgeneric TVariant10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = class

More details read onwiki page.

TUnaryFunctor

Functor is instance of a class with member function Call defined. This member function allows the object to be used with the same syntax as a regular function call, and therefore its type can be used as template parameter when a generic function type is expected.

uses
utils.functor;
typegeneric TUnaryFunctor<V, R> = class

More details read onwiki page.

TBinaryFunctor

Functor is instance of a class with member function Call defined. This member function allows the object to be used with the same syntax as a regular function call, and therefore its type can be used as template parameter when a generic function type is expected.

uses
utils.functor;
typegeneric TBinaryFunctor<V, R> = class

More details read onwiki page.

TUnsortablefunctor

It is a special compare functor that return 0 (zero) all times. Real values not used. This functor can be used for containers for unsortable values.

uses
utils.functor;
type TUnsortableFunctor = class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Integer>);

More details read onwiki page.

TDefaultCompareFunctor

It is a functor which return a negative value if AValue1 should be sorted before AValue2, a positive value if AValue1 should be sorted after AValue2, zero if AValue1 and AValue2 are equal.

uses
utils.functor;
typegeneric TDefaultCompareFunctor<V> = class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Integer>)
publicfunctionCall(AValue1, AValue2 : V) : Integer;
end;

More details read onwiki page.

TDefaultLessFunctor

It is a functor which return True if AValue1 < AValue2.

uses
utils.functor;
typegeneric TDefaultLessFunctor<V> =
class ({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Boolean>);

More details read onwiki page.

TDefaultGreaterFunctor

It is a functor which return True if AValue1 > AValue2.

uses
utils.functor;
typegeneric TDefaultGreaterFunctor<V> =
class ({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Boolean>);

More details read onwiki page.

TDefaultEqualFunctor

It is a functor which return True if AValue1 = AValue2.

uses
utils.functor;
typegeneric TDefaultEqualFunctor<V> =
class ({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Boolean>);

More details read onwiki page.

TDefaultPairKeyCompareFunctor

It is a functor which return a negative value if pair 1 key should be sorted before pair 2 key, a positive value if pair 1 key should be sorted after pair 2 key, zero if pair 1 key and pair 2 key are equal.

uses
utils.functor, utils.pair;
usesgeneric TDefaultPairKeyCompareFunctor<K, V> =
class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor
<{$IFDEF FPC}specialize{$ENDIF} TPair<K, V>, Integer>)

More details read onwiki page.

API.CString

API.CString is a wrapper around C language API cstring char * value.

uses
utils.api.cstring;
type
API = classtype
CString = classend;

More details read onwiki page.

Errors processing

TArrayErrorsStack

TArrayErrorsStack is generic stack over array of T which contains errors codes.

uses
utils.errorsstack;
typegeneric TArrayErrorsStack<T> = class

More details read onwiki page.

TListErrorsStack

TListErrorsStack is generic stack over list of T classes which contains errors codes.

uses
utils.errorsstack;
typegeneric TListErrorsStack<T> = class

More details read onwiki page.

Iterators

TForwardIterator

TForwardIterator is a base class for custom forward direction iterators.

uses
utils.enumerate;
typegeneric TForwardIterator<V, Iterator> = class

More details read onwiki page.

TBidirectionalIterator

TBidirectionalIterator is a base class for custom forward and backward directions iterators.

uses
utils.enumerate;
typegeneric TBidirectionalIterator<V, Iterator> = class

More details read onwiki page.

TEnumerator

TEnumerator class adds counter to an iterable objects what have iterator based on TForwardIterator or TBidirectionalIterator and returns it (the enumerate object) like in a Python language.

uses
utils.enumerate;
typegeneric TEnumerator<V, Iterator> = class

More details read onwiki page.

TFilterEnumerator

TFilterEnumerator class provides filtering enumerator by UnaryFunctor.

uses
utils.enumerate, utils.functor;
typegeneric TFilterEnumerator<V, Iterator, Functor> = class

Functor is based on utils.functor.TUnaryFunctor interface and used to filtering item value.

More details read onwiki page.

TAccumulate

TAccumulate accumulated values using binary functions (specified via the Functor argument).

uses
utils.functional, utils.functor;
typegeneric TAccumulate<V, Iterator, Functor> = class

Functor is based on utils.functor.TBinaryFunctor interface and used to accumulate the result value.

More details read onwiki page.

TMap

TMap applying the given functor to each item of a given iterable object).

uses
utils.functional, utils.functor;
typegeneric TMap<V, Iterator, Functor> = class

Functor is based on utils.functor.TUnaryFunctor interface and used to modify item value.

More details read onwiki page.

About

PascalUtils is an object library for delphi and FreePascal of data structures that implements syntactic sugar similar to that of other modern languages as far as syntax allows.

Topics

Resources

Stars

35 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages