File indexing completed on 2025-01-18 10:01:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef HEPMC3_ATTRIBUTE_FEATURE_H
0013 #define HEPMC3_ATTRIBUTE_FEATURE_H
0014
0015 #include <memory>
0016 #include <string>
0017 #include "HepMC3/Attribute.h"
0018 #include "HepMC3/Filter.h"
0019
0020 namespace HepMC3 {
0021
0022 class AttributeFeature {
0023 public:
0024
0025 AttributeFeature(const std::string &name): m_name(name) {}
0026
0027
0028 Filter exists() const {
0029 std::string name = m_name;
0030 return [name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).length() != 0;};
0031 }
0032
0033
0034 bool operator()(ConstGenParticlePtr p) const {
0035 return p->attribute_as_string(m_name).length() != 0;
0036 }
0037
0038
0039 Filter operator == (const Attribute &rhs) const {
0040 std::string name = m_name;
0041 std::string other;
0042 rhs.to_string(other);
0043 return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
0044 }
0045
0046
0047 Filter operator == (std::shared_ptr<const Attribute> rhs) const {
0048 std::string name = m_name;
0049 std::string other;
0050 rhs->to_string(other);
0051 return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
0052 }
0053
0054
0055 Filter operator == (std::string rhs) const {
0056 const std::string &name = m_name;
0057 return [name, rhs](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(rhs) == 0;};
0058 }
0059
0060 private:
0061 std::string m_name;
0062 };
0063 }
0064 #endif