MarlinMT  0.1.0
Selection.cc
Go to the documentation of this file.
2 
3 // -- MarlinBook includes
5 
6 namespace marlinmt {
7  namespace book {
8  WeakEntry::WeakEntry( const std::shared_ptr< const details::Entry > &entry )
9  : _entry{entry}{}
10 
11  WeakEntry::WeakEntry( const std::shared_ptr< details::Entry > &entry )
12  : _entry{entry}{}
13 
14  bool WeakEntry::valid() const {
15  return !_entry.expired() && _entry.lock()->valid();
16  }
17 
18  const EntryKey& WeakEntry::key() const {
19  return _entry.lock()->key() ;
20  }
21 
22  const Condition& Selection::condition() const { return _condition; }
23 
24 
26  return const_iterator( _entries.cbegin() ) ;
27  }
28 
30  return const_iterator( _entries.cend() ) ;
31  }
32 
33  std::size_t Selection::size() const { return _entries.size(); }
34 
36  const Condition &cond,
37  ComposeStrategy strategy )
38  : Selection{find( sel.begin(), sel.end(), cond )} {
39  switch ( strategy ) {
41  _condition = sel.condition() & cond ;
42  break ;
44  _condition = cond ;
45  break ;
47  _condition = sel.condition() ;
48  break ;
49  default:
50  MARLIN_BOOK_THROW( "Condition compose strategy is not defined." ) ;
51  }
52  }
53 
55  ComposeStrategy strategy ) {
56  return Selection( *this, cond, strategy ) ;
57  }
58 
59  //--------------------------------------------------------------------------
60 
61  void Selection::remove( std::size_t id ) {
62  _entries.erase( _entries.cbegin() + id ) ;
63  }
64 
65  //--------------------------------------------------------------------------
66 
67  void Selection::remove( std::size_t id, std::size_t n ) {
68  auto beg = _entries.cbegin() + id ;
69  _entries.erase( beg, beg + n ) ;
70  }
71 
72  //--------------------------------------------------------------------------
73 
74  void Selection::remove( const const_iterator &itr ) {
75  _entries.erase( itr ) ;
76  }
77 
78  //--------------------------------------------------------------------------
79 
81  const const_iterator &end ) {
82  _entries.erase( begin, end ) ;
83  }
84 
85  //--------------------------------------------------------------------------
86 
90  const Condition & cond ) ;
91 
92  } // end namespace book
93 } // end namespace marlinmt
Data selection to identify and manage an Entry.
Definition: EntryData.h:21
typename std::vector< WeakEntry >::const_iterator const_iterator
random access const_iterator for Selections.
Definition: Selection.h:100
std::size_t size() const
Definition: Selection.cc:33
std::vector< WeakEntry > _entries
entries which included in selection.
Definition: Selection.h:183
bool valid() const
check if WeakEntry is usable.
Definition: Selection.cc:14
const EntryKey & key() const
get key from Entry.
Definition: Selection.cc:18
std::weak_ptr< const details::Entry > _entry
wake reference to Entry
Definition: Selection.h:67
const_iterator begin() const
begin iterator to iterate through entries.
Definition: Selection.cc:25
void remove(std::size_t i)
remove entry at position.
Definition: Selection.cc:61
#define MARLIN_BOOK_THROW(message)
Definition: Types.h:10
Selection()=default
default constructor. Construct empty selection.
static Selection find(T begin, T end, const Condition &cond)
Construct Selection from range of Entries.
Definition: Selection.h:191
const_iterator end() const
end iterator for entries. First not valid iterator.
Definition: Selection.cc:29
template Selection Selection::find< Selection::const_iterator >(Selection::const_iterator begin, Selection::const_iterator end, const Condition &cond)
const Condition & condition() const
getter for Condition which every Entry full fill.
Definition: Selection.cc:22
Contains references to entries.
Definition: Selection.h:75
Condition _condition
condition which every entry fulfill.
Definition: Selection.h:185
ComposeStrategy
Possibilities to compose Conditions when creating sub selections.
Definition: Selection.h:105
wrapper class for an Entry filter function.
Definition: Condition.h:21