Mold Class Reference
Declared in |
|
class Mold; |
flip::Mold
is a convencience type to make copies of flip objects. It is typically used in implementations of user interface copy/paste feature or making clones of an object.
The Mold
itself is used in two ways :
- Making the mold by making an imprint of flip objects and get opaque data out of it
- Casting the mold by giving the previous opaque data and produce flip objects
The casting part is typically done using the emplace
overload for mold in the flip containers.
Member Functions Synopsys
Construct the | |
Add an object to the current mold | |
Cure the mold | |
Casts the mold |
Member Functions
Constructor
Mold (const DataModelBase & model); (1) |
Mold (const DataModelBase & model, StreamBinOut & sbo); (2) |
Mold (const DataModelBase & model, StreamBinIn & sbi); (3) |
Mold (Mold && other); (4) |
- Constructs the
Mold
for making and casting without serialization - Constructs the
Mold
for making, by attaching it to a binary stream for writing - Constructs the
Mold
for casting, by attaching it to a binary stream for reading - Constructs the
Mold
by moving fromother
Mold
For all constructors, the data model from which the mold is made or casted must be passed, to allow automatic flip object (not attached to a document) to be made or casted.
make
template <class T> void make (const T & obj, bool skip_container_flag = false); |
Add a flip object obj
of type T
to the current mold. If skip_container_flag
is true
, the mold will not contain the content of any flip container in the object sub-model tree.
Important: This function can only be used in version (1) or (2) of the constructor.
Example :
class Note : public Object |
{ |
public: |
Float position; |
Float duration; |
}; |
class Clip : public Object |
{ |
public: |
Float position; |
Collection <Note> notes; |
}; |
class Track : public Object |
{ |
public: |
String name; |
Array <Clip> clips; |
}; |
std::vector <uint8_t> data; |
StreamBinOut sbo (data); |
// we can use the StreamBinOut not only for molds |
// here, remember track unique reference identifier |
sbo << track.ref (); |
Mold mold (Model::use (), sbo); |
mold.make (clip); // copies clip position and all notes properties |
mold.make (clip.ancestor <Track> (), true); // only track.name |
mold.cure (); |
// now 'data' is filled with a serialisation of the molded objects |
cure
void cure (); |
Cure the mold. This flushes all necessary data to the binary stream so that the mold is ready for casting.
Important: This function can only be used in the version (2) of the constructor.
cast
template <class T> T cast () const; (1) |
template <class T> void cast (T & obj) const; (2) |
- Cast the mold which element matches type
T
and return it - Cast the mold which element matches type
T
in the passed object parameter
Important: Those functions can only be used in the version (1) or (3) of the constructor.
Example :
std::vector <uint8_t> data = ...; // from previous serialisation |
StreamBinIn sbi (data); |
// we can multiple molds in a StreamBinIn so run until we reach |
// the end of stream |
while (!sbi.is_eos ()) |
{ |
// we used the StreamBinOut not only for mold (see above) |
Ref track_ref; |
sbi >> track_ref; |
Mold mold (Model::use (), sbi); |
// sbi stream is advanced by the mold size, and filled with deserialized data |
// make a clip copy and put it in to the track clips |
track.clips.emplace (mold); |
} |