org.extex.unit.base.conditional
Class AbstractIf

java.lang.Object
  extended by org.extex.interpreter.type.AbstractCode
      extended by org.extex.unit.base.conditional.AbstractIf
All Implemented Interfaces:
java.io.Serializable, Code, ExpandableCode, PrefixCode
Direct Known Subclasses:
If, Ifcase, Ifcat, Ifcsname, Ifdefined, Ifdim, Ifeof, Iffalse, Iffontchar, Ifhbox, Ifhmode, Ifinner, Ifmmode, Ifnum, Ifodd, Iftrue, Ifvbox, Ifvmode, Ifvoid, Ifx

public abstract class AbstractIf
extends AbstractCode
implements ExpandableCode, PrefixCode

This is the abstract base class for all ifs.

If you want to implement an if-like primitive you should derive it from this class. All you have to do is to implement the method conditional(). Here you define the expression evaluated to determine whether the if or the else branch should be taken.

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

Field Summary
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
AbstractIf(CodeToken token)
          Creates a new object.
 
Method Summary
abstract  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. 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.
 void expand(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          This method takes the first token and expands it.
protected static Localizer getMyLocalizer()
          Getter for the localizer.
 boolean isIf()
          The ifs are characterized by the return value true of this method.
static boolean skipToElseOrFi(Context context, TokenSource source, CodeToken primitive)
          Skip to the next matching \fi or \else Token counting the intermediate \ifs and \fis.
 
Methods inherited from class org.extex.interpreter.type.AbstractCode
getLocalizer, getName, getToken, isOuter, readResolve, toString, toText, toText
 
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
Constructor Detail

AbstractIf

public AbstractIf(CodeToken token)
Creates a new object.

Parameters:
token - the initial token for the primitive
Method Detail

getMyLocalizer

protected static Localizer getMyLocalizer()
Getter for the localizer.

Returns:
the localizer

skipToElseOrFi

public static boolean skipToElseOrFi(Context context,
                                     TokenSource source,
                                     CodeToken primitive)
                              throws HelpingException
Skip to the next matching \fi or \else Token counting the intermediate \ifs and \fis.

This method implements the absorption of tokens at high speed.

Parameters:
context - the interpreter context
source - the source for new tokens
primitive - the name of the invoking primitive
Returns:
true if a matching \else has been found; otherwise return false if a matching \fi has been found
Throws:
HelpingException - in case of en error

conditional

public abstract boolean conditional(Context context,
                                    TokenSource source,
                                    Typesetter typesetter)
                             throws HelpingException,
                                    TypesetterException
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.

Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the boolean value
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
ConfigurationException - in case of an configuration error

execute

public void execute(Flags prefix,
                    Context context,
                    TokenSource source,
                    Typesetter typesetter)
             throws HelpingException,
                    TypesetterException
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 AbstractCode
Parameters:
prefix - the prefix controlling the execution
context - the interpreter context
source - the token source
typesetter - the typesetter
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
AbstractCode.execute( org.extex.interpreter.Flags, org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)

expand

public void expand(Flags prefix,
                   Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws HelpingException,
                   TypesetterException
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
Parameters:
prefix - the prefix flags controlling the expansion
context - the interpreter context
source - the token source
typesetter - the typesetter
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
ExpandableCode.expand( org.extex.interpreter.Flags, org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)

isIf

public boolean isIf()
The ifs are characterized by the return value true of this method. Thus the overwritten method returning the constant is provided in this abstract base class.

Specified by:
isIf in interface Code
Overrides:
isIf in class AbstractCode
Returns:
true iff this is some sort if \if.
See Also:
Code.isIf()