Code Monkey home page Code Monkey logo

jcore's Introduction

JCore

Some utility classes

  • OPF (drafts)
  • Dependency Injection Container
  • Expression Parser

OPF

Drafts of a persistence framework. Features being implemented:

  • Entities inherits from TObject and declares native data types
  • Support of any data type, registering new data mediators for unsupported PTypeInfos
  • Auto and manual mapping (object <-> storage mechanism)
  • Auto and manual model (class infos; metadata)
  • Native drivers -- mapping straight to database: no mediators or conversions
  • Bulk retrieve -- instantiate lots of objects with one query
  • Lazy loading -- load objects or attributes only on demand
  • TDD -- test driven development
  • Lazarus wizards for manual mappings, manual model and persistence configuration
  • API docs

First alpha: Dec/2014

Dependency Injection Container

Classes which help you separate specifications from implementations, as well as give you the hability to override default implementation from a framework with your own classes.

  • Declare your specification using interfaces
  • Register at least one implementation
  • Inject an implementation
  • Support of qualifiers

Samples:

TJCoreDIC.Register(IYourIntf, TYourImpl, jdsApplication);
...
TJCoreDIC.Locate(IYourIntf, VAnIntfVar);

Using qualifier:

TJCoreDIC.Register(IPayment, ‘cash’, TCashPayment, jdsApplication);
TJCoreDIC.Register(IPayment, ‘plastic’, TPlasticPayment, jdsApplication);
TJCoreDIC.Register(IPayment, ‘paypal’, TPaypalPayment, jdsApplication);
...
TJCoreDIC.Locate(IPayment, ‘paypal’, VPayment);

Expression Parser

An expression parser with an extensible function and operation library as well as support to variables.

The library is as fast as it can be: when the formula is changed, it is parsed in order to create an array with all operations, in the correct order. All results are referenced and reused without moves and copies. Point to pointers.

A simple calc:

VExpression := TJCoreExpression.Create('2+2');
try
  writeln(VExpression.VarValue);
finally
  FreeAndNil(VExpression);
end;

Using vars:

VExpression := TJCoreExpression.Create;
try
  VExpression.Vars.Variable['x'] := 2;
  VExpression.ParseExpression('2+x');
  writeln(VExpression.VarValue);
  VExpression.Vars.Variable['x'] := 4;
  writeln(VExpression.VarValue);
finally
  FreeAndNil(VExpression);
end;

User defined function:

TSinFunction = class(TJCoreExpressionFunction)
public
  function MaxParams: Integer; override;
  function MinParams: Integer; override;
  class function Name: string; override;
  procedure VarCalc; override;
end;

function TSinFunction.MaxParams: Integer;
begin
  Result := 1;
end;

function TSinFunction.MinParams: Integer;
begin
  Result := 1;
end;

class function TSinFunction.Name: string;
begin
  Result := 'sin';
end;

procedure TSinFunction.VarCalc;
begin
  Res^ := Sin(Params[0]^);
end;

begin
  JCoreExpressionLibrary.RegisterFunctions([TSinFunction]);
  VExpression := TJCoreExpression.Create('sin(30)');
  try
    writeln(VExpression.VarValue);
  finally
    FreeAndNil(VExpression);
  end;
end;

User defined operation:

TModOperation = class(TJCoreExpressionOperation)
protected
  class function InternalOperatorToken: string; override;
public
  function Priority: Byte; override;
  procedure VarCalc; override;
end;

class function TModOperation.InternalOperatorToken: string;
begin
  Result := 'mod';
end;

function TModOperation.Priority: Byte;
begin
  Result := 15;
end;

procedure TModOperation.VarCalc;
begin
  Res^ := Val1^ mod Val2^;
end;

begin
  JCoreExpressionLibrary.RegisterOperations([TModOperation]);
  VExpression := TJCoreExpression.Create('3 mod 1');
  try
    writeln(VExpression.VarValue);
  finally
    FreeAndNil(VExpression);
  end;
end;

jcore's People

Contributors

jcmoraisjr avatar mdbs99 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.