Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reusable condition/expression classes

I have needed in several occasions some classes to represent and manipulate conditions (typically in a UI so the user builds a query by combining different condition types and then the code can transform that depending on the underlying system to be queried, for example lucene and a db). I searched all over for a reusable set of classes, I am sure this has to be used in many existing places (all the expression languages for starters) but could not find anything easily usable. I ended up coding both times myself, but felt bad about not reusing something I am sure exists.

Typical needs are: - several operators: and or etc - variable number of operands - combining conditions to build expressions - serializing of expressions - parsing/formatting of expressions from/to strings

has somebody found something like that?

like image 213
Persimmonium Avatar asked May 07 '09 09:05

Persimmonium


1 Answers

It does sound like you might be looking for Functors (aka function objects). If so, this SO question would be relevant, wrt. choices: Commons functor (mentioned already) is one alternative but there are others too.

All functor libs come with the framework (which is quite simple; unary, binary predicates, mapping functionality for those, combining by chaining) and basic set of functions most commonly needed.

like image 143
StaxMan Avatar answered Nov 04 '22 13:11

StaxMan