Changeset 807
- Timestamp:
- Feb 12, 2008, 8:36:19 PM (17 years ago)
- Location:
- code/branches/core/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/Orxonox.cc
r806 r807 764 764 #define TestClassTreeMask(mask) \ 765 765 std::cout << "========== ClassTreeMask-Test ===========" << std::endl; \ 766 std::cout << mask << std::endl << std::endl; \ 766 767 std::cout << " "; \ 767 768 BoolToYesNo(mask.isIncluded(Class(BaseObject))); \ … … 808 809 809 810 ClassTreeMask test13_1; 810 // test13_1.include(Class(BaseObject));811 811 test13_1.exclude(Class(A1B1)); 812 812 test13_1.exclude(Class(A2)); … … 817 817 test13_1.exclude(Class(A3B2C1)); 818 818 test13_1.exclude(Class(A3B2C2)); 819 std::cout << "Mask 1:\n"; 820 TestClassTreeMask(test13_1); 819 821 820 822 ClassTreeMask test13_2; … … 828 830 test13_2.include(Class(A3B2)); 829 831 test13_2.exclude(Class(A3B2C2)); 830 832 std::cout << std::endl; 833 std::cout << "Mask 2:\n"; 834 TestClassTreeMask(test13_2); 835 836 ClassTreeMask test13_3; 837 test13_3.include(Class(A1)); 838 test13_3.exclude(Class(A1B2)); 839 test13_3.exclude(Class(A1B1C2)); 840 test13_3.include(Class(A2)); 841 test13_3.exclude(Class(A2B2)); 842 test13_3.include(Class(A3B1)); 843 test13_3.include(Class(A3B2)); 844 test13_3.exclude(Class(A3B2C2)); 845 std::cout << std::endl; 846 std::cout << "Mask 2 without excluded BaseObject:\n"; 847 TestClassTreeMask(test13_3); 848 test13_3.exclude(Class(BaseObject)); 849 std::cout << std::endl; 850 std::cout << "Mask 2 with BaseObject excluded afterwards:\n"; 851 TestClassTreeMask(test13_3); 852 853 ClassTreeMask test13_3_2; 854 test13_3_2.include(Class(A1)); 855 test13_3_2.exclude(Class(A1B2)); 856 test13_3_2.exclude(Class(A1B1C2)); 857 test13_3_2.include(Class(A2)); 858 test13_3_2.exclude(Class(A2B2)); 859 test13_3_2.include(Class(A3B1)); 860 test13_3_2.include(Class(A3B2)); 861 test13_3_2.exclude(Class(A3B2C2)); 862 test13_3_2.clean(); 863 test13_3_2.exclude(Class(BaseObject)); 864 std::cout << std::endl; 865 std::cout << "Mask 2 with BaseObject excluded afterwards, but cleaned before:\n"; 866 TestClassTreeMask(test13_3_2); 867 test13_3_2.include(Class(BaseObject)); 868 std::cout << std::endl; 869 std::cout << "Mask 2 from before, but BaseObject re-included without cleaning:\n"; 870 TestClassTreeMask(test13_3_2); 871 872 ClassTreeMask test13_4; 873 test13_4.include(Class(A3B2)); 874 test13_4.exclude(Class(A1B1C2)); 875 test13_4.include(Class(A3B1)); 876 test13_4.exclude(Class(A3B2C2)); 877 test13_4.exclude(Class(BaseObject)); 878 test13_4.include(Class(A2)); 879 test13_4.exclude(Class(A1B2)); 880 test13_4.exclude(Class(A2B2)); 881 test13_4.include(Class(A1)); 882 std::cout << std::endl; 883 std::cout << "Mask 2 created in random order:\n"; 884 TestClassTreeMask(test13_4); 885 886 std::cout << "2\n"; 887 888 ClassTreeMask test13_5 = test13_1; 889 std::cout << std::endl; 890 std::cout << "Mask 1 assigned to a new ClassTestMask:\n"; 891 TestClassTreeMask(test13_5); 892 893 std::cout << "3\n"; 894 895 ClassTreeMask test13_6 = !test13_1; 896 std::cout << std::endl; 897 std::cout << "Mask 1 inverted:\n"; 898 TestClassTreeMask(test13_6); 899 900 std::cout << "4\n"; 901 902 ClassTreeMask test13_7 = test13_1 + test13_2; 903 std::cout << std::endl; 904 std::cout << "Mask 1 + Mask 2:\n"; 905 TestClassTreeMask(test13_7); 906 907 std::cout << "5\n"; 908 909 ClassTreeMask test13_8 = test13_1 * test13_2; 910 std::cout << std::endl; 911 std::cout << "Mask 1 * Mask 2:\n"; 912 TestClassTreeMask(test13_8); 913 914 std::cout << "6\n"; 915 916 ClassTreeMask test13_9 = test13_1 - test13_2; 917 std::cout << std::endl; 918 std::cout << "Mask 1 - Mask 2:\n"; 919 TestClassTreeMask(test13_9); 920 921 std::cout << "7\n"; 922 923 ClassTreeMask test13_10 = test13_1 ^ test13_2; 924 std::cout << std::endl; 925 std::cout << "Mask 1 ^ Mask 2:\n"; 926 TestClassTreeMask(test13_10); 927 test13_10 = test13_10; 928 TestClassTreeMask(test13_10); 929 930 std::cout << "8\n"; 931 932 std::cout << std::endl; 933 ClassTreeMask test13_11(test13_1); 934 std::cout << std::endl; 935 std::cout << "Mask 1 assigned with copyconstructor + original mask 1:\n"; 936 TestClassTreeMask(test13_11); 831 937 TestClassTreeMask(test13_1); 938 939 ClassTreeMask test13_12(!test13_11); 940 std::cout << std::endl; 941 std::cout << "Mask 1 inverted assigned with copyconstructor + the original from before:\n"; 942 TestClassTreeMask(test13_12); 943 TestClassTreeMask(test13_11); 944 945 ClassTreeMask test13_13; 946 test13_13 = test13_2; 947 std::cout << std::endl; 948 std::cout << "Mask 2 assigned with = operator + original mask 2:\n"; 949 TestClassTreeMask(test13_13); 832 950 TestClassTreeMask(test13_2); 833 951 834 std::cout << "2\n"; 835 836 std::cout << "3\n"; 952 ClassTreeMask test13_14 = test13_11 + test13_13; 953 std::cout << std::endl; 954 std::cout << "Mask 1 + Mask 2 assigned with copyconstructor + originals from before:\n"; 955 TestClassTreeMask(test13_14); 956 TestClassTreeMask(test13_11); 957 TestClassTreeMask(test13_13); 958 959 test13_11 += test13_13; 960 std::cout << std::endl; 961 std::cout << "Mask 1 + Mask 2 with += operator + original of mask 2 from before:\n"; 962 TestClassTreeMask(test13_11); 963 TestClassTreeMask(test13_13); 964 965 std::cout << "9\n"; 837 966 838 967 // startRenderLoop(); -
code/branches/core/src/orxonox/core/ClassTreeMask.cc
r806 r807 88 88 ClassTreeMaskIterator::ClassTreeMaskIterator(ClassTreeMaskNode* node) 89 89 { 90 std::list<ClassTreeMaskNode*> templist; 91 std::list<ClassTreeMaskNode*>::iterator tempiterator = templist.insert(templist.end(), node); 92 this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(tempiterator, templist.end())); 90 std::list<ClassTreeMaskNode*>::iterator it = this->rootlist_.insert(this->rootlist_.end(), node); 91 this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(it, this->rootlist_.end())); 93 92 } 94 93 … … 157 156 { 158 157 this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true); 158 } 159 160 ClassTreeMask::ClassTreeMask(const ClassTreeMask& other) 161 { 162 this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true); 163 for (ClassTreeMaskIterator it = other.root_; it; ++it) 164 this->add(it->getClass(), it->isIncluded()); 159 165 } 160 166 … … 241 247 if (subclass->isA(node->getClass())) 242 248 { 243 //std::cout << "1_2\n";244 249 // Check for the special case 245 250 if (subclass == node->getClass()) 246 {247 //std::cout << "1_3\n";248 251 return node->isIncluded(); 249 } 250 251 //std::cout << "1_4\n"; 252 252 253 // Go through the list of subnodes and look for a node containing the searched subclass 253 254 for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); ++it) … … 255 256 return isIncluded(*it, subclass); 256 257 257 //std::cout << "1_5\n";258 258 // There is no subnode containing our class -> the rule of the current node takes in effect 259 259 return node->isIncluded(); … … 261 261 else 262 262 { 263 //std::cout << "1_6\n";264 263 // The class is not included in the mask: return false 265 264 return false; … … 285 284 node->subnodes_.insert(node->subnodes_.end(), (*it)->subnodes_.begin(), (*it)->subnodes_.end()); 286 285 (*it)->subnodes_.clear(); 287 node->subnodes_.erase(it++); 286 node->subnodes_.erase(it); 287 it = node->subnodes_.begin(); 288 288 } 289 289 else … … 294 294 } 295 295 296 ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other) 297 { 298 ClassTreeMask temp(other); 299 300 this->reset(); 301 302 for (ClassTreeMaskIterator it = temp.root_; it; ++it) 303 this->add(it->getClass(), it->isIncluded()); 304 305 return (*this); 306 } 307 308 ClassTreeMask& ClassTreeMask::operator+() 309 { 310 return (*this); 311 } 312 313 ClassTreeMask ClassTreeMask::operator-() const 314 { 315 return (!(*this)); 316 } 317 296 318 ClassTreeMask ClassTreeMask::operator+(const ClassTreeMask& other) const 297 319 { … … 330 352 } 331 353 354 ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const 355 { 356 return ((*this) * (!other)); 357 } 358 332 359 ClassTreeMask ClassTreeMask::operator!() const 333 360 { … … 338 365 newmask.add(subclass, !this->isIncluded(subclass)); 339 366 } 340 341 367 return newmask; 342 368 } 343 369 344 ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const 345 { 346 return ((*this) * (!other)); 370 ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other) 371 { 372 (*this) = (*this) + other; 373 return (*this); 374 } 375 376 ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other) 377 { 378 (*this) = (*this) * other; 379 return (*this); 380 } 381 382 ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other) 383 { 384 (*this) = (*this) - other; 385 return (*this); 347 386 } 348 387 … … 379 418 return (!(*this)); 380 419 } 420 421 ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other) 422 { 423 (*this) = (*this) & other; 424 return (*this); 425 } 426 427 ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other) 428 { 429 (*this) = (*this) | other; 430 return (*this); 431 } 432 433 ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other) 434 { 435 (*this) = (*this) ^ other; 436 return (*this); 437 } 438 439 std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask) 440 { 441 for (ClassTreeMaskIterator it = mask.root_; it; ++it) 442 { 443 if (it->isIncluded()) 444 out << "+"; 445 else 446 out << "-"; 447 448 out << it->getClass()->getName() << " "; 449 } 450 451 return out; 452 } 381 453 } -
code/branches/core/src/orxonox/core/ClassTreeMask.h
r803 r807 77 77 private: 78 78 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; 79 std::list<ClassTreeMaskNode*> rootlist_; 79 80 }; 80 81 … … 83 84 public: 84 85 ClassTreeMask(); 86 ClassTreeMask(const ClassTreeMask& other); 85 87 ~ClassTreeMask(); 86 88 … … 94 96 bool isExcluded(const Identifier* subclass) const; 95 97 98 ClassTreeMask& operator=(const ClassTreeMask& other); 99 100 ClassTreeMask& operator+(); 101 ClassTreeMask operator-() const; 102 96 103 ClassTreeMask operator+(const ClassTreeMask& other) const; 97 104 ClassTreeMask operator*(const ClassTreeMask& other) const; 105 ClassTreeMask operator-(const ClassTreeMask& other) const; 98 106 ClassTreeMask operator!() const; 99 ClassTreeMask operator-(const ClassTreeMask& other) const; 107 108 ClassTreeMask& operator+=(const ClassTreeMask& other); 109 ClassTreeMask& operator*=(const ClassTreeMask& other); 110 ClassTreeMask& operator-=(const ClassTreeMask& other); 100 111 101 112 ClassTreeMask operator&(const ClassTreeMask& other) const; … … 103 114 ClassTreeMask operator^(const ClassTreeMask& other) const; 104 115 ClassTreeMask operator~() const; 116 117 ClassTreeMask& operator&=(const ClassTreeMask& other); 118 ClassTreeMask& operator|=(const ClassTreeMask& other); 119 ClassTreeMask& operator^=(const ClassTreeMask& other); 120 121 friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask); 105 122 106 123 private:
Note: See TracChangeset
for help on using the changeset viewer.