CompositeSelection.h 3.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef COOLKERNEL_COMPOSITESELECTION_H
#define COOLKERNEL_COMPOSITESELECTION_H 1

// First of all, set/unset CORAL290, COOL300, COOL400 and COOL_HAS_CPP11 macros
#include "CoolKernel/VersionInfo.h"

// Include files
#ifdef COOL400CPP11ENUM
#include <ostream>
#endif
#include <vector>
#include "CoolKernel/IRecordSelection.h"

namespace cool
{

  //--------------------------------------------------------------------------

  /** @class CompositeSelection CompositeSelection.h
   *
   *  Composite selection on a data record obtained by the conjuction (AND)
   *  or disjunction (OR) of several simplere record selections.
   *
   *  @author Andrea Valassi and Martin Wache
   *  @date   2008-07-30
   *///

  class CompositeSelection : virtual public IRecordSelection
  {

  public:

    /// Logical connectives (logical operations).
#ifndef COOL400CPP11ENUM
    enum Connective { AND, OR };
#else
    enum class Connective { AND, OR };

    // Overloaded operator<< for cool::CompositeSelection::Connective
    inline friend std::ostream&
    operator<<( std::ostream& s, const cool::CompositeSelection::Connective& c )
    {
      return s << (int)c;
    }
#endif

    /// Describe a logical connective.
    static const std::string describe( Connective conn );

  public:

    /// Destructor.
    virtual ~CompositeSelection();

    /// Constructor for connecting two selections.
    /// Each input selection is cloned (the clone is owned by this instance).
    CompositeSelection( const IRecordSelection* sel1,
                        Connective conn,
                        const IRecordSelection* sel2 );

    /// Constructor for connecting any number of selections.
    /// The vector must contain at least two selections.
    /// Each input selection is cloned (the clone is owned by this instance).
    CompositeSelection( Connective conn,
                        const std::vector<const IRecordSelection*>& selVec );

    /// Connect another selection.
    /// The input selection is cloned (the clone is owned by this instance).
    void connect( Connective conn,
                  const IRecordSelection* sel );

    /// Can the selection be applied to a record with the given specification?
    bool canSelect( const IRecordSpecification& spec ) const;

    /// Apply the selection to the given record.
    bool select( const IRecord& record ) const;

    /// Clone the record selection (and any objects referenced therein).
    IRecordSelection* clone() const;

    /// Logical connective between all connected selections.
    Connective connective() const;

    /// The number N of connected selections.
    unsigned int size() const;

    /// Return one of the connected selections by its index in [0, N-1].
    const IRecordSelection* operator[] ( unsigned int index ) const;

  private:

    /// Standard constuctor is private
    CompositeSelection();

    /// Copy constructor - reimplemented for the clone() method
    CompositeSelection( const CompositeSelection& rhs );

    /// Assignment operator is private
    CompositeSelection& operator=( const CompositeSelection& rhs );

    /// Constructor with a default connective and no selections - for connect()
    CompositeSelection( Connective conn );

  private:

    /// The logical connective between connected selections.
    Connective m_conn;

    /// The vector of connected selections.
    /// These are clones (owned by this instance) of the user-given selections.
    std::vector<IRecordSelection*> m_selVec;

  };

}
#endif // COOLKERNEL_COMPOSITESELECTION_H