HepMC3 event record library: FilterAttribute.h Source File

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-2023 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.
17///
18/// @ingroup searchengine
19#include <string>
20#include <memory>
21#include "HepMC3/Filter.h"
22#include "HepMC3/Attribute.h"
23
24namespace HepMC3 {
25/** Deprecated */
26using std::string;
27
28 class ATTRIBUTE : public Filter {
29//
30// Constructors
31//
32public:
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//
41public:
42 /// @brief Compare if this attribute is equal to other attribute
43 Filter& operator==(std::shared_ptr<Attribute> &at) {
44 m_attribute = ATTRIBUTE_IS_EQUAL;
45 at->to_string(m_attribute_str);
46 return *this;
47 }
48
49 /// @brief Compare if this attribute is not equal to other attribute
50 Filter& operator!=(std::shared_ptr<Attribute> &at) {
51 m_bool_value = !m_bool_value;
52 m_attribute = ATTRIBUTE_IS_EQUAL;
53 at->to_string(m_attribute_str);
54 return *this;
55 }
56
57 /// @brief Compare if string version of this attribute is equal value
58 Filter& operator==(const std::string &value) {
59 m_attribute = ATTRIBUTE_IS_EQUAL;
60 m_attribute_str = value;
61 return *this;
62 }
63
64 /// @brief Compare if string version of this attribute is not equal value
65 Filter& operator!=(const std::string &value) {
66 m_bool_value = !m_bool_value;
67 m_attribute = ATTRIBUTE_IS_EQUAL;
68 m_attribute_str = value;
69 return *this;
70 }
71
72 /// @brief Negate logic of the result (eg. check if attribute does not exist)
73 Filter& operator!() {
74 m_bool_value = !m_bool_value;
75 return *this;
76 }
77};
78
79} // namespace HepMC3
80
81#endif
Attribute.h
Definition of class Attribute, class IntAttribute and class StringAttribute.
Filter.h
Defines Filter operations for combingin Filters.
HepMC3::ATTRIBUTE::ATTRIBUTE
ATTRIBUTE(const std::string &name)
Default constructor.
Definition FilterAttribute.h:36
HepMC3::ATTRIBUTE::operator!
Filter & operator!()
Negate logic of the result (eg. check if attribute does not exist).
Definition FilterAttribute.h:73
HepMC3::ATTRIBUTE::operator==
Filter & operator==(std::shared_ptr< Attribute > &at)
Compare if this attribute is equal to other attribute.
Definition FilterAttribute.h:43
HepMC3::ATTRIBUTE::operator==
Filter & operator==(const std::string &value)
Compare if string version of this attribute is equal value.
Definition FilterAttribute.h:58
HepMC3::ATTRIBUTE::operator!=
Filter & operator!=(const std::string &value)
Compare if string version of this attribute is not equal value.
Definition FilterAttribute.h:65
HepMC3::ATTRIBUTE::operator!=
Filter & operator!=(std::shared_ptr< Attribute > &at)
Compare if this attribute is not equal to other attribute.
Definition FilterAttribute.h:50
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24
HepMC3::Filter
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition Filter.h:19