ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::expressions::plugins::ElvisOperator Struct Reference

Description:

The binary variant of ternary operator "Q ? T : F" is created by leaving out term 'T', which results in "A ? : B". This operator is often called "Elvis Operator" because ?: reminds people to an emoticon of singer Elvis Presley.

Usually the operator chooses 'A' in the case that 'A' can be interpreted as something like not null, not nulled or true in any means. Otherwise it selects 'B'. Due to the type-safe approach of ALib Expressions, the type of 'A' and 'B' must be equal, or at least an auto-cast has to exist that casts the types to a pair of equal types.

This built-in compiler plug-in covers the operator for virtually any type, including custom ones. The implementation invokes box-function FIsTrue on term 'A' and chooses 'A' if the interface returned true, otherwise it chooses 'B'.

Often, the elvis operator is used with strings. Because the default implementation of boxing interface FIsTrue returns true if the boxed value is an array type and the array length is not zero, with strings given (which are arrays of characters) only empty strings evaluate to false. This way the expression:

     "" ?: "Elvis"

rightfully evaluates to string "Elvis".

With this default implementation, it should be very seldom needed to define a custom Elvis-Operator for custom types.

Definition at line 37 of file elvisoperator.inl.

Inheritance diagram for alib::expressions::plugins::ElvisOperator:
[legend]
Collaboration diagram for alib::expressions::plugins::ElvisOperator:
[legend]

Public Method Index:

ALIB_DLL ElvisOperator (Compiler &compiler)
 
virtual ~ElvisOperator () override
 Virtual destructor.
 
virtual ALIB_DLL bool TryCompilation (CIBinaryOp &ciBinaryOp) override
 
- Public Method Index: inherited from alib::expressions::CompilerPlugin
 CompilerPlugin (const NString &name, Compiler &compiler, CompilePriorities pPriority)
 
virtual ~CompilerPlugin ()
 Virtual destructor.
 
virtual bool TryCompilation (CIAutoCast &ciAutoCast)
 
virtual bool TryCompilation (CIFunction &ciFunction)
 
virtual bool TryCompilation (CIUnaryOp &ciUnaryOp)
 
- Public Method Index: inherited from alib::lang::Plugin< Compiler, CompilePriorities >
PrioritiesType GetPriority () const
 

Additional Inherited Members

- Public Type Index: inherited from alib::lang::Plugin< Compiler, CompilePriorities >
using PluginType
 This exposes the template parameter TPlugin to the outer world.
 
using PrioritiesType
 This exposes the template parameter pTPlugin to the outer world.
 
- Public Field Index: inherited from alib::expressions::CompilerPlugin
CompilerCmplr
 The compiler that this plug-in is attached to.
 
const NString Name
 
- Protected Field Index: inherited from alib::lang::Plugin< Compiler, CompilePriorities >
PrioritiesType priority
 The priority of this plug-in.
 
- Protected Method Index: inherited from alib::lang::Plugin< Compiler, CompilePriorities >
 Plugin (PrioritiesType pPriority)
 

Constructor(s) / Destructor Details:

◆ ElvisOperator()

ALIB_DLL alib::expressions::plugins::ElvisOperator::ElvisOperator ( Compiler & compiler)

Constructor.

Parameters
compilerThe compiler we will get attached to.

◆ ~ElvisOperator()

virtual alib::expressions::plugins::ElvisOperator::~ElvisOperator ( )
inlineoverridevirtual

Virtual destructor.

Definition at line 48 of file elvisoperator.inl.

Method Details:

◆ TryCompilation()

virtual ALIB_DLL bool alib::expressions::plugins::ElvisOperator::TryCompilation ( CIBinaryOp & ciBinaryOp)
overridevirtual

Compiles binary elvis operator A ?: B if terms 'A' and 'B' share the same type.

Parameters
[in,out]ciBinaryOpThe compilation info struct.
Returns
true if an entry was found. false otherwise.

Reimplemented from alib::expressions::CompilerPlugin.


The documentation for this struct was generated from the following file: