Flip Reference

Vector Class Reference

Inherits from

Blob

Declared in

flip/Vector.h

template <class T> class Vector;

flip::Vector is an container of non flip Objects that are continguous in memory.

It is used to store a massive number of objects in a performant way, but is not inherently concurrent like Array or Collection, because the whole content of the vector is resent every time there is a change to it, instead of just changing one element.

This means that if two users are changing a property of an element in the vector, and if this operation is done concurrently, only one of the user will see his change applied, and the other user will have it rollbacked.

The more there is latency on the network, the more this concurrency problem shows. On the local aera network however, this problem would most likely rarely shows.

The Vector itself provides support for modification introspection. When modifying the content of the Vector, the previous representation of the vector is still present. However individual elements are not tracked.

Template Parameters

T

The type of the elements. T shall not inherit from flip::Object

Member Types

value_type

T

reference

T &

const_reference

const T &

pointer

T *

const_pointer

const T *

const_iterator

Constant random access iterator

Member Functions Synopsys

Constructor

Constructs the Vector

Destructor

Destructs the Vector

operator =

Assigns values to the container

Document Management

document

Returns the document to which the object is attached to

ref

Returns the unique reference number of the object

added

Returns true iff the object was just attached to the document tree

removed

Returns true iff the object was just detached from the document tree

resident

Returns true iff the object was neither attached nor detached from the document tree

changed

Returns true iff the object or one of its children was modified

ancestor

Returns a reference to a parent in the current parent chain of the object

disable_in_undo

Disables the record state modification in history

inherit_in_undo

Inherits the record state modification in history

is_in_undo_enabled

Returns true iff this object modifications are recorded in history

revert

Reverts all the changes made to the object and its children if any

assign

Replaces the content of the object with the content of the provided object

Iterators

begin cbegin

Returns an iterator to the beginning

end cend

Returns an iterator to the end

Modifiers

clear

Clears the contents

replace

Replace a specified portion of the container

Member Functions

Constructor

Vector ();                                (1)
Vector (const Vector & other);            (2)
Vector (Vector && other);                 (3)
Vector (const std::vector <T> & value);   (4)
  1. Default constructor, constructs an empty container.
  2. Copy constructor. Constructs the container with a copy of elements of other.
  3. Move constructor. Constructs the container by moving the elements of other.
  4. Constructor. Constructs the container with a copy of elements of value.

Destructor

~Vector ();

Destructor.


operator =

Vector & operator = (const Vector & other); (1)
Vector & operator = (Vector && other); (2)
Vector & operator = (const std::vector <T> & other); (3)
Vector & operator = (std::vector <T> && other); (4)

Copy assignment operator.

  1. Copy assignment operator.
  2. Move assignment operator.
  3. Assignment operator by copying the elements of other.
  4. Assignment operator by moving the elements of other.

document

DocumentBase & document () const;

Returns the document to which the object is attached to.

WARNING: Temporary flip objects are not attached to a document


ref

const Ref & ref () const;

Returns the unique reference number of the object.


added

bool  added () const;

Returns true iff the object was just attached to the document tree.

Example :

void  Observer::document_changed (Note & note)
{
   if (note.added ())
   {
      // A note was added to the document. Create the corresponding
      // view element
      note.entity ().emplace <NoteView> ();
   }
   [...]
}

removed

bool  removed () const;

Returns true iff the object was just detached from the document tree.

Example :

void  Observer::document_changed (Note & note)
{
   [...]
   if (note.removed ())
   {
      // A note was removed from the document. Release the corresponding
      // view element
      note.entity ().erase <NoteView> ();
   }
}

resident

bool  resident () const;

Returns true iff the object was neither attached nor detached from the document tree.

An object can be resident but moved. In this case the iterator pointing to it will allow to detect the move.

Example :

void  Observer::document_changed (Array <Track> & tracks)
{
   auto it = tracks.begin ();
   auto it_end = tracks.end ();
   for (; it != it_end ; ++it)
   {
      Track & track = *it;
      if (it.added () && track.resident ())
      {
         // the track was moved in the container
         // this is the destination position
      }
      if (it.added () && track.resident ())
      {
         // the track was moved in the container
         // this is the source position
      }
   }
}

changed

bool  changed () const;

Returns true iff the object or one of its children was modified.

Example :

void  Observer::document_changed (Note & note)
{
   auto & view = note.entity ().use <ViewNote> ();
   if (note.changed ())
   {
      // one or more properties of the note changed
      if (note.position.changed ())
      {
         view.set_position (note.position);
      }
      if (note.duration.changed ())
      {
         view.set_duration (note.duration);
      }
   }
}

ancestor

template <class T>   T &   ancestor ();
template <class T>   const T &   ancestor () const;

Returns a reference to a parent in the current parent chain of the object.

Note: If an object or its parent is moved from one container to another, this function will always return the current parent, that is not the previous one


disable_in_undo

void   disable_in_undo ();

Disables the record state modification in history of the object and its subtree if any.

Example :

void  add_user (Root & root)
{
   // emplace a new User of the document to store
   // user specific data. User is constructed with
   // the unique user id number given at document
   // creation
   User & user = root.users.emplace <User> (root.document ().user ());
   // we don't want the scroll position in the document
   // to be part of undo
   user.scroll_position.disable_in_undo ();
}

inherit_in_undo

void   inherit_in_undo ();

Inherits the record state modification in history of the object and its subtree if any, from its parent state. This is the default mode.

Note: If the Root object of the tree is in inherited mode, then it is considered as enabled in undo.


is_in_undo_enabled

bool  is_in_undo_enabled () const;

Returns true iff this object modifications are recorded in history. The function recursively search for disabled state starting from the object itself and navigating through the parent objects, if the state is inherited.


revert

void  revert () const;

Reverts all the changes make to the object and its children if any.

Example :

// initially, note.position == 1
note.position = 2;
note.revert ();
// now, note.position == 1

assign

void  assign (const Type & rhs);

Replaces the content of the object with the content of the provided object. Both objects need to be bound to a document for the function to succeed.

Example :

// initially :
// note.position == 1
// note.duration == 3
// note2.position == 2
// note2.duration == 1
note.assign (note2);
// now :
// note.position == 2
// note.duration == 1

begin cbegin

Returns an iterator to the beginning.


end cend

Returns an iterator to the end.


clear

void  clear ();

Removes all the elements from the container.


replace

void  replace (const_iterator it, const_iterator it_end, const std::vector <T> & value); (1)
template <class InputIterator>
void  replace (const_iterator it, const_iterator it_end, InputIterator it2, InputIterator it_end2); (2)

Replaces the part of the container indicated by [it, it_end) with new elements.