0 Views
0 Downloads
0 Favorites
ObjectList
ÿþ/**/

#include <SRC\Service\ObjectList.mqh> //your path

class A {};

class B:public A {};

/****************************************************************

Example of ObjectList usage

/****************************************************************/

void OnStart()

  {

   ObjectList<A>list;

   A* o1=new B();             //dynamic

   A  o2;                     //automatic

   A* o3=&o2;                 //automatic

   /**/

   list+=&o2;                 //append object ref

   list^=o1;                  //prepend

   list+=o3;                  //append pointer

   list.PrintHash();          //see output

   /**/

     {string s; for(int i=0; i<13; i++) {s+="-";} Print(s);}

   /**/

   list-=&o2;                 //remove

   ObjectList<A>list2=list;   //copy list

   list2.PrintHash();         //see output

   /**/

     {string s; for(int i=0; i<13; i++) {s+="-";} Print(s);}

   /**/

   ~list;                     //clean list, this is empty now

   list2.RemoveLast();        //remove

   list2.PrintHash();         //see output

   /**/

     {string s; for(int i=0; i<13; i++) {s+="-";} Print(s);}

   /**/

   A* o=list2[0];                                        //direct access

   Print(list2.Hash(o));   //2097152     //   same...    //risky to use o without check, but if you sure

   Print(list2.Hash(0));   //2097152     //...object

   Print(list2.TryGet(o,666)); //false, don't use o      //safe access

   /**

   ...On destruction the list will delete the dynamic object o1 from memory.

   /**/

  }

/****************************************************************

Output:

/**

   0:2097152(A*)

   1:3145728(A*)

   2:3145728(A*)

   -------------

   0:2097152(A*)

   1:3145728(A*)

   -------------

   0:2097152(A*)

   -------------

   2097152

   2097152

   false

/**/

Comments