de.dante.extex.interpreter.primitives.conditional
Class Ifcase

java.lang.Object
  extended byde.dante.extex.interpreter.type.AbstractCode
      extended byde.dante.extex.interpreter.primitives.conditional.AbstractIf
          extended byde.dante.extex.interpreter.primitives.conditional.Ifcase
All Implemented Interfaces:
Code, ExpandableCode, Localizable, java.io.Serializable

public class Ifcase
extends AbstractIf

This class provides an implementation for the primitive \ifcase.

The Primitive \ifcase

The primitive \ifcase provides a conditional switch on a numeric value. The next tokens are used as a number. This number determines which branch to expand. The first branch follows the number immediately. This branch is associated to the number 0.

The primitive \or advances to the next branch. The primitive \else starts the else branch. The else branch is used if no other branch fits.

Syntax

The formal description of this primitive is the following:
    ⟨ifcase⟩
     → \ifcase ⟨number⟩  ⟨cases⟩ \fi

    ⟨cases⟩
     →
      |  ⟨branch text⟩ \else ⟨else text⟩
      |  ⟨branch text⟩ \or ⟨cases⟩  

Examples

    \ifcase\count0 a\or b\or c\else x\fi  

Version:
$Revision: 1.34 $
Author:
Gerd Neugebauer
See Also:
Serialized Form

Nested Class Summary
protected static class Ifcase.Tag
          This is an internal class for type-safe values.
 
Field Summary
protected static Ifcase.Tag ELSE
          The constant ELSE contains the value indicating an \else.
protected static Ifcase.Tag FI
          The constant FI contains the value indicating a \fi.
protected static Ifcase.Tag OR
          The constant OR contains the value indicating an \or.
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
Ifcase(java.lang.String name)
          Creates a new object.
 
Method Summary
protected  boolean conditional(Context context, TokenSource source, Typesetter typesetter)
          This method computes the boolean value of the conditional.
 void execute(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          This method takes the first token and executes it.
 void expand(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          This method takes the first token and expands it.
 
Methods inherited from class de.dante.extex.interpreter.primitives.conditional.AbstractIf
getMyLocalizer, isIf, skipToElseOrFi
 
Methods inherited from class de.dante.extex.interpreter.type.AbstractCode
enableLocalization, getLocalizer, getName, isOuter, printable, printableControlSequence, readResolve, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values

OR

protected static final Ifcase.Tag OR
The constant OR contains the value indicating an \or.


ELSE

protected static final Ifcase.Tag ELSE
The constant ELSE contains the value indicating an \else.


FI

protected static final Ifcase.Tag FI
The constant FI contains the value indicating a \fi.

Constructor Detail

Ifcase

public Ifcase(java.lang.String name)
Creates a new object.

Parameters:
name - the name for debugging
Method Detail

execute

public void execute(Flags prefix,
                    Context context,
                    TokenSource source,
                    Typesetter typesetter)
             throws InterpreterException
Description copied from interface: Code
This method takes the first token and executes it. The result is placed on the stack. This operation might have side effects. To execute a token it might be necessary to consume further tokens.

Specified by:
execute in interface Code
Overrides:
execute in class AbstractIf
Throws:
InterpreterException
See Also:
Code.execute( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

expand

public void expand(Flags prefix,
                   Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws InterpreterException
Description copied from interface: ExpandableCode
This method takes the first token and expands it. The result is placed on the stack. This means that expandable code does one step of expansion and puts the result on the stack. To expand a token it might be necessary to consume further tokens.

Specified by:
expand in interface ExpandableCode
Overrides:
expand in class AbstractIf
Throws:
InterpreterException
See Also:
ExpandableCode.expand( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

conditional

protected boolean conditional(Context context,
                              TokenSource source,
                              Typesetter typesetter)
Description copied from class: AbstractIf
This method computes the boolean value of the conditional. If the result is true then the then branch is expanded and the else branch is skipped. Otherwise the then branch is skipped and the else branch is expanded.

Specified by:
conditional in class AbstractIf
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the boolean value
See Also:
AbstractIf.conditional( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)