Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 817


Ignore:
Timestamp:
Feb 16, 2008, 7:31:18 PM (17 years ago)
Author:
landauf
Message:

big update:

  • reimplemented direct-child and direct-parent list and several related functions (get-iterator, get-list)
  • reimplemented isDirectChildOf- and isDirectParentOf-functions in Identifier, SubclassIdentifier and OrxonoxClass
  • renamed isDirectlyA to isExactlyA in Identifier, SubclassIdentifier and OrxonoxClass
  • ClassTreeMask works now with interfaces and has more possibilities (parameters for overwriting of previous rules and cleaning after adding a new function)
  • ObjectList's begin() and end() functions use ClassManager to avoid problems with libraries
  • the Factory got functions to return begin() and end() iterator for the identifier-map
  • overloaded << operator to put identifier-lists on the stream
Location:
code/branches/core/src/orxonox
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/Orxonox.cc

    r811 r817  
    7878#include "core/ClassTreeMask.h"
    7979#include "objects/WorldEntity.h"
     80#include "core/DebugLevel.h"
    8081#include "core/BaseObject.h"
    8182#include "objects/Test.h"
     
    231232      break;
    232233    }
    233 
    234234        #define testandcout(code) \
    235235          std::cout << #code << " " << code << "\n"
    236 
    237236/*
    238237        std::cout << "Test 1\n";
     
    259258        test4 = new A3();
    260259        test4 = new A3();
    261 */
    262 /*
     260
     261
    263262        std::cout << "Test 5\n";
    264263        A1* test5_01 = new A1();
     
    280279        A3B2C1* test5_17 = new A3B2C1();
    281280        A3B2C2* test5_18 = new A3B2C2();
    282 
    283         OrxonoxClass* test5;
     281*/
     282/*
     283        OrxonoxClass* test5 = 0;
    284284        for (int i = 0; i <= 18; i++)
    285285        {
     
    305305
    306306          std::cout << "\n";
    307           std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): parents:     " << test5->getIdentifier()->getParents().toString() << "\n";
    308           std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): children:    " << test5->getIdentifier()->getChildren().toString() << "\n";
     307          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): parents:         " << test5->getIdentifier()->getParents() << "\n";
     308          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): children:        " << test5->getIdentifier()->getChildren() << "\n";
     309          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): direct parents:  " << test5->getIdentifier()->getDirectParents() << "\n";
     310          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): direct children: " << test5->getIdentifier()->getDirectChildren() << "\n";
    309311        }
    310 
    311         std::cout << "Class with ID 0: " << ID(0) << " " << ID(0)->getName() << "\n";
    312         std::cout << "Class with ID 1: " << ID(1) << " " << ID(1)->getName() << "\n";
    313         std::cout << "Class with ID 2: " << ID(2) << " " << ID(2)->getName() << "\n";
    314         std::cout << "Class with ID 3: " << ID(3) << " " << ID(3)->getName() << "\n";
    315         std::cout << "Class with ID 4: " << ID(4) << " " << ID(4)->getName() << "\n";
     312*/
     313/*
     314        for (std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryBegin(); it != Factory::getFactoryEnd(); ++it)
     315            std::cout << "Class with ID " << (*it).second->getNetworkID() << ": " << ID((*it).second->getNetworkID()) << " / " << ID((*it).second->getNetworkID())->getName() << std::endl;
     316
    316317        std::cout << "Class with ID 100: " << ID(100) << "\n";
    317318        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
     
    360361        std::cout << "isDirectA(XYZ)-Test:\n";
    361362        std::cout << "test5_01 = A1, Erwartet: 1 0 0 0 0\n";
    362         testandcout(test5_01->isDirectlyA(Class(A1)));
    363         testandcout(test5_01->isDirectlyA(Class(A2)));
    364         testandcout(test5_01->isDirectlyA(Class(A1B1)));
    365         testandcout(test5_01->isDirectlyA(Class(BaseObject)));
    366         testandcout(test5_01->isDirectlyA(Class(Interface1)));
     363        testandcout(test5_01->isExactlyA(Class(A1)));
     364        testandcout(test5_01->isExactlyA(Class(A2)));
     365        testandcout(test5_01->isExactlyA(Class(A1B1)));
     366        testandcout(test5_01->isExactlyA(Class(BaseObject)));
     367        testandcout(test5_01->isExactlyA(Class(Interface1)));
    367368
    368369        std::cout << "\n";
    369370        std::cout << "test5_02 = A2, Erwartet: 0 1 0 0 0\n";
    370         testandcout(test5_02->isDirectlyA(Class(A1)));
    371         testandcout(test5_02->isDirectlyA(Class(A2)));
    372         testandcout(test5_02->isDirectlyA(Class(A1B1)));
    373         testandcout(test5_02->isDirectlyA(Class(BaseObject)));
    374         testandcout(test5_02->isDirectlyA(Class(Interface1)));
     371        testandcout(test5_02->isExactlyA(Class(A1)));
     372        testandcout(test5_02->isExactlyA(Class(A2)));
     373        testandcout(test5_02->isExactlyA(Class(A1B1)));
     374        testandcout(test5_02->isExactlyA(Class(BaseObject)));
     375        testandcout(test5_02->isExactlyA(Class(Interface1)));
    375376
    376377        std::cout << "\n";
    377378        std::cout << "test5_03 = A3, Erwartet: 0 0 0 0 0\n";
    378         testandcout(test5_03->isDirectlyA(Class(A1)));
    379         testandcout(test5_03->isDirectlyA(Class(A2)));
    380         testandcout(test5_03->isDirectlyA(Class(A1B1)));
    381         testandcout(test5_03->isDirectlyA(Class(BaseObject)));
    382         testandcout(test5_03->isDirectlyA(Class(Interface1)));
     379        testandcout(test5_03->isExactlyA(Class(A1)));
     380        testandcout(test5_03->isExactlyA(Class(A2)));
     381        testandcout(test5_03->isExactlyA(Class(A1B1)));
     382        testandcout(test5_03->isExactlyA(Class(BaseObject)));
     383        testandcout(test5_03->isExactlyA(Class(Interface1)));
    383384
    384385        std::cout << "\n";
     
    431432
    432433        std::cout << "\n";
     434        std::cout << "isDirectChildOf(XYZ)-Test:\n";
     435        std::cout << "test5_04 = A1B1, Erwartet: 1 0 0 0 0 0 0\n";
     436        testandcout(test5_04->isDirectChildOf(Class(A1)));
     437        testandcout(test5_04->isDirectChildOf(Class(A2)));
     438        testandcout(test5_04->isDirectChildOf(Class(BaseObject)));
     439        testandcout(test5_04->isDirectChildOf(Class(Interface1)));
     440        testandcout(test5_04->isDirectChildOf(Class(Interface2)));
     441        testandcout(test5_04->isDirectChildOf(Class(A1B1C2)));
     442        testandcout(test5_04->isDirectChildOf(Class(A1B1)));
     443
     444        std::cout << "\n";
     445        std::cout << "test5_06 = A2B1, Erwartet: 0 1 0 0 0 0 0\n";
     446        testandcout(test5_06->isDirectChildOf(Class(A1)));
     447        testandcout(test5_06->isDirectChildOf(Class(A2)));
     448        testandcout(test5_06->isDirectChildOf(Class(BaseObject)));
     449        testandcout(test5_06->isDirectChildOf(Class(Interface1)));
     450        testandcout(test5_06->isDirectChildOf(Class(Interface2)));
     451        testandcout(test5_06->isDirectChildOf(Class(A1B1C2)));
     452        testandcout(test5_06->isDirectChildOf(Class(A1B1)));
     453
     454        std::cout << "\n";
     455        std::cout << "test5_07 = A2B2, Erwartet: 0 1 0 1 0 0\n";
     456        testandcout(test5_07->isDirectChildOf(Class(A1)));
     457        testandcout(test5_07->isDirectChildOf(Class(A2)));
     458        testandcout(test5_07->isDirectChildOf(Class(BaseObject)));
     459        testandcout(test5_07->isDirectChildOf(Class(Interface1)));
     460        testandcout(test5_07->isDirectChildOf(Class(Interface2)));
     461        testandcout(test5_07->isDirectChildOf(Class(A1B1C2)));
     462
     463        std::cout << "\n";
     464        std::cout << "test5_08 = A3B1, Erwartet: 0 0 0 0 0 0\n";
     465        testandcout(test5_08->isDirectChildOf(Class(A1)));
     466        testandcout(test5_08->isDirectChildOf(Class(A2)));
     467        testandcout(test5_08->isDirectChildOf(Class(BaseObject)));
     468        testandcout(test5_08->isDirectChildOf(Class(Interface1)));
     469        testandcout(test5_08->isDirectChildOf(Class(Interface2)));
     470        testandcout(test5_08->isDirectChildOf(Class(A1B1C2)));
     471
     472        std::cout << "\n";
     473        std::cout << "test5_09 = A3B2, Erwartet: 0 0 0 0 1 0\n";
     474        testandcout(test5_09->isDirectChildOf(Class(A1)));
     475        testandcout(test5_09->isDirectChildOf(Class(A2)));
     476        testandcout(test5_09->isDirectChildOf(Class(BaseObject)));
     477        testandcout(test5_09->isDirectChildOf(Class(Interface1)));
     478        testandcout(test5_09->isDirectChildOf(Class(Interface2)));
     479        testandcout(test5_09->isDirectChildOf(Class(A1B1C2)));
     480
     481        std::cout << "\n";
     482
    433483        std::cout << "isParentOf(XYZ)-Test:\n";
    434484        std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 1 1 1\n";
     
    460510        testandcout(Class(Interface1)->isParentOf(Class(A2B2)));
    461511        testandcout(Class(Interface1)->isParentOf(Class(A3B1C2)));
     512
     513        std::cout << "\n";
     514        std::cout << "isDirectParentOf(XYZ)-Test:\n";
     515        std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 0 0 0\n";
     516        testandcout(test1->isDirectParentOf(Class(BaseObject)));
     517        testandcout(test1->isDirectParentOf(Class(Interface1)));
     518        testandcout(test1->isDirectParentOf(Class(A1)));
     519        testandcout(test1->isDirectParentOf(Class(A2)));
     520        testandcout(test1->isDirectParentOf(Class(A1B1)));
     521        testandcout(test1->isDirectParentOf(Class(A2B2)));
     522        testandcout(test1->isDirectParentOf(Class(A3B1C2)));
     523
     524        std::cout << "\n";
     525        std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n";
     526        testandcout(test5_01->isDirectParentOf(Class(BaseObject)));
     527        testandcout(test5_01->isDirectParentOf(Class(Interface1)));
     528        testandcout(test5_01->isDirectParentOf(Class(A1)));
     529        testandcout(test5_01->isDirectParentOf(Class(A2)));
     530        testandcout(test5_01->isDirectParentOf(Class(A1B1)));
     531        testandcout(test5_01->isDirectParentOf(Class(A2B2)));
     532        testandcout(test5_01->isDirectParentOf(Class(A3B1C2)));
     533
     534        std::cout << "\n";
     535        std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 0\n";
     536        testandcout(Class(Interface1)->isDirectParentOf(Class(BaseObject)));
     537        testandcout(Class(Interface1)->isDirectParentOf(Class(Interface1)));
     538        testandcout(Class(Interface1)->isDirectParentOf(Class(A1)));
     539        testandcout(Class(Interface1)->isDirectParentOf(Class(A2)));
     540        testandcout(Class(Interface1)->isDirectParentOf(Class(A1B1)));
     541        testandcout(Class(Interface1)->isDirectParentOf(Class(A2B2)));
     542        testandcout(Class(Interface1)->isDirectParentOf(Class(A3B1C2)));
    462543*/
    463544/*
    464545        std::cout << "Test 6\n";
    465         std::cout << "1:\n";
     546        std::cout << "1\n";
    466547        Identifier* test6_01 = Class(A1B1);
    467         std::cout << "2:\n";
     548        std::cout << "2\n";
    468549        Identifier* test6_02 = Class(A1B1);
    469         std::cout << "3:\n";
     550        std::cout << "3\n";
    470551        Identifier* test6_03 = Class(A1);
    471         std::cout << "4:\n";
     552        std::cout << "4\n";
    472553        Identifier* test6_04 = Class(A1B1C1);
    473         std::cout << "5:\n";
     554        std::cout << "5\n";
    474555        Identifier* test6_05 = Class(A1B1);
    475         std::cout << "6:\n";
     556        std::cout << "6\n";
    476557        Identifier* test6_06 = Class(A1B1C1);
    477558
    478         std::cout << "\n";
    479         std::cout << "BaseObject: parents:     " << Class(BaseObject)->getParents().toString() << "\n";
    480         std::cout << "BaseObject: children:    " << Class(BaseObject)->getChildren().toString() << "\n";
    481 
    482         std::cout << "\n";
    483         std::cout << "A1: parents:     " << Class(A1)->getParents().toString() << "\n";
    484         std::cout << "A1: children:    " << Class(A1)->getChildren().toString() << "\n";
    485 
    486         std::cout << "\n";
    487         std::cout << "A1B1: parents:     " << Class(A1B1)->getParents().toString() << "\n";
    488         std::cout << "A1B1: children:    " << Class(A1B1)->getChildren().toString() << "\n";
    489 
    490         std::cout << "\n";
    491         std::cout << "A1B1C1: parents:     " << Class(A1B1C1)->getParents().toString() << "\n";
    492         std::cout << "A1B1C1: children:    " << Class(A1B1C1)->getChildren().toString() << "\n";
    493 
    494         std::cout << "\n";
    495         std::cout << "A3B1C1 child of A3:  " << Class(A3B1C1)->isChildOf(Class(A3)) << "\n";
    496         std::cout << "\n";
    497         std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n";
     559        std::cout << "7\n";
     560
     561        std::cout << "\n";
     562        std::cout << "BaseObject: parents:         " << Class(BaseObject)->getParents() << "\n";
     563        std::cout << "BaseObject: children:        " << Class(BaseObject)->getChildren() << "\n";
     564        std::cout << "BaseObject: direct parents:  " << Class(BaseObject)->getDirectParents() << "\n";
     565        std::cout << "BaseObject: direct children: " << Class(BaseObject)->getDirectChildren() << "\n";
     566
     567        std::cout << "\n";
     568        std::cout << "A1: parents:                 " << Class(A1)->getParents() << "\n";
     569        std::cout << "A1: children:                " << Class(A1)->getChildren() << "\n";
     570        std::cout << "A1: direct parents:          " << Class(A1)->getDirectParents() << "\n";
     571        std::cout << "A1: direct children:         " << Class(A1)->getDirectChildren() << "\n";
     572
     573        std::cout << "\n";
     574        std::cout << "A1B1: parents:               " << Class(A1B1)->getParents() << "\n";
     575        std::cout << "A1B1: children:              " << Class(A1B1)->getChildren() << "\n";
     576        std::cout << "A1B1: direct parents:        " << Class(A1B1)->getDirectParents() << "\n";
     577        std::cout << "A1B1: direct children:       " << Class(A1B1)->getDirectChildren() << "\n";
     578
     579        std::cout << "\n";
     580        std::cout << "A1B1C1: parents:             " << Class(A1B1C1)->getParents() << "\n";
     581        std::cout << "A1B1C1: children:            " << Class(A1B1C1)->getChildren() << "\n";
     582        std::cout << "A1B1C1: direct parents:      " << Class(A1B1C1)->getDirectParents() << "\n";
     583        std::cout << "A1B1C1: direct children:     " << Class(A1B1C1)->getDirectChildren() << "\n";
     584
     585        std::cout << "\n";
     586        std::cout << "A3B1C1 child of A3:      " << Class(A3B1C1)->isChildOf(Class(A3)) << "\n";
     587        std::cout << "\n";
     588        std::cout << "A2 parent of A2B1C1:     " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n";
     589
     590        std::cout << "8\n";
    498591*/
    499592/*
     
    510603*/
    511604/*
     605// ## WARNING - CRASH! ##
    512606        std::cout << "2\n";
    513607
     
    520614        SubclassIdentifier<A1B1> test7_05;
    521615        test7_05 = Class(A2);
     616// ## END WARNING - CRASH! ##
    522617*/
    523618/*
     
    558653        delete test8_02;
    559654        delete test8_03;
    560 
    561 
     655*/
     656/*
    562657        std::cout << "Test 9\n";
    563658        std::cout << "1\n";
     
    603698        int count;
    604699
    605         count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
     700        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it; ++it) { count++; }
    606701        std::cout << "Anzahl BaseObjects: " << count << "\n";
    607         count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
     702        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it; ++it) { count++; }
    608703        std::cout << "Anzahl A1: " << count << "\n";
    609704        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
     
    616711        std::cout << "2\n";
    617712        BaseObject* test10_08;
    618         BaseObject* test10_09;
    619         BaseObject* test10_10;
     713        BaseObject* test10_09 = 0;
     714        BaseObject* test10_10 = 0;
    620715        for (int i = 0; i < 10; i++)
    621716        {
     
    632727        }
    633728
    634         count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
     729        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it; ++it) { count++; }
    635730        std::cout << "Anzahl BaseObjects: " << count << "\n";
    636         count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
     731        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it; ++it) { count++; }
    637732        std::cout << "Anzahl A1: " << count << "\n";
    638733        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
     
    653748        delete test10_08;
    654749
    655         count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
     750        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it; ++it) { count++; }
    656751        std::cout << "Anzahl BaseObjects: " << count << "\n";
    657         count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
     752        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it; ++it) { count++; }
    658753        std::cout << "Anzahl A1: " << count << "\n";
    659754        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
     
    675770        delete test10_09;
    676771
    677         count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it != 0; --it) { count++; }
     772        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it; --it) { count++; }
    678773        std::cout << "Anzahl BaseObjects: " << count << "\n";
    679         count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it != 0; --it) { count++; }
     774        count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it; --it) { count++; }
    680775        std::cout << "Anzahl A1: " << count << "\n";
    681776        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::end(); it; --it) { count++; }
     
    697792        delete test10_10;
    698793
    699         count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
     794        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it; ++it) { count++; }
    700795        std::cout << "Anzahl BaseObjects: " << count << "\n";
    701         count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
     796        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it; ++it) { count++; }
    702797        std::cout << "Anzahl A1: " << count << "\n";
    703798        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
     
    721816        std::cout << "Test 11\n";
    722817        std::cout << "1\n";
    723         count = 0; for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) { count++; }
    724         std::cout << "AnzahlTickable: " << count << "\n";
     818        int count2 = 0; for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) { count2++; }
     819        std::cout << "AnzahlTickable: " << count2 << "\n";
    725820
    726821        Test1* test11_1;
     
    728823            test11_1 = new Test1;
    729824
    730         count = 0; for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) { count++; }
    731         std::cout << "AnzahlTickable: " << count << "\n";
     825        count2 = 0; for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) { count2++; }
     826        std::cout << "AnzahlTickable: " << count2 << "\n";
    732827
    733828        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
     
    736831        std::cout << "2\n";
    737832        Test2* test11_2 = new Test2;
    738 */
    739 /*
     833
     834
    740835        std::cout << "3\n";
    741836        Test3* test11_3 = new Test3;
     
    834929        std::cout << "Mask 2:\n";
    835930        TestClassTreeMask(test13_2);
    836 /*
     931
     932        std::cout << "2\n";
     933
    837934        ClassTreeMask test13_3;
    838         test13_3.include(Class(A1));
    839         test13_3.exclude(Class(A1B2));
    840         test13_3.exclude(Class(A1B1C2));
    841         test13_3.include(Class(A2));
    842         test13_3.exclude(Class(A2B2));
    843         test13_3.include(Class(A3B1));
    844         test13_3.include(Class(A3B2));
    845         test13_3.exclude(Class(A3B2C2));
     935        test13_3.include(Class(A1), true, false);
     936        test13_3.exclude(Class(A1B2), true, false);
     937        test13_3.exclude(Class(A1B1C2), true, false);
     938        test13_3.include(Class(A2), true, false);
     939        test13_3.exclude(Class(A2B2), true, false);
     940        test13_3.include(Class(A3B1), true, false);
     941        test13_3.include(Class(A3B2), true, false);
     942        test13_3.exclude(Class(A3B2C2), true, false);
    846943        std::cout << std::endl;
    847944        std::cout << "Mask 2 without excluded BaseObject:\n";
    848945        TestClassTreeMask(test13_3);
    849         test13_3.exclude(Class(BaseObject));
    850         std::cout << std::endl;
    851         std::cout << "Mask 2 with BaseObject excluded afterwards:\n";
     946        test13_3.exclude(Class(BaseObject), false, false);
     947        std::cout << std::endl;
     948        std::cout << "Mask 2 with BaseObject excluded afterwards without overwrite:\n";
    852949        TestClassTreeMask(test13_3);
    853 
    854         ClassTreeMask test13_3_2;
    855         test13_3_2.include(Class(A1));
    856         test13_3_2.exclude(Class(A1B2));
    857         test13_3_2.exclude(Class(A1B1C2));
    858         test13_3_2.include(Class(A2));
    859         test13_3_2.exclude(Class(A2B2));
    860         test13_3_2.include(Class(A3B1));
    861         test13_3_2.include(Class(A3B2));
    862         test13_3_2.exclude(Class(A3B2C2));
    863         test13_3_2.clean();
    864         test13_3_2.exclude(Class(BaseObject));
    865         std::cout << std::endl;
    866         std::cout << "Mask 2 with BaseObject excluded afterwards, but cleaned before:\n";
    867         TestClassTreeMask(test13_3_2);
    868         test13_3_2.include(Class(BaseObject));
    869         std::cout << std::endl;
    870         std::cout << "Mask 2 from before, but BaseObject re-included without cleaning:\n";
    871         TestClassTreeMask(test13_3_2);
     950        test13_3.exclude(Class(BaseObject), true);
     951        std::cout << std::endl;
     952        std::cout << "Mask 2 with BaseObject excluded afterwards with overwrite:\n";
     953        TestClassTreeMask(test13_3);
    872954
    873955        ClassTreeMask test13_4;
     
    882964        test13_4.include(Class(A1));
    883965        std::cout << std::endl;
    884         std::cout << "Mask 2 created in random order:\n";
     966        std::cout << "Mask 2 created in random order with overwrite and clean:\n";
    885967        TestClassTreeMask(test13_4);
    886968
    887         std::cout << "2\n";
    888 
    889         ClassTreeMask test13_5 = test13_1;
    890         std::cout << std::endl;
    891         std::cout << "Mask 1 assigned to a new ClassTestMask:\n";
    892         TestClassTreeMask(test13_5);
     969        ClassTreeMask test13_4_2;
     970        test13_4_2.include(Class(A3B2), false, false);
     971        test13_4_2.exclude(Class(A1B1C2), false, false);
     972        test13_4_2.include(Class(A3B1), false, false);
     973        test13_4_2.exclude(Class(A3B2C2), false, false);
     974        test13_4_2.exclude(Class(BaseObject), false, false);
     975        test13_4_2.include(Class(A2), false, false);
     976        test13_4_2.exclude(Class(A1B2), false, false);
     977        test13_4_2.exclude(Class(A2B2), false, false);
     978        test13_4_2.include(Class(A1), false, false);
     979        std::cout << std::endl;
     980        std::cout << "Mask 2 created in random order without overwrite and without clean:\n";
     981        TestClassTreeMask(test13_4_2);
    893982
    894983        std::cout << "3\n";
     
    9291018        std::cout << "8\n";
    9301019
    931         std::cout << std::endl;
    932         ClassTreeMask test13_11(test13_1);
    933         std::cout << std::endl;
    934         std::cout << "Mask 1 assigned with copyconstructor + original mask 1:\n";
    935         TestClassTreeMask(test13_11);
    936         TestClassTreeMask(test13_1);
    937 
    938         ClassTreeMask test13_12(!test13_11);
     1020        ClassTreeMask test13_12(!test13_1);
    9391021        std::cout << std::endl;
    9401022        std::cout << "Mask 1 inverted assigned with copyconstructor + the original from before:\n";
    9411023        TestClassTreeMask(test13_12);
    942         TestClassTreeMask(test13_11);
    943 
    944         ClassTreeMask test13_13;
    945         test13_13 = test13_2;
    946         std::cout << std::endl;
    947         std::cout << "Mask 2 assigned with = operator + original mask 2:\n";
     1024        TestClassTreeMask(test13_1);
     1025
     1026
     1027        ClassTreeMask test13_13 = test13_1 + test13_2;
     1028        std::cout << std::endl;
     1029        std::cout << "Mask 1 + Mask 2 assigned with copyconstructor + originals from before:\n";
    9481030        TestClassTreeMask(test13_13);
     1031        TestClassTreeMask(test13_1);
    9491032        TestClassTreeMask(test13_2);
    9501033
    951         ClassTreeMask test13_14 = test13_11 + test13_13;
    952         std::cout << std::endl;
    953         std::cout << "Mask 1 + Mask 2 assigned with copyconstructor + originals from before:\n";
     1034        ClassTreeMask test13_14 = test13_1;
     1035        test13_14 += test13_2;
     1036        std::cout << std::endl;
     1037        std::cout << "Mask 1 + Mask 2 with += operator + original of mask 2 from before:\n";
    9541038        TestClassTreeMask(test13_14);
    955         TestClassTreeMask(test13_11);
    956         TestClassTreeMask(test13_13);
    957 
    958         test13_11 += test13_13;
    959         std::cout << std::endl;
    960         std::cout << "Mask 1 + Mask 2 with += operator + original of mask 2 from before:\n";
    961         TestClassTreeMask(test13_11);
    962         TestClassTreeMask(test13_13);
     1039        TestClassTreeMask(test13_2);
    9631040
    9641041        test13_1 = test13_1;
     
    9681045
    9691046        std::cout << "9\n";
    970 */
    971 
     1047
     1048        ClassTreeMask test13_15;
     1049        test13_15.exclude(Class(Interface1));
     1050        std::cout << std::endl;
     1051        std::cout << "Mask with excluded Interface 1:\n";
     1052        TestClassTreeMask(test13_15);
     1053
     1054        ClassTreeMask test13_16 = test13_1;
     1055        test13_16.exclude(Class(Interface1));
     1056        std::cout << std::endl;
     1057        std::cout << "Mask 1 with excluded Interface 1 (overwrite):\n";
     1058        TestClassTreeMask(test13_16);
     1059
     1060        ClassTreeMask test13_17 = test13_1;
     1061        test13_17.exclude(Class(Interface1), false);
     1062        std::cout << std::endl;
     1063        std::cout << "Mask 1 with excluded Interface 1 (without overwrite):\n";
     1064        TestClassTreeMask(test13_17);
     1065
     1066        ClassTreeMask test13_18 = test13_2;
     1067        test13_18.exclude(Class(Interface1), false);
     1068        std::cout << std::endl;
     1069        std::cout << "Mask 2 with excluded Interface 1 (without overwrite):\n";
     1070        TestClassTreeMask(test13_18);
     1071
     1072        std::cout << "10\n";
     1073
     1074        ClassTreeMask test13_19;
     1075        test13_19.exclude(Class(Test1));
     1076        std::cout << std::endl;
     1077        std::cout << "Mask with excluded Test1:\n";
     1078        TestClassTreeMask(test13_19);
     1079
     1080        std::cout << "11\n";
     1081
     1082        ClassTreeMask test13_20;
     1083        test13_20.exclude(Class(DebugLevel));
     1084        std::cout << std::endl;
     1085        std::cout << "Mask with excluded DebugLevel:\n";
     1086        TestClassTreeMask(test13_20);
     1087
     1088        std::cout << "12\n";
     1089
     1090/*
    9721091        std::cout << "Test 14\n";
    9731092        std::cout << "1\n";
     
    9911110        std::cout << test14_5.getIdentifier()->getName() << std::endl;
    9921111
     1112        std::cout << "2\n";
     1113*/
    9931114//    startRenderLoop();
    9941115  }
  • code/branches/core/src/orxonox/core/ClassTreeMask.cc

    r813 r817  
    5757    {
    5858        // Go through the list of all subnodes and delete them
     59        this->deleteAllSubnodes();
     60    }
     61
     62    /**
     63        @brief Sets the rule for the node to "included".
     64    */
     65    void ClassTreeMaskNode::include(bool overwrite)
     66    {
     67        this->setIncluded(true, overwrite);
     68    }
     69
     70    /**
     71        @brief Sets the rule for the node to "excluded".
     72    */
     73    void ClassTreeMaskNode::exclude(bool overwrite)
     74    {
     75        this->setIncluded(false, overwrite);
     76    }
     77
     78    /**
     79        @brief Sets the rule for the node to a given value and erases all following rules.
     80        @param bIncluded The rule: included (true) or excluded (false)
     81    */
     82    void ClassTreeMaskNode::setIncluded(bool bIncluded, bool overwrite)
     83    {
     84        if (overwrite)
     85            this->deleteAllSubnodes();
     86
     87        this->bIncluded_ = bIncluded;
     88    }
     89
     90    /**
     91        @brief Adds a new subnode to the list of subnodes.
     92        @param subnode The new subnode
     93    */
     94    void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode)
     95    {
     96        this->subnodes_.insert(this->subnodes_.end(), subnode);
     97    }
     98
     99    /**
     100        @brief Tells if the rule is "included" or not.
     101        @return The rule: true = included, false = excluded
     102    */
     103    bool ClassTreeMaskNode::isIncluded() const
     104    {
     105        return this->bIncluded_;
     106    }
     107
     108    /**
     109        @brief Tells if the rule is "excluded" or not.
     110        @return The inverted rule: true = excluded, false = included
     111    */
     112    bool ClassTreeMaskNode::isExcluded() const
     113    {
     114        return (!this->bIncluded_);
     115    }
     116
     117    /**
     118        @brief Returns the Identifier of the class the rule refers to.
     119        @return The Identifier representing the class
     120    */
     121    const Identifier* ClassTreeMaskNode::getClass() const
     122    {
     123        return this->subclass_;
     124    }
     125
     126    /**
     127        @brief Deletes all subnodes of this node.
     128    */
     129    void ClassTreeMaskNode::deleteAllSubnodes()
     130    {
     131        // Go through the list of all subnodes and delete them
    59132        for (std::list<ClassTreeMaskNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); )
    60133            delete (*(it++));
    61     }
    62 
    63     /**
    64         @brief Sets the rule for the node to "included".
    65     */
    66     void ClassTreeMaskNode::include()
    67     {
    68         this->bIncluded_ = true;
    69     }
    70 
    71     /**
    72         @brief Sets the rule for the node to "excluded".
    73     */
    74     void ClassTreeMaskNode::exclude()
    75     {
    76         this->bIncluded_ = false;
    77     }
    78 
    79     /**
    80         @brief Sets the rule for the node to a given value.
    81         @param bIncluded The rule: included (true) or excluded (false)
    82     */
    83     void ClassTreeMaskNode::setIncluded(bool bIncluded)
    84     {
    85         this->bIncluded_ = bIncluded;
    86     }
    87 
    88     /**
    89         @brief Adds a new subnode to the list of subnodes.
    90         @param subnode The new subnode
    91     */
    92     void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode)
    93     {
    94         this->subnodes_.insert(this->subnodes_.end(), subnode);
    95     }
    96 
    97     /**
    98         @brief Tells if the rule is "included" or not.
    99         @return The rule: true = included, false = excluded
    100     */
    101     bool ClassTreeMaskNode::isIncluded() const
    102     {
    103         return this->bIncluded_;
    104     }
    105 
    106     /**
    107         @brief Tells if the rule is "excluded" or not.
    108         @return The inverted rule: true = excluded, false = included
    109     */
    110     bool ClassTreeMaskNode::isExcluded() const
    111     {
    112         return (!this->bIncluded_);
    113     }
    114 
    115     /**
    116         @brief Returns the Identifier of the class the rule refers to.
    117         @return The Identifier representing the class
    118     */
    119     const Identifier* ClassTreeMaskNode::getClass() const
    120     {
    121         return this->subclass_;
     134
     135        // Clear the list
     136        this->subnodes_.clear();
    122137    }
    123138
     
    258273        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier(), true);
    259274        for (ClassTreeMaskIterator it = other.root_; it; ++it)
    260             this->add(it->getClass(), it->isIncluded());
     275            this->add(it->getClass(), it->isIncluded(), false);
    261276    }
    262277
     
    273288        @param subclass The subclass
    274289    */
    275     void ClassTreeMask::include(const Identifier* subclass)
    276     {
    277         this->add(subclass, true);
     290    void ClassTreeMask::include(const Identifier* subclass, bool overwrite, bool clean)
     291    {
     292        this->add(subclass, true, overwrite, clean);
    278293    }
    279294
     
    282297        @param subclass The subclass
    283298    */
    284     void ClassTreeMask::exclude(const Identifier* subclass)
    285     {
    286         this->add(subclass, false);
     299    void ClassTreeMask::exclude(const Identifier* subclass, bool overwrite, bool clean)
     300    {
     301        this->add(subclass, false, overwrite, clean);
    287302    }
    288303
     
    292307        @param bInclude The rule: include (true) or exclude (false)
    293308    */
    294     void ClassTreeMask::add(const Identifier* subclass, bool bInclude)
    295     {
     309    void ClassTreeMask::add(const Identifier* subclass, bool bInclude, bool overwrite, bool clean)
     310    {
     311        // Check if the given subclass is a child of our root-class
    296312        if (subclass->isA(this->root_->getClass()))
    297             this->add(this->root_, subclass, bInclude);
     313        {
     314            // Yes it is: Just add the rule to the three
     315            this->add(this->root_, subclass, bInclude, overwrite);
     316        }
    298317        else
    299318        {
    300 
    301         }
    302 
    303         this->clean();
     319            // No it's not: Search for classes inheriting from the given class and add the rules for them
     320            for (std::list<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it)
     321                if ((*it)->isA(this->root_->getClass()))
     322                    if (overwrite || (!this->nodeExists(*it))) // If we don't want to overwrite, only add nodes that don't already exist
     323                        this->add(this->root_, *it, bInclude, overwrite);
     324        }
     325
     326        // Clean the rule-tree
     327        if (clean)
     328            this->clean();
    304329    }
    305330
     
    310335        @param bInclude The rule: include (true) or exclude (false)
    311336    */
    312     void ClassTreeMask::add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude)
     337    void ClassTreeMask::add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude, bool overwrite)
    313338    {
    314339        // Check if the current node contains exactly the subclass we want to add
     
    316341        {
    317342            // We're at the right place, just change the mask and return
    318             node->setIncluded(bInclude);
     343            node->setIncluded(bInclude, overwrite);
    319344            return;
    320345        }
    321         else
     346        else if (subclass->isA(node->getClass()))
    322347        {
    323348            // Search for an already existing node, containing the subclass we want to add
     
    327352                {
    328353                    // We've found an existing node -> delegate the work with a recursive function-call and return
    329                     this->add(*it, subclass, bInclude);
     354                    this->add(*it, subclass, bInclude, overwrite);
    330355                    return;
    331356                }
     
    335360            ClassTreeMaskNode* newnode = new ClassTreeMaskNode(subclass, bInclude);
    336361
    337             // Search for nodes that should actually be subnodes of our new node
     362            // Search for nodes that should actually be subnodes of our new node and erase them
    338363            for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); )
    339364            {
    340365                if ((*it)->getClass()->isChildOf(subclass))
    341366                {
    342                     // We've found a subnode: add it to the new node an erase it from the current node
    343                     newnode->addSubnode(*it);
     367                    // We've found a subnode: add it to the new node and erase it from the current node
     368                    if (!overwrite)
     369                        newnode->addSubnode(*it);
     370                    else
     371                        delete (*it);
     372
    344373                    node->subnodes_.erase(it++);
    345374                }
     
    453482
    454483    /**
     484        @brief Checks if a node for the given subclass exists.
     485        @param subclass The Identifier of the subclass
     486        @return True = the node exists
     487    */
     488    bool ClassTreeMask::nodeExists(const Identifier* subclass)
     489    {
     490        for (ClassTreeMaskIterator it = this->root_; it; ++it)
     491            if ((*it)->getClass() == subclass)
     492                return true;
     493
     494        return false;
     495    }
     496
     497    /**
    455498        @brief Assignment operator: Adds all rules of the other mask.
    456499        @param other The other mask
     
    467510        // Copy all rules from the other mask
    468511        for (ClassTreeMaskIterator it = temp.root_; it; ++it)
    469             this->add(it->getClass(), it->isIncluded());
     512            this->add(it->getClass(), it->isIncluded(), false, false);
    470513
    471514        // Return a reference to the mask itself
     
    505548        {
    506549            const Identifier* subclass = it->getClass();
    507             newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
     550            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false);
    508551        }
    509552
     
    512555        {
    513556            const Identifier* subclass = it->getClass();
    514             newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
     557            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false);
    515558        }
    516559
     
    536579        {
    537580            const Identifier* subclass = it->getClass();
    538             newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
     581            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false);
    539582        }
    540583
     
    543586        {
    544587            const Identifier* subclass = it->getClass();
    545             newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
     588            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false);
    546589        }
    547590
     
    576619        {
    577620            const Identifier* subclass = it->getClass();
    578             newmask.add(subclass, !this->isIncluded(subclass));
     621            newmask.add(subclass, !this->isIncluded(subclass), false, false);
    579622        }
    580623
     
    650693        {
    651694            const Identifier* subclass = it->getClass();
    652             newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
     695            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false);
    653696        }
    654697
     
    657700        {
    658701            const Identifier* subclass = it->getClass();
    659             newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
     702            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false);
    660703        }
    661704
  • code/branches/core/src/orxonox/core/ClassTreeMask.h

    r813 r817  
    3434    Identifier of the class.
    3535
    36     You can work with a ClassTreeMask in the sense of the set theory, meaning that you can create
     36    You can work with a ClassTreeMask in the sense of the set-theory, meaning that you can create
    3737    unions, intersections, complements and differences by using overloaded operators.
     38
     39
    3840
    3941    The ClassTreeMask is internally represented by a tree. The nodes in the tree are
     
    4244    nodes changing the mask. By adding new rules, the tree gets reordered dynamically.
    4345
    44     You can manually add useless rules and they stay in the tree. That way you can add rules in
    45     any order without changing information of the resulting mask. Example: A new mask includes all
    46     classes. Now you explicitly include a subclass. This seems to be useless. But if you exclude a
    47     baseclass of the formerly included subclass, the subclass stays included. You could create the
    48     same mask by first excluding the baseclass and then including the subclass. You can drop
    49     useless rules from the tree by calling clean().
     46    Adding a new rule overwrites all rules assigned to inherited classes. Use overwrite = false
     47    if you don't like this feature. Useless rules that don't change the information of the mask
     48    aren't saved in the internal tree. Use clean = false if you wan't to save them.
     49
     50    With overwrite = false and clean = false it doesn't matter in which way you create the mask.
     51    You can manually drop useless rules from the tree by calling clean().
     52
     53
    5054
    5155    Because of the complicated shape of the internal tree, there is an iterator to iterate
     
    9195            ~ClassTreeMaskNode();
    9296
    93             void include();
    94             void exclude();
    95             void setIncluded(bool bIncluded);
     97            void include(bool overwrite = true);
     98            void exclude(bool overwrite = true);
     99            void setIncluded(bool bIncluded, bool overwrite = true);
    96100
    97101            void addSubnode(ClassTreeMaskNode* subnode);
     
    103107
    104108        private:
     109            void deleteAllSubnodes();
     110
    105111            const Identifier* subclass_;                //!< The Identifier of the subclass the rule refers to
    106112            bool bIncluded_;                            //!< The rule: included or excluded
     
    146152        With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting
    147153        with a given subclass, described by the corresponding Identifier. To minimize the size
    148         of the mask, the mask saves only relevant rules. But you are allowed to manually add
    149         rules that don't change the information of the mask. This way you can create the same
    150         mask by adding the same rules in a different way without changing the information. If
    151         you want to drop useless rules, call the clean() function.
     154        of the mask, the mask saves only relevant rules. But you can manually add rules that
     155        don't change the information of the mask by using clean = false. If you want to drop
     156        useless rules, call the clean() function.
    152157    */
    153158    class _CoreExport ClassTreeMask
     
    158163            ~ClassTreeMask();
    159164
    160             void include(const Identifier* subclass);
    161             void exclude(const Identifier* subclass);
    162             void add(const Identifier* subclass, bool bInclude);
     165            void include(const Identifier* subclass, bool overwrite = true, bool clean = true);
     166            void exclude(const Identifier* subclass, bool overwrite = true, bool clean = true);
     167            void add(const Identifier* subclass, bool bInclude, bool overwrite = true, bool clean = true);
    163168            void reset();
    164169            void clean();
     
    193198
    194199        private:
    195             void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude);
     200            void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude, bool overwrite = true);
    196201            bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const;
    197202            void clean(ClassTreeMaskNode* node);
     203            bool nodeExists(const Identifier* subclass);
    198204
    199205            ClassTreeMaskNode* root_;   //!< The root-node of the internal rule-tree, usually BaseObject
  • code/branches/core/src/orxonox/core/Factory.cc

    r813 r817  
    109109      return &theOneAndOnlyFactoryInstance;
    110110    }
     111
     112    /**
     113        @brief Returns the begin-iterator of the factory-map.
     114        @return The begin-iterator
     115    */
     116    std::map<std::string, Identifier*>::const_iterator Factory::getFactoryBegin()
     117    {
     118        return Factory::getFactoryPointer()->identifierStringMap_.begin();
     119    }
     120
     121    /**
     122        @brief Returns the end-iterator of the factory-map.
     123        @return The end-iterator
     124    */
     125    std::map<std::string, Identifier*>::const_iterator Factory::getFactoryEnd()
     126    {
     127        return Factory::getFactoryPointer()->identifierStringMap_.end();
     128    }
    111129}
  • code/branches/core/src/orxonox/core/Factory.h

    r813 r817  
    6767
    6868            static Factory* getFactoryPointer();    // avoid overriding order problem in the static intialisation process
     69            static std::map<std::string, Identifier*>::const_iterator getFactoryBegin();
     70            static std::map<std::string, Identifier*>::const_iterator getFactoryEnd();
    6971
    7072        private:
  • code/branches/core/src/orxonox/core/Identifier.cc

    r813 r817  
    3030    @brief Implementation of the Identifier class.
    3131*/
     32
     33#include <ostream>
    3234
    3335#include "Identifier.h"
     
    5052
    5153        this->children_ = new std::list<const Identifier*>();
     54        this->directChildren_ = new std::list<const Identifier*>();
    5255
    5356        // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables
     
    6265    {
    6366        delete this->children_;
     67        delete this->directChildren_;
    6468    }
    6569
     
    7579        if (parents)
    7680        {
    77             std::list<const Identifier*>::iterator temp1 = parents->begin();
    78             while (temp1 != parents->end())
     81            this->parents_ = (*parents);
     82            this->directParents_ = (*parents);
     83
     84            // Iterate through all parents
     85            for (std::list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
    7986            {
    80                 this->parents_.insert(this->parents_.end(), *temp1);
    81                 (*temp1)->getChildren().insert((*temp1)->getChildren().end(), this); // We're a child of our parents
    82 
    83                 ++temp1;
     87                // Tell the parent we're one of it's children
     88                (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
     89
     90                // Erase all parents of our parent from our direct-parent-list
     91                for (std::list<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
     92                {
     93                    // Search for the parent's parent in our direct-parent-list
     94                    for (std::list<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
     95                    {
     96                        if ((*it1) == (*it2))
     97                        {
     98                            // We've found a non-direct parent in our list: Erase it
     99                            this->directParents_.erase(it2);
     100                            break;
     101                        }
     102                    }
     103                }
     104            }
     105
     106            // Now iterate through all direct parents
     107            for (std::list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
     108            {
     109                // Tell the parent we're one of it's direct children
     110                (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
    84111            }
    85112        }
     
    98125        else
    99126        {
    100             // Abstract classes don't have a factory and therefore can't create new objects
    101127            COUT(1) << "An error occurred in Identifier:" << std::endl;
    102             COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract." << std::endl;
     128            COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl;
    103129            COUT(1) << "Aborting..." << std::endl;
    104130            abort();
     
    130156        @param identifier The identifier to compare with
    131157    */
    132     bool Identifier::isDirectlyA(const Identifier* identifier) const
     158    bool Identifier::isExactlyA(const Identifier* identifier) const
    133159    {
    134160        return (identifier == this);
     
    145171
    146172    /**
     173        @brief Returns true, if the assigned identifier is a direct child of the given identifier.
     174        @param identifier The identifier to compare with
     175    */
     176    bool Identifier::isDirectChildOf(const Identifier* identifier) const
     177    {
     178        return this->identifierIsInList(identifier, this->directParents_);
     179    }
     180
     181    /**
    147182        @brief Returns true, if the assigned identifier is a parent of the given identifier.
    148183        @param identifier The identifier to compare with
     
    151186    {
    152187        return this->identifierIsInList(identifier, *this->children_);
     188    }
     189
     190    /**
     191        @brief Returns true, if the assigned identifier is a direct parent of the given identifier.
     192        @param identifier The identifier to compare with
     193    */
     194    bool Identifier::isDirectParentOf(const Identifier* identifier) const
     195    {
     196        return this->identifierIsInList(identifier, *this->directChildren_);
    153197    }
    154198
     
    167211        return false;
    168212    }
     213
     214    std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list)
     215    {
     216        for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
     217            out << (*it)->getName() << " ";
     218
     219        return out;
     220    }
    169221}
  • code/branches/core/src/orxonox/core/Identifier.h

    r814 r817  
    3939
    4040    Every object has a pointer to the Identifier of its class. This allows the use isA(...),
    41     isDirectlyA(...), isChildOf(...) and isParentOf(...).
     41    isExactlyA(...), isChildOf(...) and isParentOf(...).
    4242
    4343    To create the class-hierarchy, the Identifier has some intern functions and variables.
     
    8282
    8383        Every object has a pointer to the Identifier of its class. This allows the use isA(...),
    84         isDirectlyA(...), isChildOf(...) and isParentOf(...).
     84        isExactlyA(...), isChildOf(...) and isParentOf(...).
    8585
    8686        You can't directly create an Identifier, it's just the base-class for ClassIdentifier.
     
    102102            BaseObject* fabricate();
    103103            bool isA(const Identifier* identifier) const;
    104             bool isDirectlyA(const Identifier* identifier) const;
     104            bool isExactlyA(const Identifier* identifier) const;
    105105            bool isChildOf(const Identifier* identifier) const;
     106            bool isDirectChildOf(const Identifier* identifier) const;
    106107            bool isParentOf(const Identifier* identifier) const;
     108            bool isDirectParentOf(const Identifier* identifier) const;
    107109
    108110            /** @brief Removes all objects of the corresponding class. */
     
    114116            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    115117            inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
    116 
    117118            /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
    118119            inline std::list<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
    119 
    120120            /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */
    121121            inline std::list<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
    122122
     123            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
     124            inline const std::list<const Identifier*>& getChildren() const { return (*this->children_); }
    123125            /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
    124126            inline std::list<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
    125 
    126127            /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
    127128            inline std::list<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
     129
     130            /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
     131            inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
     132            /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */
     133            inline std::list<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
     134            /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */
     135            inline std::list<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
     136
     137            /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
     138            inline const std::list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
     139            /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
     140            inline std::list<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
     141            /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
     142            inline std::list<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
    128143
    129144            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
     
    143158            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
    144159                { this->configValues_[varname] = container; }
     160
     161            static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
    145162
    146163        private:
     
    150167            void initialize(std::list<const Identifier*>* parents);
    151168
    152             /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    153             inline std::list<const Identifier*>& getParents() { return this->parents_; }
    154 
    155169            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    156             inline std::list<const Identifier*>& getChildren() const { return (*this->children_); }
     170            inline std::list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     171            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
     172            inline std::list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    157173
    158174            /**
     
    174190            }
    175191
    176             static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
    177 
    178             std::list<const Identifier*> parents_;                      //!< The Parents of the class the Identifier belongs to
    179             std::list<const Identifier*>* children_;                    //!< The Children of the class the Identifier belongs to
     192            std::list<const Identifier*> parents_;                      //!< The parents of the class the Identifier belongs to
     193            std::list<const Identifier*>* children_;                    //!< The children of the class the Identifier belongs to
     194
     195            std::list<const Identifier*> directParents_;                //!< The direct parents of the class the Identifier belongs to
     196            std::list<const Identifier*>* directChildren_;              //!< The direct children of the class the Identifier belongs to
    180197
    181198            std::string name_;                                          //!< The name of the class the Identifier belongs to
     
    188205    };
    189206
     207    std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list);
     208
    190209
    191210    // ###############################
     
    215234            void removeObjects() const;
    216235            void setName(const std::string& name);
     236            inline const ObjectList<T>* getObjects() const { return this->objects_; }
    217237
    218238        private:
     
    231251    ClassIdentifier<T>::ClassIdentifier()
    232252    {
    233         this->objects_ = ObjectList<T>::getList();
     253//        this->objects_ = ObjectList<T>::getList();
     254        this->objects_ = new ObjectList<T>();
    234255        this->bSetName_ = false;
    235256    }
     
    294315    void ClassIdentifier<T>::removeObjects() const
    295316    {
    296         for (Iterator<T> it = ObjectList<T>::start(); it;)
     317        for (Iterator<T> it = this->objects_->start(); it;)
    297318            delete *(it++);
    298319    }
     320
    299321
    300322    // ###############################
     
    409431
    410432            /** @brief Returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */
    411             inline bool isDirectlyA(const Identifier* identifier) const
    412                 { return this->identifier_->isDirectlyA(identifier); }
     433            inline bool isExactlyA(const Identifier* identifier) const
     434                { return this->identifier_->isExactlyA(identifier); }
    413435
    414436            /** @brief Returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */
     
    416438                { return this->identifier_->isChildOf(identifier); }
    417439
     440            /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */
     441            inline bool isDirectChildOf(const Identifier* identifier) const
     442                { return this->identifier_->isDirectChildOf(identifier); }
     443
    418444            /** @brief Returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */
    419445            inline bool isParentOf(const Identifier* identifier) const
    420446                { return this->identifier_->isParentOf(identifier); }
     447
     448            /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */
     449            inline bool isDirectParentOf(const Identifier* identifier) const
     450                { return this->identifier_->isDirectParentOf(identifier); }
    421451
    422452        private:
  • code/branches/core/src/orxonox/core/ObjectList.h

    r813 r817  
    4040#include "CorePrereqs.h"
    4141#include "Iterator.h"
     42#include "ClassManager.h"
    4243
    4344namespace orxonox
     
    8384    {
    8485        public:
    85             static ObjectList<T>* getList();
     86            ObjectList();
     87            ~ObjectList();
    8688
    8789            ObjectListElement<T>* add(T* object);
     
    9092            /** @brief Returns the first element in the list. @return The first element */
    9193            inline static Iterator<T> start()
    92                 { return Iterator<T>(getList()->first_); }
     94                { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->first_); }
    9395
    9496            /** @brief Returns the first element in the list. @return The first element */
    9597            inline static Iterator<T> begin()
    96                 { return Iterator<T>(getList()->first_); }
     98                { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->first_); }
    9799
    98100            /** @brief Returns the last element in the list. @return The last element */
    99101            inline static Iterator<T> end()
    100                 { return Iterator<T>(getList()->last_); }
     102                { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->last_); }
    101103
    102104            ObjectListElement<T>* first_;       //!< The first element in the list
    103105            ObjectListElement<T>* last_;        //!< The last element in the list
    104 
    105         private:
    106             ObjectList();
    107             ~ObjectList();
    108106    };
    109107
     
    131129            this->first_ = temp;
    132130        }
    133     }
    134 
    135     /**
    136         @brief Returns a pointer to the only existing instance for the given class T. @return The instance
    137     */
    138     template <class T>
    139     ObjectList<T>* ObjectList<T>::getList()
    140     {
    141         static ObjectList<T> theOnlyObjectListObjectForClassT = ObjectList<T>();
    142         return &theOnlyObjectListObjectForClassT;
    143131    }
    144132
  • code/branches/core/src/orxonox/core/OrxonoxClass.h

    r813 r817  
    7272            inline void createParents() { this->parents_ = new std::list<const Identifier*>(); }
    7373
    74 //            /** @brief Sets the Parents of the object. Used by the RegisterObject-macro. */
    75 //            inline void setParents(std::list<const Identifier*>* parents) { this->parents_ = parents; }
    76 
    7774            /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */
    7875            inline MetaObjectList& getMetaList() { return this->metaList_; }
     
    8380                { return this->getIdentifier()->isA(identifier); }
    8481            /** @brief Returns true if the objects class is exactly of the given type. */
    85             inline bool isDirectlyA(const Identifier* identifier)
    86                 { return this->getIdentifier()->isDirectlyA(identifier); }
     82            inline bool isExactlyA(const Identifier* identifier)
     83                { return this->getIdentifier()->isExactlyA(identifier); }
    8784            /** @brief Returns true if the objects class is a child of the given type. */
    8885            inline bool isChildOf(const Identifier* identifier)
    8986                { return this->getIdentifier()->isChildOf(identifier); }
     87            /** @brief Returns true if the objects class is a direct child of the given type. */
     88            inline bool isDirectChildOf(const Identifier* identifier)
     89                { return this->getIdentifier()->isDirectChildOf(identifier); }
    9090            /** @brief Returns true if the objects class is a parent of the given type. */
    9191            inline bool isParentOf(const Identifier* identifier)
    9292                { return this->getIdentifier()->isParentOf(identifier); }
     93            /** @brief Returns true if the objects class is a direct parent of the given type. */
     94            inline bool isDirectParentOf(const Identifier* identifier)
     95                { return this->getIdentifier()->isDirectParentOf(identifier); }
    9396
    9497
     
    97100                { return this->getIdentifier()->isA(identifier->getIdentifier()); }
    98101            /** @brief Returns true if the objects class is exactly of the given type. */
    99             inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier)
    100                 { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); }
     102            inline bool isExactlyA(const SubclassIdentifier<class B>* identifier)
     103                { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
    101104            /** @brief Returns true if the objects class is a child of the given type. */
    102105            inline bool isChildOf(const SubclassIdentifier<class B>* identifier)
    103106                { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
     107            /** @brief Returns true if the objects class is a direct child of the given type. */
     108            inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier)
     109                { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
    104110            /** @brief Returns true if the objects class is a parent of the given type. */
    105111            inline bool isParentOf(const SubclassIdentifier<class B>* identifier)
    106112                { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
     113            /** @brief Returns true if the objects class is a direct parent of the given type. */
     114            inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier)
     115                { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
    107116
    108117
     
    111120                { return this->getIdentifier()->isA(identifier.getIdentifier()); }
    112121            /** @brief Returns true if the objects class is exactly of the given type. */
    113             inline bool isDirectlyA(const SubclassIdentifier<class B> identifier)
    114                 { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); }
     122            inline bool isExactlyA(const SubclassIdentifier<class B> identifier)
     123                { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
    115124            /** @brief Returns true if the objects class is a child of the given type. */
    116125            inline bool isChildOf(const SubclassIdentifier<class B> identifier)
    117126                { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
     127            /** @brief Returns true if the objects class is a direct child of the given type. */
     128            inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier)
     129                { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
    118130            /** @brief Returns true if the objects class is a parent of the given type. */
    119131            inline bool isParentOf(const SubclassIdentifier<class B> identifier)
    120132                { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
     133            /** @brief Returns true if the objects class is a direct parent of the given type. */
     134            inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier)
     135                { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
    121136
    122137
     
    125140                { return this->getIdentifier()->isA(object->getIdentifier()); }
    126141            /** @brief Returns true if the objects class is exactly of the given type. */
    127             inline bool isDirectlyA(const OrxonoxClass* object)
    128                 { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); }
     142            inline bool isExactlyA(const OrxonoxClass* object)
     143                { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
    129144            /** @brief Returns true if the objects class is a child of the given type. */
    130145            inline bool isChildOf(const OrxonoxClass* object)
    131146                { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
     147            /** @brief Returns true if the objects class is a direct child of the given type. */
     148            inline bool isDirectChildOf(const OrxonoxClass* object)
     149                { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
    132150            /** @brief Returns true if the objects class is a parent of the given type. */
    133151            inline bool isParentOf(const OrxonoxClass* object)
    134152                { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
     153            /** @brief Returns true if the objects class is a direct child of the given type. */
     154            inline bool isDirectParentOf(const OrxonoxClass* object)
     155                { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
    135156
    136157
  • code/branches/core/src/orxonox/objects/Test.h

    r811 r817  
    7474        public:
    7575            A1B2() { RegisterObject(A1B2); }
    76             virtual void test() = 0;
     76//            virtual void test() = 0;
    7777    };
    7878
     
    117117        public:
    118118            A1B2C1() { RegisterObject(A1B2C1); }
    119             void test() { std::cout << "test!\n"; }
     119//            void test() { std::cout << "test!\n"; }
    120120    };
    121121
     
    160160    CreateFactory(A3);
    161161    CreateFactory(A1B1);
    162 //    CreateFactory(A1B2);
     162    CreateFactory(A1B2);
    163163    CreateFactory(A2B1);
    164164    CreateFactory(A2B2);
Note: See TracChangeset for help on using the changeset viewer.