» collections
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

collections

acl(devvvv vvvvgroup)

.net 4.0 collections

.net 4.0 Collections Overview

VVVV.Core.Collections

This namespace contains vvvvs own set of collections which where mainly created to overcome two limitations of the available .net collections:

Therefore VVVV.Core.Collections contains:

  • EditableCollection<T>
    • EditableList<T>
      • SortedEditableList<T>
      • EditableIDList<T>
  • ViewableCollection<T>
    • ViewableList<T>
      • SortedViewableList<T>
      • ViewableIDList<T>

where the term Viewable means that you cannot add or remove items to and from those collections. Se we have:

  • Collections
  • Lists (ordered collections, can be sorted manually)
  • SortedLists (always sorted lists)
  • IDLists (entries are IIDItems, think of an IDList as a namespace in which all elements have different names)

The main purposes of our set of collections is to

  • ease object graph modeling
  • support both viewable-only & editable collections
  • ease external syncronization with & modification of that model.

Create an EditableCollection

public class MyModel
    {
        public IEditableCollection<int> Numbers
        {
            get;
            private set;
        }
 
        Numbers = new EditableCollection<int>();
    }

A model that wants to expose a collection typically uses a property that can only be accessed, not written (get; private set) and the collection is created in the constructor. Typically it is sufficient to expose the interface to the collection.
The central idea now is that your model can be changed through its exposed collection property. So you would NOT need to introduce some custom AddNumber() / RemoveNumber() methods to your model. Users just directly work with the editable collection. That's the way to go.
In other words the collection should be perceived as a first class citizen within your model. That way the use of such a model is straight forward. When you want to change a collection of a model, you do just that. As a result, adding and removing objects from collections can also be done with standardized commands, which is a plus.
Now, if you need to react to a changing collection within your model, you can subscribe to the events of the collection (sometimes even that can be omitted like seen in the syncer example on the bottom of the page).

Our collections make it easy to decide which collections might be edited or only viewed from outside. All flavours of collections come as either editable or viewable (can't be edited). Here is how to use a viewable collection:

Create a ViewableCollection

public IViewableCollection<int> Results
        {
            get;
            private set;
        }
 
        FResults = new EditableCollection<int>();
        Results = FResults.AsViewableCollection();

Above you see how to build up a list, that can be edited within the model object, but only be viewed from outside.

Syncing

One Collection can stay in sync with another collection, even if it manages another type of elements. A syncer will react on each event of the first collection and change the second collection accordingly.

You only need to specify a mapping that creates an element in the second list based on an element of the first.

public IEditableList<int> Numbers
        {
            get;
            private set;
        }
 
        private EditableList<int> FResults;
        public IViewableList<int> Results
        {
            get;
            private set;
        }
 
        public void TestMethod1()
        {
            Numbers = new EditableList<int>();
 
            FResults = new EditableList<int>();
            using (FResults.SyncWith(Numbers, x => x * x))
            {
                Results = FResults.AsViewableList();
 
                // when doing more than one change: 
                // use beginupdate/endupdate to reduce syncing events
                Numbers.BeginUpdate();
                try
                {
                    Numbers.Add(4);
                    Numbers.Add(7);
                }
                finally
                {
                    Numbers.EndUpdate();
                }
 
                // Magically results (x*x) are already added to the Results list
                foreach (var r in Results)
                    Debug.WriteLine(r);
 
                // You can't add a result to the public Results list
                // Results.Add(17);
 
                // again: change source collection:
                Numbers.Add(8);
 
                // synced results collection is already updated.
                foreach (var r in Results)
                    Debug.WriteLine(r);
            }
        }

Above you can see how a syncer can be used to model a collection depending on another collection.

Note that the standard case to use syncing however is to sync a collection of views onto you model objects.

For that just create a private editable collection and sync it with the model collection by passing a delegate that creates a view object for your model object. If you still need to do more than just creating and disposing your view think of reacting on syncer events or events of your own synced list...

anonymous user login

Shoutbox

~2d ago

joreg: 6 session beginner course part 2 "Deep Dive" starts January 13th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-ii/

~2d ago

joreg: 6 session beginner course part 1 "Playground" starts November 4th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-i/

~2d ago

joreg: Save the date: Oktober 17: vvvv meetup in Berlin!

~4d ago

joreg: 12 session online vvvv beginner course postponed to start November 4th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-class/

~15d ago

~24d ago

joreg: Webinar on October 2nd: Rhino meets Realtime with vvvv https://visualprogramming.net/blog/2024/webinar-rhino-meets-realtime-with-vvvv/

~29d ago

joreg: Introducing: Support for latest Ultraleap hand-tracking devices: https://visualprogramming.net/blog/2024/introducing-support-for-new-ultraleap-devices/

~1mth ago

joreg: 2 day vvvv/fuse workshop in Vienna as part of NOISE festival on Sept. 13 and 14: https://www.noise.ist/vienna

~1mth ago

joreg: New beginner video tutorial: World Cities https://youtu.be/ymzrK7tZLBI

~1mth ago

catweasel: https://colour-burst.com/2023/01/26/macroscopic/ yeah, ' is there anyone who cares about slides anymore...' Well me for a start! :D