Made to Order Software Corporation Logo

libsswf: sswf::ActionBranch Class Reference

An action to change the execution pointer. More...

#include <libsswf.h>

Inheritance diagram for sswf::ActionBranch:

:Action :MemoryManager :ItemBase :MemBuffer

List of all members.

Public Member Functions

 ActionBranch (TagBase *tag, action_t action=ACTION_BRANCH_ALWAYS)
 Initialize an branch action.
void SetLabel (const char *label)
 Set the label this branch needs to branch to.

Private Member Functions

virtual ActionDuplicate (void) const
 Duplicate an ActionBranch object.
virtual ErrorManager::error_code_t Parse2ndPass (Vectors &list)
 Search the offset to place a label.
virtual ErrorManager::error_code_t ParseData (const Data &data)
 Parses a branch offset.
virtual ErrorManager::error_code_t Save2ndPass (const Vectors &list, Data &data)
 Save the real branch offset.
virtual ErrorManager::error_code_t SaveData (Data &data, Data &nested_data)
 Save a branch offset placeholder.

Private Attributes

unsigned long f_goto_offset
char * f_label

Detailed Description

The ActionBranch class is used to create a branch or jump from one place to another in your ActionScript. Depending on the type of Branch that you define, it will always be taken, or it will be taken only when the current value on the stack is true.

By default, if you do not specify the type of branch, it will always branch.

See also:
SWF Alexis' Reference—Branch Always

SWF Alexis' Reference—Branch If True

Constructor & Destructor Documentation

ActionBranch::ActionBranch ( TagBase tag,
action_t  action = ACTION_BRANCH_ALWAYS 

This function initializes an ActionBranch object. You can specify which action whether you want the branch to be conditional or not.

[in] tag The tag in which this action is being created
[in] action The branch to be created, one of: ACTION_BRANCH_ALWAYS or ACTION_BRANCH_IF_TRUE

References sswf::Action::ACTION_BRANCH_ALWAYS, sswf::Action::ACTION_BRANCH_IF_TRUE, sswf::assert(), and f_label.

Referenced by Duplicate().

Member Function Documentation

Action * ActionBranch::Duplicate ( void   )  const [private, virtual]

This function creates a new ActionBranch and copies the label from this ActionBranch to the new one.

The ActionBranch copy

Reimplemented from sswf::Action.

References ActionBranch(), sswf::Action::f_action, f_label, SetLabel(), and sswf::Action::Tag().

ErrorManager::error_code_t ActionBranch::Parse2ndPass ( Vectors list  )  [private, virtual]

This function is used on the second pass to add a label so the Branch is complete.

[in] list The list of actions.
An error code or ERROR_CODE_NONE.

Reimplemented from sswf::Action.

References sswf::ErrorManager::ERROR_CODE_LABEL_NOT_FOUND, sswf::ErrorManager::ERROR_CODE_NONE, f_goto_offset, sswf::Action::FindLabelAtOffset(), sswf::ActionLabel::GetLabel(), and SetLabel().

ErrorManager::error_code_t ActionBranch::ParseData ( const Data data  )  [private, virtual]

This function retrieves the offset of the branch from the Data buffer.

A label will be added on the second pass.

[in] data The Data buffer to be parsed

Reimplemented from sswf::Action.

References sswf::ErrorManager::ERROR_CODE_NONE, f_goto_offset, sswf::Action::f_offset, and sswf::Data::GetShort().

ErrorManager::error_code_t ActionBranch::Save2ndPass ( const Vectors list,
Data data 
) [private, virtual]

This function searches the whole list of actions for the label specified in the branch. If the label cannot be found, this is an error and the function fails.

When the label is found, the offset to that label is read and used to compute the offset we need to save in the branch byte codes.

If the branch cannot be generated because the offset is out of bounds (i.e. smaller than 0x8000 or larger than 0x7FFF) then an error is generated and the function fails.

[in] list The list of actions where the label is searched
[in] data The Data buffer where the resulting offset is saved

Reimplemented from sswf::Action.

References sswf::ErrorManager::ERROR_CODE_LABEL_NOT_FOUND, sswf::ErrorManager::ERROR_CODE_LABEL_OVERFLOW, sswf::ErrorManager::ERROR_CODE_NONE, f_label, sswf::Action::f_offset, sswf::Action::FindLabel(), sswf::Action::Offset(), sswf::Action::OnError(), and sswf::Data::OverwriteShort().

ErrorManager::error_code_t ActionBranch::SaveData ( Data data,
Data nested_data 
) [private, virtual]

This function saves 2 bytes which represent the offset where the branch needs to go.

Since at this time we cannot be sure of the exact offset (forward offset are not yet known), we just save an offset of zero. The Save2ndPass() will save the real offset.

[in] data The Data buffer where the offset is saved
[in] nested_data Branches have no nested data

Reimplemented from sswf::Action.

References sswf::ErrorManager::ERROR_CODE_NONE, and sswf::Data::PutShort().

void ActionBranch::SetLabel ( const char *  label  ) 

This function defines the label this branch needs to branch to. This label will be searched in the same block the ActionBranch is inserted in. (note that their is no 'if' block in byte code ActionScript.)

There should be an ActionLabel for each different label defined in ActionBranch objects.

At this time, we do not verify that the label is unique.
[in] label The label to branch to

References f_label, sswf::MemoryManager::MemFree(), and sswf::MemoryManager::StrDup().

Referenced by Duplicate(), and Parse2ndPass().

Member Data Documentation

unsigned long sswf::ActionBranch::f_goto_offset [private]

Referenced by Parse2ndPass(), and ParseData().

The documentation for this class was generated from the following files:

Generated on Wed Mar 18 15:13:57 2009 for libsswf by  doxygen 1.5.5