HepMC3 event record library
FilterAttribute.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5 //
6 #ifndef HEPMC3_SEARCH_FILTEATTRIBUTE_H
7 #define HEPMC3_SEARCH_FILTEATTRIBUTE_H
8 ///
9 /// @file FilterAttribute.h
10 /// @brief Definition of \b class ATTRIBUTE
11 ///
12 /// @class HepMC3::ATTRIBUTE
13 /// @brief Filter for the attributes
14 ///
15 /// Used to construct filters that can check if an attribute exists
16 /// or to compare against other attribute. See @ref searchengine for details
17 /// and examples of its use.
18 ///
19 /// @ingroup searchengine
20 #include "HepMC3/Filter.h"
21 #include "HepMC3/Attribute.h"
22 #include <string>
23 
24 namespace HepMC3 {
25 /** Deprecated */
26 using std::string;
27 
28 class ATTRIBUTE : public Filter {
29 //
30 // Constructors
31 //
32 public:
33  /// @brief Default constructor
34  ///
35  /// Provides the name of the attribute used in by the filter
36  ATTRIBUTE(const std::string &name):Filter(ATTRIBUTE_EXISTS,name) {}
37 
38 //
39 // Operators
40 //
41 public:
42 
43  /// @brief Compare if this attribute is equal to other attribute
44  Filter& operator==( std::shared_ptr<Attribute> &at ) {
45  m_attribute = ATTRIBUTE_IS_EQUAL;
46  at->to_string(m_attribute_str);
47  return *this;
48  }
49 
50  /// @brief Compare if this attribute is not equal to other attribute
51  Filter& operator!=( std::shared_ptr<Attribute> &at ) {
52  m_bool_value = !m_bool_value;
53  m_attribute = ATTRIBUTE_IS_EQUAL;
54  at->to_string(m_attribute_str);
55  return *this;
56  }
57 
58  /// @brief Compare if string version of this attribute is equal value
59  Filter& operator==( const std::string &value ) {
60  m_attribute = ATTRIBUTE_IS_EQUAL;
61  m_attribute_str = value;
62  return *this;
63  }
64 
65  /// @brief Compare if string version of this attribute is not equal value
66  Filter& operator!=( const std::string &value ) {
67  m_bool_value = !m_bool_value;
68  m_attribute = ATTRIBUTE_IS_EQUAL;
69  m_attribute_str = value;
70  return *this;
71  }
72 
73  /// @brief Negate logic of the result (eg. check if attribute does not exist)
75  m_bool_value = !m_bool_value;
76  return *this;
77  }
78 };
79 
80 } // namespace HepMC3
81 
82 #endif
Filter & operator!()
Negate logic of the result (eg. check if attribute does not exist)
Filter & operator!=(std::shared_ptr< Attribute > &at)
Compare if this attribute is not equal to other attribute.
ATTRIBUTE(const std::string &name)
Default constructor.
Filter & operator!=(const std::string &value)
Compare if string version of this attribute is not equal value.
Defines Filter operations for combingin Filters.
Filter for the attributes.
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition: Filter.h:17
Filter & operator==(const std::string &value)
Compare if string version of this attribute is equal value.
Annotation for function names.
Definition: attr.h:36
Definition of class Attribute, class IntAttribute and class StringAttribute.
Filter & operator==(std::shared_ptr< Attribute > &at)
Compare if this attribute is equal to other attribute.