Skip to content

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.

License

Notifications You must be signed in to change notification settings

isemenkov/pascalutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

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;

type
  generic 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;
 
type
  generic TOptional<T> = class

More details read on wiki 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;
  
type
  generic TResult<V, E> = class

More details read on wiki 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;
  
type
  generic TVoidResult<E> = class

More details read on wiki page.

TDataSize

TDataSize class provide the interface to manipulate data sizes.

uses
  utils.datasize;

type
  TDataSize = class

More details read on wiki page.

TTimeInterval

TTimeInterval class provide the interface to manipulate time intervals.

uses
  utils.timeinterval;

type
  TTimeInterval = class

More details read on wiki 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;

type
  generic TPair<T1, T2> = class

More details read on wiki 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;

type
  generic TTuple3<T1, T2, T3> = class
  generic TTuple4<T1, T2, T3, T4> = class
  generic TTuple5<T1, T2, T3, T4, T5> = class
  generic TTuple6<T1, T2, T3, T4, T5, T6> = class
  generic TTuple7<T1, T2, T3, T4, T5, T6, T7> = class
  generic TTuple8<T1, T2, T3, T4, T5, T6, T7, T8> = class
  generic TTuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = class
  generic TTuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = class

More details read on wiki 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;

type
  generic TVariant2<T1, T2> = class
  generic TVariant3<T1, T2, T3> = class
  generic TVariant4<T1, T2, T3, T4> = class
  generic TVariant5<T1, T2, T3, T4, T5> = class
  generic TVariant6<T1, T2, T3, T4, T5, T6> = class
  generic TVariant7<T1, T2, T3, T4, T5, T6, T7> = class
  generic TVariant8<T1, T2, T3, T4, T5, T6, T7, T8> = class
  generic TVariant9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = class
  generic TVariant10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = class

More details read on wiki 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;
  
type
  generic TUnaryFunctor<V, R> = class

More details read on wiki 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;
  
type
  generic TBinaryFunctor<V, R> = class

More details read on wiki 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 on wiki 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;
  
type
  generic TDefaultCompareFunctor<V> = 
    class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Integer>)
  public
    function Call(AValue1, AValue2 : V) : Integer;
  end;

More details read on wiki page.

TDefaultLessFunctor

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

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

More details read on wiki page.

TDefaultGreaterFunctor

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

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

More details read on wiki page.

TDefaultEqualFunctor

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

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

More details read on wiki 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;
  
uses
  generic TDefaultPairKeyCompareFunctor<K, V> =
    class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor
    <{$IFDEF FPC}specialize{$ENDIF} TPair<K, V>, Integer>)

More details read on wiki page.

API.CString

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

uses
  utils.api.cstring;
  
type
  API = class
  type
    CString = class
  end;

More details read on wiki page.

Errors processing

TArrayErrorsStack

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

uses
  utils.errorsstack;

type
  generic TArrayErrorsStack<T> = class

More details read on wiki page.

TListErrorsStack

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

uses
  utils.errorsstack;

type
  generic TListErrorsStack<T> = class

More details read on wiki page.

Iterators

TForwardIterator

TForwardIterator is a base class for custom forward direction iterators.

uses
  utils.enumerate;

type
  generic TForwardIterator<V, Iterator> = class

More details read on wiki page.

TBidirectionalIterator

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

uses
  utils.enumerate;

type
  generic TBidirectionalIterator<V, Iterator> = class

More details read on wiki 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;

type
  generic TEnumerator<V, Iterator> = class

More details read on wiki page.

TFilterEnumerator

TFilterEnumerator class provides filtering enumerator by UnaryFunctor.

uses
  utils.enumerate, utils.functor;

type
  generic TFilterEnumerator<V, Iterator, Functor> = class

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

More details read on wiki page.

TAccumulate

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

uses
  utils.functional, utils.functor;

type
  generic TAccumulate<V, Iterator, Functor> = class

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

More details read on wiki page.

TMap

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

uses
  utils.functional, utils.functor;

type
  generic TMap<V, Iterator, Functor> = class

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

More details read on wiki 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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages