00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkNodePredicateAnd.h" 00019 00020 00021 mitk::NodePredicateAnd::NodePredicateAnd() 00022 : NodePredicateCompositeBase() 00023 { 00024 } 00025 00026 00027 mitk::NodePredicateAnd::NodePredicateAnd(const NodePredicateBase* p1, const NodePredicateBase* p2) 00028 : NodePredicateCompositeBase() 00029 { 00030 this->AddPredicate(p1); 00031 this->AddPredicate(p2); 00032 } 00033 00034 00035 mitk::NodePredicateAnd::NodePredicateAnd(const NodePredicateBase* p1, const NodePredicateBase* p2, const NodePredicateBase* p3) 00036 : NodePredicateCompositeBase() 00037 { 00038 this->AddPredicate(p1); 00039 this->AddPredicate(p2); 00040 this->AddPredicate(p3); 00041 } 00042 00043 00044 mitk::NodePredicateAnd::~NodePredicateAnd() 00045 { 00046 } 00047 00048 00049 bool mitk::NodePredicateAnd::CheckNode(const mitk::DataNode* node) const 00050 { 00051 if (m_ChildPredicates.empty()) 00052 throw std::invalid_argument("NodePredicateAnd: no child predicates available"); 00053 00054 if (node == NULL) 00055 throw std::invalid_argument("NodePredicateAnd: invalid node"); 00056 00057 // return the conjunction of the child predicate. If any predicate returns false, we return false too 00058 for (ChildPredicates::const_iterator it = m_ChildPredicates.begin(); ( it != m_ChildPredicates.end() ); ++it) 00059 if ((*it)->CheckNode(node) == false) 00060 return false; // if one element of the conjunction is false, the whole conjunction gets false 00061 return true; // none of the childs was false, so return true 00062 }