Top | ![]() |
![]() |
![]() |
![]() |
InfAdoptedOperationInfAdoptedOperation — Operation that can be processed by InfAdoptedAlgorithm. |
GEnum ╰── InfAdoptedConcurrencyId GFlags ╰── InfAdoptedOperationFlags GInterface ╰── InfAdoptedOperation
InfAdoptedOperation is implemented by InfAdoptedNoOperation and InfAdoptedSplitOperation.
The InfAdoptedOperation interface must be implemented by operations that are supposed to be used by InfAdoptedAlgorithm. They basically need to define transformation rules for transformation against other operations.
gboolean inf_adopted_operation_need_concurrency_id (InfAdoptedOperation *operation
,InfAdoptedOperation *against
);
This function returns whether transforming operation
against against
is not defined unambiguously. In that case, transformation requires a
so-called concurrency ID which determines which of the two operations
is transformed.
operation |
The InfAdoptedOperation to transform. |
|
against |
The operation to transform against. |
InfAdoptedOperation * inf_adopted_operation_transform (InfAdoptedOperation *operation
,InfAdoptedOperation *against
,InfAdoptedOperation *operation_lcs
,InfAdoptedOperation *against_lcs
,gint concurrency_id
);
Performs an inclusion transformation of operation
against against
,
meaning that the effect of against
is included in operation
.
If inf_adopted_operation_need_concurrency_id()
returns TRUE
for operation
and against
, then operation_lcs
and against_lcs
must not be NULL
. In
this case they must be the same operations as operation
and against
at
the earlierst state to which both of them can be transformed. This
information can then be used to resolve any conflicts in the transformation
of operation
against against
.
The concurrency_id
parameter is used if
inf_adopted_operation_need_concurrency_id()
returns TRUE
and no conflict
resolution can be deduced from operation_lcs
and against_lcs
. In this
case concurrency_id
defines a unique way to transform the two operations.
Usually, this is derived from the user IDs of the users who issued the two
conflicting operations.
operation |
The InfAdoptedOperation to transform. |
|
against |
The operation to transform against. |
|
operation_lcs |
The operation at a previous state, or |
|
against_lcs |
The |
|
concurrency_id |
The concurrency ID for the transformation. |
The transformed
InfAdoptedOperation, or NULL
if the transformation failed.
[transfer full][allow-none]
InfAdoptedOperation *
inf_adopted_operation_copy (InfAdoptedOperation *operation
);
Returns a copy of operation
.
InfAdoptedOperationFlags
inf_adopted_operation_get_flags (InfAdoptedOperation *operation
);
Returns the flags for operation
.
gboolean inf_adopted_operation_apply (InfAdoptedOperation *operation
,InfAdoptedUser *by
,InfBuffer *buffer
,GError **error
);
Applies operation
to buffer
. The operation is considered to be applied by
user by
. If the operation cannot be applied then error
is set and the
function returns FALSE
.
operation |
||
by |
||
buffer |
The InfBuffer to apply the operation to. |
|
error |
Location to store error information, if any, or |
InfAdoptedOperation * inf_adopted_operation_apply_transformed (InfAdoptedOperation *operation
,InfAdoptedOperation *transformed
,InfAdoptedUser *by
,InfBuffer *buffer
,GError **error
);
Applies transformed
to buffer
. The operation is considered to be applied
by user by
. The operation transformed
must have originated from
operation
by transformation with inf_adopted_operation_transform()
.
If operation
is reversible or does not affect the buffer (see
InfAdoptedOperationFlags), this function is equivalent to
inf_adopted_operation_apply(transformed, by, buffer)
, with
the exception of the return value. In that case the return value will be
operation
itself, with a reference added.
However, if operation
is not reversible and affects the buffer, the
function attempts to construct an operation which is identical to
operation
, but reversible, and returns it. The function can use
information from the transformed operation and the buffer to construct
the reversible operation. If a reversible operation cannot be constructed,
the function returns an additional reference on operation
, and still
applies the transformed operation
to the buffer.
For example, an operation that deletes text in a text editor would be transmitting only the position and the length of the text to delete over the network. From that information alone, the operation cannot be made reversible. However, when the operation is applied to the buffer, the actual text that is being removed can be restored by looking it up in the buffer, making the operation reversible.
operation |
||
transformed |
A transformed version of |
|
by |
The InfAdoptedUser applying the operation. |
|
buffer |
The InfBuffer to apply the operation to. |
|
error |
Location to store error information, if any, or |
A InfAdoptedOperation, or NULL
on error.
Free with g_object_unref()
when no longer needed.
[transfer full]
gboolean
inf_adopted_operation_is_reversible (InfAdoptedOperation *operation
);
Returns whether operation
is reversible.
InfAdoptedOperation *
inf_adopted_operation_revert (InfAdoptedOperation *operation
);
Returns a new InfAdoptedOperation that undoes the effect of operation
. If
operation
and then its reverse operation are applied to a buffer (in that
order), the buffer remains unchanged.
operation
must be reversible for this function to be called (i.e.
inf_adopted_operation_is_reversible()
must return TRUE).
typedef struct _InfAdoptedOperation InfAdoptedOperation;
InfAdoptedOperation is an opaque data type. You should only access it via the public API functions.
struct InfAdoptedOperationInterface { gboolean (*need_concurrency_id)(InfAdoptedOperation* operation, InfAdoptedOperation* against); InfAdoptedOperation* (*transform)(InfAdoptedOperation* operation, InfAdoptedOperation* against, InfAdoptedOperation* operation_lcs, InfAdoptedOperation* against_lcs, InfAdoptedConcurrencyId concurrency_id); InfAdoptedOperation* (*copy)(InfAdoptedOperation* operation); InfAdoptedOperationFlags (*get_flags)(InfAdoptedOperation* operation); gboolean (*apply)(InfAdoptedOperation* operation, InfAdoptedUser* by, InfBuffer* buffer, GError** error); InfAdoptedOperation* (*apply_transformed)(InfAdoptedOperation* operation, InfAdoptedOperation* transformed, InfAdoptedUser* by, InfBuffer* buffer, GError** error); InfAdoptedOperation* (*revert)(InfAdoptedOperation* operation); };
The virtual methods that need to be implemented by an operation to be used with InfAdoptedAlgorithm.
Virtual function to determine whether a concurrency
ID is required to transform |
||
Virtual function that transform |
||
Virtual function that returns a copy of the operation. |
||
Virtual function that returns the flags of the operation, see InfAdoptedOperationFlags. |
||
Virtual function that applies the operation to the buffer. |
||
Virtual function that applies a transformed version of the operation to the buffer. It attempts to use information from the buffer to make the original operation reversible, if it is not already. The implementation of this function is optional, and only needs to be implemented if the operation is not reversible but can be made reversible with additional information from the buffer or the transformed operation. |
||
Virtual function that creates a new operation that undoes the
effect of the operation. If |
Various flags for InfAdoptedOperation.
The operation changes the content of the buffer. |
||
The operation is reversible, which means
that |