Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:11

0001 // -*- C++ -*-
0002 //
0003 // This file is part of HepMC
0004 // Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
0005 //
0006 #ifndef HEPMC3_ATTRIBUTE_H
0007 #define HEPMC3_ATTRIBUTE_H
0008 /**
0009  *  @file Attribute.h
0010  *  @brief Definition of \b class Attribute, \b class IntAttribute and \b class StringAttribute
0011  *
0012  *  @class HepMC3::Attribute
0013  *  @brief Base class for all attributes
0014  *
0015  *  Contains virtual functions to_string and from_string that
0016  *  each attribute must implement, as well as init function that
0017  *  attributes should overload to initialize parsed attribute
0018  *
0019  *  @ingroup attributes
0020  *
0021  */
0022 #include <cstdio> // sprintf
0023 #include <string>
0024 #include <limits>
0025 #include <sstream>
0026 #include <iomanip>
0027 #include <map>
0028 
0029 #include "HepMC3/GenParticle_fwd.h"
0030 #include "HepMC3/GenVertex_fwd.h"
0031 
0032 /** Deprecated */
0033 using std::string;
0034 
0035 namespace HepMC3 {
0036 
0037 /** @brief Forward declaration of GenEvent. */
0038 class GenEvent;
0039 
0040 /** @brief Forward declaration of GenRunInfo. */
0041 class GenRunInfo;
0042 
0043 /** @brief  Base attribute class. */
0044 class Attribute {
0045 //
0046 // Constructors
0047 //
0048 public:
0049     /** @brief Default constructor */
0050     //Note: m_event should be set to nullptr in case event is deleted!
0051     Attribute():m_is_parsed(true) {    m_event=nullptr; }
0052 
0053     /** @brief Virtual destructor */
0054     virtual ~Attribute() {}
0055 
0056 protected:
0057     /** @brief Protected constructor that allows to set string
0058      *
0059      *  Used when parsing attributes from file. An StringAttribute class
0060      *  object is made, which uses this constructor to signify that
0061      *  it just holds string without parsing it.
0062      *
0063      *  @note There should be no need for user class to ever use this constructor
0064      */
0065     //Note: m_event should be set to nullptr n case event is deleted!
0066     explicit Attribute(const std::string &st):m_is_parsed(false),m_string(st) { m_event=nullptr; }
0067 
0068     /** @brief GenEvent is a friend */
0069     friend class GenEvent;
0070 
0071 //
0072 // Virtual Functions
0073 //
0074 public:
0075     /** @brief Fill class content from string.
0076      */
0077     virtual bool from_string(const std::string & att) = 0;
0078 
0079     /** @brief Optionally initialize the attribute after from_string.
0080      */
0081     virtual bool init() {
0082         return true;
0083     }
0084 
0085     /** @brief Optionally initialize the attribute after from_string
0086      *
0087      * Is passed a reference to the GenRunInfo object to which the
0088      * Attribute belongs.
0089      */
0090     virtual bool init(const GenRunInfo & ) {
0091         return true;
0092     }
0093 
0094     /** @brief Fill string from class content */
0095     virtual bool to_string(std::string &att) const = 0;
0096 
0097 //
0098 // Accessors
0099 //
0100 public:
0101     /** @brief Check if this attribute is parsed */
0102     bool is_parsed() const { return m_is_parsed; }
0103 
0104     /** @brief Get unparsed string */
0105     const std::string& unparsed_string() const { return m_string; }
0106 
0107     /** return the GenEvent to which this Attribute belongs, if at all. */
0108     const GenEvent * event() const {
0109         return m_event;
0110     }
0111 
0112     /** return the GenParticle to which this Attribute belongs, if at all. */
0113     GenParticlePtr particle() {
0114         return m_particle;
0115     }
0116 
0117     /** return the GenParticle to which this Attribute belongs, if at all. */
0118     ConstGenParticlePtr particle() const {
0119         return std::const_pointer_cast<GenParticle>(m_particle);
0120     }
0121 
0122     /** return the GenVertex to which this Attribute belongs, if at all. */
0123     GenVertexPtr vertex() {
0124         return m_vertex;
0125     }
0126 
0127     /** return the GenVertex to which this Attribute belongs, if at all. */
0128     ConstGenVertexPtr vertex() const {
0129         return std::const_pointer_cast<GenVertex>(m_vertex);
0130     }
0131 
0132 protected:
0133     /** @brief Set is_parsed flag */
0134     void set_is_parsed(bool flag) { m_is_parsed = flag; }
0135 
0136     /** @brief Set unparsed string */
0137     void set_unparsed_string(const std::string &st) { m_string = st; }
0138 
0139 //
0140 // Fields
0141 //
0142 private:
0143     bool   m_is_parsed;             //!< Is this attribute parsed?
0144     std::string m_string;                //!< Raw (unparsed) string
0145     const GenEvent * m_event;       //!< Possibility to be aware of the
0146     //!  controlling GenEvent object.
0147     GenParticlePtr m_particle; //!< Particle to which assigned.
0148     GenVertexPtr m_vertex;      //!< Vertex to which assigned.
0149 };
0150 
0151 /**
0152  *  @class HepMC3::IntAttribute
0153  *  @brief Attribute that holds an Integer implemented as an int
0154  *
0155  *  @ingroup attributes
0156  */
0157 class IntAttribute : public Attribute {
0158 public:
0159 
0160     /** @brief Default constructor */
0161     IntAttribute():Attribute(),m_val(0) {}
0162 
0163     /** @brief Constructor initializing attribute value */
0164     IntAttribute(int val):Attribute(),m_val(val) {}
0165 
0166     /** @brief Implementation of Attribute::from_string */
0167     bool from_string(const std::string &att) override {
0168         m_val = atoi( att.c_str() );
0169         set_is_parsed(true);
0170         return true;
0171     }
0172 
0173     /** @brief Implementation of Attribute::to_string */
0174     bool to_string(std::string &att) const  override {
0175         att = std::to_string(m_val);
0176         return true;
0177     }
0178 
0179     /** @brief get the value associated to this Attribute. */
0180     int value() const {
0181         return m_val;
0182     }
0183 
0184     /** @brief set the value associated to this Attribute. */
0185     void set_value(const int& i) {
0186         m_val = i;
0187         set_is_parsed(true);
0188     }
0189 
0190 private:
0191     int m_val; ///< Attribute value
0192 };
0193 
0194 /**
0195  *  @class HepMC3::LongAttribute
0196  *  @brief Attribute that holds an Integer implemented as a long int
0197  *
0198  *  @ingroup attributes
0199  */
0200 class LongAttribute : public Attribute {
0201 public:
0202 
0203     /** @brief Default constructor */
0204     LongAttribute(): Attribute(), m_val(0) {}
0205 
0206     /** @brief Constructor initializing attribute value */
0207     LongAttribute(long val): Attribute(), m_val(val) {}
0208 
0209     /** @brief Implementation of Attribute::from_string */
0210     bool from_string(const std::string &att)  override {
0211         m_val = atol( att.c_str() );
0212         set_is_parsed(true);
0213         return true;
0214     }
0215 
0216     /** @brief Implementation of Attribute::to_string */
0217     bool to_string(std::string &att) const  override {
0218         att = std::to_string(m_val);
0219         return true;
0220     }
0221 
0222     /** @brief get the value associated to this Attribute. */
0223     long value() const {
0224         return m_val;
0225     }
0226 
0227     /** @brief set the value associated to this Attribute. */
0228     void set_value(const long& l) {
0229         m_val = l;
0230         set_is_parsed(true);
0231     }
0232 
0233 private:
0234 
0235     long m_val; ///< Attribute value
0236 
0237 };
0238 
0239 /**
0240  *  @class HepMC3::DoubleAttribute
0241  *  @brief Attribute that holds a real number as a double.
0242  *
0243  *  @ingroup attributes
0244  */
0245 class DoubleAttribute : public Attribute {
0246 public:
0247 
0248     /** @brief Default constructor */
0249     DoubleAttribute(): Attribute(), m_val(0.0) {}
0250 
0251     /** @brief Constructor initializing attribute value */
0252     DoubleAttribute(double val): Attribute(), m_val(val) {}
0253 
0254     /** @brief Implementation of Attribute::from_string */
0255     bool from_string(const std::string &att)  override {
0256         m_val = atof( att.c_str() );
0257         set_is_parsed(true);
0258         return true;
0259     }
0260 
0261     /** @brief Implementation of Attribute::to_string */
0262     bool to_string(std::string &att) const  override {
0263         std::ostringstream oss;
0264         oss << std::setprecision(std::numeric_limits<double>::digits10)
0265             << m_val;
0266         att = oss.str();
0267         return true;
0268     }
0269 
0270     /** @brief get the value associated to this Attribute. */
0271     double value() const {
0272         return m_val;
0273     }
0274 
0275     /** @brief set the value associated to this Attribute. */
0276     void set_value(const double& d) {
0277         m_val = d;
0278         set_is_parsed(true);
0279     }
0280 
0281 private:
0282 
0283     double m_val; ///< Attribute value
0284 };
0285 
0286 /**
0287  *  @class HepMC3::FloatAttribute
0288  *  @brief Attribute that holds a real number as a float.
0289  *
0290  *  @ingroup attributes
0291  */
0292 class FloatAttribute : public Attribute {
0293 public:
0294 
0295     /** @brief Default constructor */
0296     FloatAttribute(): Attribute(), m_val(0.0) {}
0297 
0298     /** @brief Constructor initializing attribute value */
0299     FloatAttribute(float val): Attribute(), m_val(val) {}
0300 
0301     /** @brief Implementation of Attribute::from_string */
0302     bool from_string(const std::string &att)  override {
0303         m_val = float(atof( att.c_str() ));
0304         set_is_parsed(true);
0305         return true;
0306     }
0307 
0308     /** @brief Implementation of Attribute::to_string */
0309     bool to_string(std::string &att) const  override {
0310         std::ostringstream oss;
0311         oss << std::setprecision(std::numeric_limits<float>::digits10)
0312             << m_val;
0313         att = oss.str();
0314         return true;
0315     }
0316 
0317     /** @brief get the value associated to this Attribute. */
0318     float value() const {
0319         return m_val;
0320     }
0321 
0322     /** @brief set the value associated to this Attribute. */
0323     void set_value(const float& f) {
0324         m_val = f;
0325         set_is_parsed(true);
0326     }
0327 
0328 private:
0329 
0330     float m_val; ///< Attribute value
0331 };
0332 
0333 /**
0334  *  @class HepMC3::StringAttribute
0335  *  @brief Attribute that holds a string
0336  *
0337  *  Default attribute constructed when reading input files.
0338  *  It can be then parsed by other attributes or left as a string.
0339  *
0340  *  @ingroup attributes
0341  *
0342  */
0343 class StringAttribute : public Attribute {
0344 public:
0345 
0346     /** @brief Default constructor - empty string */
0347     StringAttribute():Attribute() {}
0348 
0349     /** @brief String-based constructor
0350      *
0351      *  The Attribute constructor used here marks that this is an unparsed
0352      *  string that can be (but does not have to be) parsed
0353      *
0354      */
0355     StringAttribute(const std::string &st):Attribute(st) {}
0356 
0357     /** @brief Implementation of Attribute::from_string */
0358     bool from_string(const std::string &att)  override {
0359         set_unparsed_string(att);
0360         return true;
0361     }
0362 
0363     /** @brief Implementation of Attribute::to_string */
0364     bool to_string(std::string &att) const  override {
0365         att = unparsed_string();
0366         return true;
0367     }
0368 
0369     /** @brief get the value associated to this Attribute. */
0370     std::string value() const {
0371         return unparsed_string();
0372     }
0373 
0374     /** @brief set the value associated to this Attribute. */
0375     void set_value(const std::string& s) {
0376         set_unparsed_string(s);
0377     }
0378 
0379 };
0380 
0381 /**
0382  *  @class HepMC3::CharAttribute
0383  *  @brief Attribute that holds an Character implemented as an int
0384  *
0385  *  @ingroup attributes
0386  */
0387 class CharAttribute : public Attribute {
0388 public:
0389 
0390     /** @brief Default constructor */
0391     CharAttribute():Attribute(),m_val(0) {}
0392 
0393     /** @brief Constructor initializing attribute value */
0394     CharAttribute(char val):Attribute(),m_val(val) {}
0395 
0396     /** @brief Implementation of Attribute::from_string */
0397     bool from_string(const std::string &att) override {
0398         set_is_parsed(true);
0399         if (att.size())
0400         {
0401             m_val = att.at(0);
0402             return true;
0403         }
0404         return false;
0405     }
0406 
0407     /** @brief Implementation of Attribute::to_string */
0408     bool to_string(std::string &att) const override {
0409         att = std::to_string(m_val);
0410         return true;
0411     }
0412 
0413     /** @brief get the value associated to this Attribute. */
0414     char value() const {
0415         return m_val;
0416     }
0417 
0418     /** @brief set the value associated to this Attribute. */
0419     void set_value(const char& i) {
0420         m_val = i;
0421         set_is_parsed(true);
0422     }
0423 
0424 private:
0425     char m_val; ///< Attribute value
0426 };
0427 
0428 /**
0429  *  @class HepMC3::LongLongAttribute
0430  *  @brief Attribute that holds an Integer implemented as a long long int
0431  *
0432  *  @ingroup attributes
0433  */
0434 class LongLongAttribute : public Attribute {
0435 public:
0436 
0437     /** @brief Default constructor */
0438     LongLongAttribute(): Attribute(), m_val(0) {}
0439 
0440     /** @brief Constructor initializing attribute value */
0441     LongLongAttribute(long long val): Attribute(), m_val(val) {}
0442 
0443     /** @brief Implementation of Attribute::from_string */
0444     bool from_string(const std::string &att)  override {
0445         m_val = atoll( att.c_str() );
0446         set_is_parsed(true);
0447         return true;
0448     }
0449 
0450     /** @brief Implementation of Attribute::to_string */
0451     bool to_string(std::string &att) const  override {
0452         att = std::to_string(m_val);
0453         return true;
0454     }
0455 
0456     /** @brief get the value associated to this Attribute. */
0457     long long value() const {
0458         return m_val;
0459     }
0460 
0461     /** @brief set the value associated to this Attribute. */
0462     void set_value(const long long& l) {
0463         m_val = l;
0464         set_is_parsed(true);
0465     }
0466 
0467 private:
0468 
0469     long long m_val; ///< Attribute value
0470 
0471 };
0472 
0473 /**
0474  *  @class HepMC3::LongDoubleAttribute
0475  *  @brief Attribute that holds a real number as a long double.
0476  *
0477  *  @ingroup attributes
0478  */
0479 class LongDoubleAttribute : public Attribute {
0480 public:
0481 
0482     /** @brief Default constructor */
0483     LongDoubleAttribute(): Attribute(), m_val(0.0) {}
0484 
0485     /** @brief Constructor initializing attribute value */
0486     LongDoubleAttribute(long double val): Attribute(), m_val(val) {}
0487 
0488     /** @brief Implementation of Attribute::from_string */
0489     bool from_string(const std::string &att) override {
0490         m_val = strtold( att.c_str(),NULL);
0491         set_is_parsed(true);
0492         return true;
0493     }
0494 
0495     /** @brief Implementation of Attribute::to_string */
0496     bool to_string(std::string &att) const  override {
0497         std::ostringstream oss;
0498         oss << std::setprecision(std::numeric_limits<long double>::digits10)
0499             << m_val;
0500         att = oss.str();
0501         return true;
0502     }
0503 
0504     /** @brief get the value associated to this Attribute. */
0505     long double value() const {
0506         return m_val;
0507     }
0508 
0509     /** @brief set the value associated to this Attribute. */
0510     void set_value(const long double& d) {
0511         m_val = d;
0512         set_is_parsed(true);
0513     }
0514 
0515 private:
0516 
0517     long double m_val; ///< Attribute value
0518 };
0519 
0520 
0521 
0522 /**
0523  *  @class HepMC3::UIntAttribute
0524  *  @brief Attribute that holds an unsigned int
0525  *
0526  *  @ingroup attributes
0527  */
0528 class UIntAttribute : public Attribute {
0529 public:
0530 
0531     /** @brief Default constructor */
0532     UIntAttribute():Attribute(),m_val(0) {}
0533 
0534     /** @brief Constructor initializing attribute value */
0535     UIntAttribute(unsigned int val):Attribute(),m_val(val) {}
0536 
0537     /** @brief Implementation of Attribute::from_string */
0538     bool from_string(const std::string &att)  override {
0539         m_val = strtoul(att.c_str(), NULL, 0);
0540         set_is_parsed(true);
0541         return true;
0542     }
0543 
0544     /** @brief Implementation of Attribute::to_string */
0545     bool to_string(std::string &att) const  override {
0546         att = std::to_string(m_val);
0547         return true;
0548     }
0549 
0550     /** @brief get the value associated to this Attribute. */
0551     unsigned int value() const {
0552         return m_val;
0553     }
0554 
0555     /** @brief set the value associated to this Attribute. */
0556     void set_value(const unsigned int& i) {
0557         m_val = i;
0558         set_is_parsed(true);
0559     }
0560 
0561 private:
0562     unsigned int m_val; ///< Attribute value
0563 };
0564 
0565 
0566 
0567 /**
0568  *  @class HepMC3::ULongAttribute
0569  *  @brief Attribute that holds an unsigned long
0570  *
0571  *  @ingroup attributes
0572  */
0573 class ULongAttribute : public Attribute {
0574 public:
0575 
0576     /** @brief Default constructor */
0577     ULongAttribute():Attribute(),m_val(0) {}
0578 
0579     /** @brief Constructor initializing attribute value */
0580     ULongAttribute(unsigned long val):Attribute(),m_val(val) {}
0581 
0582     /** @brief Implementation of Attribute::from_string */
0583     bool from_string(const std::string &att)  override {
0584         m_val = strtoul(att.c_str(), NULL, 0);
0585         set_is_parsed(true);
0586         return true;
0587     }
0588 
0589     /** @brief Implementation of Attribute::to_string */
0590     bool to_string(std::string &att) const  override {
0591         att = std::to_string(m_val);
0592         return true;
0593     }
0594 
0595     /** @brief get the value associated to this Attribute. */
0596     unsigned long value() const {
0597         return m_val;
0598     }
0599 
0600     /** @brief set the value associated to this Attribute. */
0601     void set_value(const unsigned long& i) {
0602         m_val = i;
0603         set_is_parsed(true);
0604     }
0605 
0606 private:
0607     unsigned long m_val; ///< Attribute value
0608 };
0609 
0610 
0611 /**
0612  *  @class HepMC3::ULongLongAttribute
0613  *  @brief Attribute that holds an unsigned long long
0614  *
0615  *  @ingroup attributes
0616  */
0617 class ULongLongAttribute : public Attribute {
0618 public:
0619 
0620     /** @brief Default constructor */
0621     ULongLongAttribute():Attribute(),m_val(0) {}
0622 
0623     /** @brief Constructor initializing attribute value */
0624     ULongLongAttribute(unsigned long long val):Attribute(),m_val(val) {}
0625 
0626     /** @brief Implementation of Attribute::from_string */
0627     bool from_string(const std::string &att)  override {
0628         m_val = strtoull(att.c_str(), NULL, 0);
0629         set_is_parsed(true);
0630         return true;
0631     }
0632 
0633     /** @brief Implementation of Attribute::to_string */
0634     bool to_string(std::string &att) const  override {
0635         att = std::to_string(m_val);
0636         return true;
0637     }
0638 
0639     /** @brief get the value associated to this Attribute. */
0640     unsigned long long value() const {
0641         return m_val;
0642     }
0643 
0644     /** @brief set the value associated to this Attribute. */
0645     void set_value(const unsigned long long& i) {
0646         m_val = i;
0647         set_is_parsed(true);
0648     }
0649 
0650 private:
0651     unsigned long long m_val; ///< Attribute value
0652 };
0653 
0654 /**
0655 *  @class HepMC3::BoolAttribute
0656 *  @brief Attribute that holds an Booleger implemented as an int
0657 *
0658 *  @ingroup attributes
0659 */
0660 class BoolAttribute : public Attribute {
0661 public:
0662 
0663     /** @brief Default constructor */
0664     BoolAttribute():Attribute(),m_val(false) {}
0665 
0666     /** @brief Constructor initializing attribute value */
0667     BoolAttribute(bool val):Attribute(),m_val(val) {}
0668 
0669     /** @brief Implementation of Attribute::from_string */
0670     bool from_string(const std::string &att)  override {
0671         if (att.size()!=1) return false;
0672         if (att==std::string("1")) {m_val = true;  return true;}
0673         if (att==std::string("0")) {m_val = false; return true;}
0674         set_is_parsed(true);
0675         return false;
0676     }
0677 
0678     /** @brief Implementation of Attribute::to_string */
0679     bool to_string(std::string &att) const override {
0680         att = std::to_string(m_val);
0681         return true;
0682     }
0683 
0684     /** @brief get the value associated to this Attribute. */
0685     bool value() const {
0686         return m_val;
0687     }
0688 
0689     /** @brief set the value associated to this Attribute. */
0690     void set_value(const bool& i) {
0691         m_val = i;
0692         set_is_parsed(true);
0693     }
0694 
0695 private:
0696     bool m_val; ///< Attribute value
0697 };
0698 
0699 /**
0700  *  @class HepMC3::VectorCharAttribute
0701  *  @brief Attribute that holds a vector of characters of type  char
0702  *
0703  *  @ingroup attributes
0704  */
0705 class VectorCharAttribute : public Attribute {
0706 public:
0707 
0708     /** @brief Default constructor */
0709     VectorCharAttribute():Attribute(),m_val() {}
0710 
0711     /** @brief Constructor initializing attribute value */
0712     VectorCharAttribute(std::vector<char> val):Attribute(),m_val(val) {}
0713 
0714     /** @brief Implementation of Attribute::from_string */
0715     bool from_string(const std::string &att) override {
0716         char  datafoo;
0717         m_val.clear();
0718         std::stringstream datastream(att);
0719         while (datastream >> datafoo) m_val.emplace_back(datafoo);
0720         set_is_parsed(true);
0721         return true;
0722     }
0723 
0724     /** @brief Implementation of Attribute::to_string */
0725     bool to_string(std::string &att) const  override {
0726         att.clear();
0727         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
0728         return true;
0729     }
0730 
0731     /** @brief get the value associated to this Attribute. */
0732     std::vector<char> value() const {
0733         return m_val;
0734 
0735     }
0736 
0737     /** @brief set the value associated to this Attribute. */
0738     void set_value(const std::vector<char>& i) {
0739         m_val = i;
0740         set_is_parsed(true);
0741     }
0742 
0743 private:
0744     std::vector<char> m_val; ///< Attribute value
0745 };
0746 
0747 /**
0748  *  @class HepMC3::VectorFloatAttribute
0749  *  @brief Attribute that holds a vector of real numbers of type float
0750  *
0751  *  @ingroup attributes
0752  */
0753 class VectorFloatAttribute : public Attribute {
0754 public:
0755 
0756     /** @brief Default constructor */
0757     VectorFloatAttribute():Attribute(),m_val() {}
0758 
0759     /** @brief Constructor initializing attribute value */
0760     VectorFloatAttribute(std::vector<float> val):Attribute(),m_val(val) {}
0761 
0762     /** @brief Implementation of Attribute::from_string */
0763     bool from_string(const std::string &att) override {
0764         float  datafoo;
0765         m_val.clear();
0766         std::stringstream datastream(att);
0767         while (datastream >> datafoo) m_val.emplace_back(datafoo);
0768         set_is_parsed(true);
0769         return true;
0770     }
0771 
0772     /** @brief Implementation of Attribute::to_string */
0773     bool to_string(std::string &att) const  override {
0774         att.clear();
0775         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
0776         return true;
0777     }
0778 
0779     /** @brief get the value associated to this Attribute. */
0780     std::vector<float> value() const {
0781         return m_val;
0782     }
0783 
0784     /** @brief set the value associated to this Attribute. */
0785     void set_value(const std::vector<float>& i) {
0786         m_val = i;
0787         set_is_parsed(true);
0788     }
0789 
0790 private:
0791     std::vector<float> m_val; ///< Attribute value
0792 };
0793 
0794 
0795 /**
0796  *  @class HepMC3::VectorLongDoubleAttribute
0797  *  @brief Attribute that holds a vector of real numbers of type long double
0798  *
0799  *  @ingroup attributes
0800  */
0801 class VectorLongDoubleAttribute : public Attribute {
0802 public:
0803 
0804     /** @brief Default constructor */
0805     VectorLongDoubleAttribute():Attribute(),m_val() {}
0806 
0807     /** @brief Constructor initializing attribute value */
0808     VectorLongDoubleAttribute(std::vector<long double> val):Attribute(),m_val(val) {}
0809 
0810     /** @brief Implementation of Attribute::from_string */
0811     bool from_string(const std::string &att) override {
0812         long double  datafoo;
0813         m_val.clear();
0814         std::stringstream datastream(att);
0815         while (datastream >> datafoo) m_val.emplace_back(datafoo);
0816         set_is_parsed(true);
0817         return true;
0818     }
0819 
0820     /** @brief Implementation of Attribute::to_string */
0821     bool to_string(std::string &att) const  override {
0822         att.clear();
0823         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
0824         return true;
0825     }
0826 
0827     /** @brief get the value associated to this Attribute. */
0828     std::vector<long double> value() const {
0829         return m_val;
0830     }
0831 
0832     /** @brief set the value associated to this Attribute. */
0833     void set_value(const std::vector<long double>& i) {
0834         m_val = i;
0835         set_is_parsed(true);
0836     }
0837 
0838 private:
0839     std::vector<long double> m_val; ///< Attribute value
0840 };
0841 
0842 
0843 
0844 /**
0845  *  @class HepMC3::VectorLongLongAttribute
0846  *  @brief Attribute that holds a vector of integers of type  long long
0847  *
0848  *  @ingroup attributes
0849  */
0850 class VectorLongLongAttribute : public Attribute {
0851 public:
0852 
0853     /** @brief Default constructor */
0854     VectorLongLongAttribute():Attribute(),m_val() {}
0855 
0856     /** @brief Constructor initializing attribute value */
0857     VectorLongLongAttribute(std::vector<long long> val):Attribute(),m_val(val) {}
0858 
0859     /** @brief Implementation of Attribute::from_string */
0860     bool from_string(const std::string &att) override {
0861         long long  datafoo;
0862         m_val.clear();
0863         std::stringstream datastream(att);
0864         while (datastream >> datafoo) m_val.emplace_back(datafoo);
0865         set_is_parsed(true);
0866         return true;
0867     }
0868 
0869     /** @brief Implementation of Attribute::to_string */
0870     bool to_string(std::string &att) const  override {
0871         att.clear();
0872         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
0873         return true;
0874     }
0875 
0876     /** @brief get the value associated to this Attribute. */
0877     std::vector<long long> value() const {
0878         return m_val;
0879     }
0880 
0881     /** @brief set the value associated to this Attribute. */
0882     void set_value(const std::vector<long long>& i) {
0883         m_val = i;
0884         set_is_parsed(true);
0885     }
0886 
0887 private:
0888     std::vector<long long> m_val; ///< Attribute value
0889 };
0890 
0891 /**
0892  *  @class HepMC3::VectorUIntAttribute
0893  *  @brief Attribute that holds a vector of unsigned integers of type  unsigned int
0894  *
0895  *  @ingroup attributes
0896  */
0897 class VectorUIntAttribute : public Attribute {
0898 public:
0899 
0900     /** @brief Default constructor */
0901     VectorUIntAttribute():Attribute(),m_val() {}
0902 
0903     /** @brief Constructor initializing attribute value */
0904     VectorUIntAttribute(std::vector<unsigned int> val):Attribute(),m_val(val) {}
0905 
0906     /** @brief Implementation of Attribute::from_string */
0907     bool from_string(const std::string &att) override {
0908         unsigned int  datafoo;
0909         m_val.clear();
0910         std::stringstream datastream(att);
0911         while (datastream >> datafoo) m_val.emplace_back(datafoo);
0912         set_is_parsed(true);
0913         return true;
0914     }
0915 
0916     /** @brief Implementation of Attribute::to_string */
0917     bool to_string(std::string &att) const  override {
0918         att.clear();
0919         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
0920         return true;
0921     }
0922 
0923     /** @brief get the value associated to this Attribute. */
0924     std::vector<unsigned int> value() const {
0925         return m_val;
0926     }
0927 
0928     /** @brief set the value associated to this Attribute. */
0929     void set_value(const std::vector<unsigned int>& i) {
0930         m_val = i;
0931         set_is_parsed(true);
0932     }
0933 
0934 private:
0935     std::vector<unsigned int> m_val; ///< Attribute value
0936 };
0937 
0938 /**
0939  *  @class HepMC3::VectorULongAttribute
0940  *  @brief Attribute that holds a vector of unsigned integers of type  unsigned long
0941  *
0942  *  @ingroup attributes
0943  */
0944 class VectorULongAttribute : public Attribute {
0945 public:
0946 
0947     /** @brief Default constructor */
0948     VectorULongAttribute():Attribute(),m_val() {}
0949 
0950     /** @brief Constructor initializing attribute value */
0951     VectorULongAttribute(std::vector<unsigned long> val):Attribute(),m_val(val) {}
0952 
0953     /** @brief Implementation of Attribute::from_string */
0954     bool from_string(const std::string &att) override {
0955         unsigned long  datafoo;
0956         m_val.clear();
0957         std::stringstream datastream(att);
0958         while (datastream >> datafoo) m_val.emplace_back(datafoo);
0959         set_is_parsed(true);
0960         return true;
0961     }
0962 
0963     /** @brief Implementation of Attribute::to_string */
0964     bool to_string(std::string &att) const  override {
0965         att.clear();
0966         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
0967         return true;
0968     }
0969 
0970     /** @brief get the value associated to this Attribute. */
0971     std::vector<unsigned long> value() const {
0972         return m_val;
0973     }
0974 
0975     /** @brief set the value associated to this Attribute. */
0976     void set_value(const std::vector<unsigned long>& i) {
0977         m_val = i;
0978         set_is_parsed(true);
0979     }
0980 
0981 private:
0982     std::vector<unsigned long> m_val; ///< Attribute value
0983 };
0984 
0985 
0986 /**
0987  *  @class HepMC3::VectorULongLongAttribute
0988  *  @brief Attribute that holds a vector of integers of type  unsigned long long
0989  *
0990  *  @ingroup attributes
0991  */
0992 class VectorULongLongAttribute : public Attribute {
0993 public:
0994 
0995     /** @brief Default constructor */
0996     VectorULongLongAttribute():Attribute(),m_val() {}
0997 
0998     /** @brief Constructor initializing attribute value */
0999     VectorULongLongAttribute(std::vector<unsigned long long> val):Attribute(),m_val(val) {}
1000 
1001     /** @brief Implementation of Attribute::from_string */
1002     bool from_string(const std::string &att) override {
1003         unsigned long long  datafoo;
1004         m_val.clear();
1005         std::stringstream datastream(att);
1006         while (datastream >> datafoo) m_val.emplace_back(datafoo);
1007         set_is_parsed(true);
1008         return true;
1009     }
1010 
1011     /** @brief Implementation of Attribute::to_string */
1012     bool to_string(std::string &att) const  override {
1013         att.clear();
1014         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
1015         return true;
1016     }
1017 
1018     /** @brief get the value associated to this Attribute. */
1019     std::vector<unsigned long long> value() const {
1020         return m_val;
1021     }
1022 
1023     /** @brief set the value associated to this Attribute. */
1024     void set_value(const std::vector<unsigned long long>& i) {
1025         m_val = i;
1026         set_is_parsed(true);
1027     }
1028 
1029 private:
1030     std::vector<unsigned long long> m_val; ///< Attribute value
1031 };
1032 
1033 /**
1034  *  @class HepMC3::VectorIntAttribute
1035  *  @brief Attribute that holds a vector of integers of type  int
1036  *
1037  *  @ingroup attributes
1038  */
1039 class VectorIntAttribute : public Attribute {
1040 public:
1041 
1042     /** @brief Default constructor */
1043     VectorIntAttribute():Attribute(),m_val() {}
1044 
1045     /** @brief Constructor initializing attribute value */
1046     VectorIntAttribute(std::vector<int> val):Attribute(),m_val(val) {}
1047 
1048     /** @brief Implementation of Attribute::from_string */
1049     bool from_string(const std::string &att) override {
1050         int  datafoo;
1051         m_val.clear();
1052         std::stringstream datastream(att);
1053         while (datastream >> datafoo) m_val.emplace_back(datafoo);
1054         set_is_parsed(true);
1055         return true;
1056     }
1057 
1058     /** @brief Implementation of Attribute::to_string */
1059     bool to_string(std::string &att) const  override {
1060         att.clear();
1061         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
1062         return true;
1063     }
1064 
1065     /** @brief get the value associated to this Attribute. */
1066     std::vector<int> value() const {
1067         return m_val;
1068 
1069     }
1070 
1071     /** @brief set the value associated to this Attribute. */
1072     void set_value(const std::vector<int>& i) {
1073         m_val = i;
1074         set_is_parsed(true);
1075     }
1076 
1077 private:
1078     std::vector<int> m_val; ///< Attribute value
1079 };
1080 
1081 /**
1082  *  @class HepMC3::VectorLongIntAttribute
1083  *  @brief Attribute that holds a vector of integers of type long int
1084  *
1085  *  @ingroup attributes
1086  */
1087 class VectorLongIntAttribute : public Attribute {
1088 public:
1089 
1090     /** @brief Default constructor */
1091     VectorLongIntAttribute():Attribute(),m_val() {}
1092 
1093     /** @brief Constructor initializing attribute value */
1094     VectorLongIntAttribute(std::vector<long int> val):Attribute(),m_val(val) {}
1095 
1096     /** @brief Implementation of Attribute::from_string */
1097     bool from_string(const std::string &att) override {
1098         long int  datafoo;
1099         m_val.clear();
1100         std::stringstream datastream(att);
1101         while (datastream >> datafoo) m_val.emplace_back(datafoo);
1102         set_is_parsed(true);
1103         return true;
1104     }
1105 
1106     /** @brief Implementation of Attribute::to_string */
1107     bool to_string(std::string &att) const  override {
1108         att.clear();
1109         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
1110         return true;
1111     }
1112 
1113     /** @brief get the value associated to this Attribute. */
1114     std::vector<long int> value() const {
1115         return m_val;
1116     }
1117 
1118     /** @brief set the value associated to this Attribute. */
1119     void set_value(const std::vector<long int>& i) {
1120         m_val = i;
1121         set_is_parsed(true);
1122     }
1123 
1124 private:
1125     std::vector<long int> m_val; ///< Attribute value
1126 };
1127 
1128 /**
1129  *  @class HepMC3::VectorDoubleAttribute
1130  *  @brief Attribute that holds a vector of real numbers of type  double
1131  *
1132  *  @ingroup attributes
1133  */
1134 class VectorDoubleAttribute : public Attribute {
1135 public:
1136 
1137     /** @brief Default constructor */
1138     VectorDoubleAttribute():Attribute(),m_val() {}
1139 
1140     /** @brief Constructor initializing attribute value */
1141     VectorDoubleAttribute(std::vector<double> val):Attribute(),m_val(val) {}
1142 
1143     /** @brief Implementation of Attribute::from_string */
1144     bool from_string(const std::string &att) override {
1145         double  datafoo;
1146         m_val.clear();
1147         std::stringstream datastream(att);
1148         while (datastream >> datafoo) m_val.emplace_back(datafoo);
1149         set_is_parsed(true);
1150         return true;
1151     }
1152 
1153     /** @brief Implementation of Attribute::to_string */
1154     bool to_string(std::string &att) const  override {
1155         att.clear();
1156         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=std::to_string(a);}
1157         return true;
1158     }
1159 
1160     /** @brief get the value associated to this Attribute. */
1161     std::vector<double> value() const {
1162         return m_val;
1163     }
1164 
1165     /** @brief set the value associated to this Attribute. */
1166     void set_value(const std::vector<double>& i) {
1167         m_val = i;
1168         set_is_parsed(true);
1169     }
1170 
1171 private:
1172     std::vector<double> m_val; ///< Attribute value
1173 };
1174 
1175 
1176 /**
1177  *  @class HepMC3::VectorStringAttribute
1178  *  @brief Attribute that holds a vector of type  string
1179  *
1180  *  @ingroup attributes
1181  */
1182 class VectorStringAttribute : public Attribute {
1183 public:
1184 
1185     /** @brief Default constructor */
1186     VectorStringAttribute():Attribute(),m_val() {}
1187 
1188     /** @brief Constructor initializing attribute value */
1189     VectorStringAttribute(std::vector<std::string> val):Attribute(),m_val(val) {}
1190 
1191     /** @brief Implementation of Attribute::from_string */
1192     bool from_string(const string &att) override {
1193         size_t posb = att.find_first_not_of(' ');
1194         do {
1195             size_t pose = att.find_first_of(' ', posb);
1196             m_val.push_back(att.substr(posb, pose - posb));
1197             posb = att.find_first_not_of(' ', pose);
1198         } while (posb != std::string::npos);
1199         set_is_parsed(true);
1200         return true;
1201     }
1202 
1203     /** @brief Implementation of Attribute::to_string */
1204     bool to_string(std::string &att) const  override {
1205         att.clear();
1206         for (const auto& a:  m_val) {if (att.length()) att+=" ";  att+=a;}
1207         return true;
1208     }
1209 
1210     /** @brief get the value associated to this Attribute. */
1211     std::vector<std::string> value() const {
1212         return m_val;
1213     }
1214 
1215     /** @brief set the value associated to this Attribute. */
1216     void set_value(const std::vector<std::string>& i) {
1217         m_val = i;
1218         set_is_parsed(true);
1219     }
1220 
1221 private:
1222     std::vector<std::string> m_val; ///< Attribute value
1223 };
1224 
1225 
1226 } // namespace HepMC3
1227 
1228 #endif