PlugSpace

PlugSpace

Stack
Stack Position Description
Stack(In) top object / object vector
Stack(Out) top -

Stack objects are registered as PlugSpace. 'PlugSpace' defines a context for parameter mediation as it is used in formula calculation (class CX_FORMULA), conditioned bag search (class CX_CONDITIONED_BAG), when calling plug and during macro substitution in strings.

Each PlugSpace call resets 'PlugSpace' - the functions do not work together. In other words: a new 'PlugSpace' replaces the old one. To make objects overlay (see picture below), the objects need to be collected in a vector first. After, this vector gets put into the stack for PlugSpace. All vector objects will be in the 'PlugSpace'. The object that has been added last to the vector will be at the very top of the 'PlugSpace'. When evaluating, it will be seen first.  See Example.

A practical example for PlugSpace use is the data field calculation in orders and order items.
The order has a group item, which in turn contains an order item.

The order date is "01.09.2008", whereas the group contains a different date (07.08.2008), since this group is supposed to be delivered before the entire order. The item has no extra delivery date.

The delivery date is saved as "delivered.spanDate" in all objects.

When calculating the item delivery date, a vector gets created via item structure and put into the PlugSpace. The command Plug(delivered.spanDate) will be called. It provides the "bottom" delivery date. In this case it is the group delivery date (07.08.2008). In the top position (highest priority), the vector contains the order item, then the order group and at last the actual order. The command Plug (delivered.spanDate) checks, whether the highest object contains the searched data field "delivered.spanDate". If this is not the case, the next-highest object gets searched. If this object does not include the searched data field either, the search continues, until all PlugSpace objects have been checked. Not only the command "plug" uses the PlugSpace, but also calculations, such as "Evaluate" or booking rules, such as "transaction description" and "business operations".

PlugSpace vector priority can be controlled as follows: the object, which has been included in the vector last, has the highest priority. Now getting the order item, after its higher-level group and the order at last - the order would be just the wrong way around. Now, the vector needs to be reversed via "revert":

Example:

 

Var(plugSpaceVector)

// Collect plug space vector

[] -> plugSpaceVector

orderItem

do

  Dup plugSpaceVector Insert

  Get(transaction) Dup ifnot { Drop break }

loop

// Turn around vector priority (Revert) and set PlugSpace

plugSpaceVector Revert PlugSpace

// Check value

Plug(delivered.spanDate)

// Result   = Delivery date in priority of "from bottom to the top"

 

A more simple Example:

 

Var(plugSpaceVector, txn1, txn2, txn3)

// Set variables

CreateTransObject(CX_TRANSACTION) -> txn1

CreateTransObject(CX_TRANSACTION) -> txn2

CreateTransObject(CX_TRANSACTION) -> txn3

 

"Priorität 1" txn1 Put(comment)

"Priorität 2" txn2 Put(comment)

"Priorität 3" txn3 Put(comment)

 

// Initialize plug space vector

[] -> plugSpaceVector

// Collect objects for the plug space: The object with the highest priority at last

txn3 plugSpaceVector Insert

txn2 plugSpaceVector Insert

txn1 plugSpaceVector Insert
 

// Set plug space

plugSpaceVector PlugSpace

// Check value

Plug(comment)

// Result   = "Priorität 1"

 

 

// ############ Now we turn around the priority through the vector and check again ##############

 

// Set plug space

plugSpaceVector Revert PlugSpace

// Check value

Plug(comment)

// Result   = "Priorität 3"

 

// ## Now we will delete the searched slot "comment" from object 3 and try again ##

txn3 DeleteSlot(comment)

// Check value again: The plug space doesn't need to be set again, because it only keeps references to the contained objects. Changes of the objects have influence of the plug space, too.

Plug(comment)

// Result   = "Priorität 2"

 
Technical description:
 

Example 1:
                   

1.a) Register objects A and B as:

[ B A ] PlugSpace

Stack
Stack Position Description
stack  top   ]
 
top - 1
 A 
   top - 2   B
   top - 3   [

1.b) The following picture shows the object cast in PlugSpace when evaluating a formula:

Var(f) CreateTransObject (CX_FORMULA) -> f
" if (c < Date(\"today\")) b + 5 else a / 2 m * 3 " f  Put
f Call (Evaluate)

 

Example 2:

2.a) Register objects A, B and C as PlugSpace:

[ C B A ] PlugSpace

Stack
Stack Positions Description
stack  top   ]
 
top - 1
 A 
   top - 2   B
   top - 3  C
   top - 4   [

2.b) The following picture shows the object cast in PlugSpace when evaluating a formula:

Var(f) CreateTransObject (CX_FORMULA) -> f
" if ( ptr.name != “ABC” & e = links) 25 + sin( X * pi ) else ::Foo( X, Y ) " f  Put
f Call (Evaluate)

 

 

  The PlugSpace allocation remains the same until 

Moreover, CyberEnterprise® object functions can modify the PlugSpace.

Seach in PlugSpace, search order:

Related topics: