HepMC3 event record library
AttributeFeature.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2021 The HepMC collaboration (see AUTHORS for details)
5 //
6 ///
7 /// @file AttributeFeature.h
8 /// @brief Defines AttributeFeature for obtaining Filters to search by Attribute.
9 /// @class HepMC3::AttributeFeature
10 /// @brief AttributeFeature
11 
12 #ifndef HEPMC3_ATTRIBUTE_FEATURE_H
13 #define HEPMC3_ATTRIBUTE_FEATURE_H
14 
15 #include <memory>
16 #include <string>
17 #include "HepMC3/Attribute.h"
18 #include "HepMC3/Filter.h"
19 
20 namespace HepMC3 {
21 
23 public:
24  /// @brief constructor
25  AttributeFeature(const std::string &name): m_name(name) {}
26 
27  /// @brief existence
28  Filter exists() const {
29  std::string name = m_name;
30  return [name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).length() != 0;};
31  }
32 
33  /// @brief evaluate
34  bool operator()(ConstGenParticlePtr p) const {
35  return p->attribute_as_string(m_name).length() != 0;
36  }
37 
38  /// @brief equality operator
39  Filter operator == (const Attribute &rhs) const {
40  std::string name = m_name;
41  std::string other;
42  rhs.to_string(other);
43  return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
44  }
45 
46  /// @brief equality operator
47  Filter operator == (std::shared_ptr<const Attribute> rhs) const {
48  std::string name = m_name;
49  std::string other;
50  rhs->to_string(other);
51  return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
52  }
53 
54  /// @brief equality operator
55  Filter operator == (std::string rhs) const {
56  const std::string &name = m_name;
57  return [name, rhs](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(rhs) == 0;};
58  }
59 
60 private:
61  std::string m_name; ///< holds name
62 };
63 }
64 #endif
Definition of class Attribute, class IntAttribute and class StringAttribute.
Defines Filter operations for combingin Filters.
Filter exists() const
existence
bool operator()(ConstGenParticlePtr p) const
evaluate
AttributeFeature(const std::string &name)
constructor
Filter operator==(const Attribute &rhs) const
equality operator
std::string m_name
holds name
Base attribute class.
Definition: Attribute.h:44
virtual bool to_string(std::string &att) const =0
Fill string from class content.
HepMC3 main namespace.
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition: Filter.h:19