selxComponentSelector.cxx 3 KB
Newer Older
1
2
/*=========================================================================
 *
3
 *  Copyright Leiden University Medical Center, Erasmus University Medical
Floris Berendsen's avatar
Floris Berendsen committed
4
 *  Center and contributors
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
19
20
//#ifndef ComponentSelector_hxx
//#define ComponentSelector_hxx
21

22
#include "selxComponentSelector.h"
23

Floris Berendsen's avatar
Floris Berendsen committed
24
namespace selx
25
{
Floris Berendsen's avatar
Floris Berendsen committed
26
ComponentSelector::ComponentSelector()
27
28
29
{
  std::list< itk::LightObject::Pointer > allobjects
    = itk::ObjectFactoryBase::CreateAllInstance( "ComponentBase" );
30

31
32
33
34
35
36
  for( std::list< itk::LightObject::Pointer >::iterator i = allobjects.begin();
    i != allobjects.end(); ++i )
  {
    ComponentBase * io
      = dynamic_cast< ComponentBase * >( i->GetPointer() );
    if( io )
37
    {
38
      this->m_PossibleComponents.push_back( io );
39
    }
40
  }
41
42
43
}


44
ComponentSelector::~ComponentSelector()
45
46
{
}
47

48
49
50

void
ComponentSelector::AddCriterion( const CriterionType & criterion )
51
{
52
53
54
  this->m_PossibleComponents.remove_if([ & ]( ComponentBasePointer component ){
      return !component->MeetsCriterionBase( criterion );
    } );
55
56
}

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
void
ComponentSelector::AddAcceptingInterfaceCriteria(const InterfaceCriteriaType & interfaceCriteria)
{
  this->m_PossibleComponents.remove_if([&](ComponentBasePointer component){
    return 0==component->CountAcceptingInterfaces(interfaceCriteria);
  });
}

void
ComponentSelector::AddProvidingInterfaceCriteria(const InterfaceCriteriaType & interfaceCriteria)
{
  this->m_PossibleComponents.remove_if([&](ComponentBasePointer component){
    return 0 == component->CountProvidingInterfaces(interfaceCriteria);
  });
}

73
74
// CompatibleInterfaces
unsigned int ComponentSelector::RequireAcceptInterfaceFrom(ComponentBasePointer other, const InterfaceCriteriaType & interfaceCriteria)
75
{
76
77
  this->m_PossibleComponents.remove_if([&](ComponentBasePointer component){auto status = component->CanAcceptConnectionFrom(other, interfaceCriteria);
    return status == ComponentBase::interfaceStatus::noaccepter || status == ComponentBase::interfaceStatus::noprovider;
78
  });
79
  return 0;
80
}
81

82
83
ComponentSelector::ComponentBasePointer
ComponentSelector::GetComponent()
84
85
{
  //TODO check if Modified
86
  //this->UpdatePossibleComponents();
87

88
  if( this->m_PossibleComponents.size() == 1 )
89
  {
90
    return *( this->m_PossibleComponents.begin() );
91
92
93
94
95
  }
  else
  {
    return ITK_NULLPTR;
  }
96
}
97

98
99
100

bool
ComponentSelector::HasMultipleComponents()
101
{
102
  return ( this->m_PossibleComponents.size() > 1 );
103
}
Floris Berendsen's avatar
Floris Berendsen committed
104
} // end namespace selx
105

106
//#endif