Copying Objects

Since Storm needs to create copies of object graphs whenever messages are sent between threads, the standard library contains mechanisms to achieve this. The functionality is implemented through the function clone and the type CloneEnv.

The public interface to the object copying facilities is the clone function:

The clone interface is implemented through the following facilities:

Furthermore, the clone system expects that all value and class types have the following members:

To illustrate how the system works, consider the following classes in Basic Storm, with the accompanying implementation of copy constructors and deepCopy functions:

class MyClass {
    Nested nested;
    Value value;

    // Copy constructor:
    init(MyClass original) {
        init {
            nested = original.nested;
            data = original.data;
        }
    }

    // DeepCopy:
    void deepCopy(CloneEnv env) : override {
        nested = nested.clone(env);
        value.deepCopy(env);
    }
}

class Nested {
    Int x;

    init(Nested original) {
        init { x = original.x; }
    }
}

value Value {
    Int x;

    init(Value original) {
        init { x = original.x; }
    }
}

This allows MyClass to be copied by calling clone(MyClass()).

The system provides default implementations of both copy constructors and deepCopy as the types core.lang.TypeCopyCtor and core.lang.TypeDeepCopy.