| 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_ATTRIBUTE_H |
| 7 |
#define HEPMC3_ATTRIBUTE_H |
| 8 |
/** |
| 9 |
* @file Attribute.h |
| 10 |
* @brief Definition of \b class Attribute, \b class IntAttribute and \b class StringAttribute |
| 11 |
* |
| 12 |
* @class HepMC3::Attribute |
| 13 |
* @brief Base class for all attributes |
| 14 |
* |
| 15 |
* Contains virtual functions to_string and from_string that |
| 16 |
* each attribute must implement, as well as init function that |
| 17 |
* attributes should overload to initialize parsed attribute |
| 18 |
* |
| 19 |
* @ingroup attributes |
| 20 |
* |
| 21 |
*/ |
| 22 |
#include <cstdio> // sprintf |
| 23 |
#include <string> |
| 24 |
#include <limits> |
| 25 |
#include <sstream> |
| 26 |
#include <iomanip> |
| 27 |
#include <map> |
| 28 |
|
| 29 |
#include "HepMC3/GenParticle_fwd.h" |
| 30 |
#include "HepMC3/GenVertex_fwd.h" |
| 31 |
|
| 32 |
using std::string; |
| 33 |
|
| 34 |
namespace HepMC3 { |
| 35 |
|
| 36 |
/** @brief Forward declaration of GenEvent. */ |
| 37 |
class GenEvent; |
| 38 |
|
| 39 |
/** @brief Forward declaration of GenRunInfo. */ |
| 40 |
class GenRunInfo; |
| 41 |
|
| 42 |
/** @brief Forward declaration of GenParticle. */ |
| 43 |
// class GenParticle; |
| 44 |
|
| 45 |
class Attribute { |
| 46 |
// |
| 47 |
// Constructors |
| 48 |
// |
| 49 |
public: |
| 50 |
/** @brief Default constructor */ |
| 51 |
//Note: m_event should be set to nullptr in case event is deleted! |
| 52 |
Attribute():m_is_parsed(true) { m_event=nullptr; } |
| 53 |
|
| 54 |
/** @brief Virtual destructor */ |
| 55 |
virtual ~Attribute() {} |
| 56 |
|
| 57 |
protected: |
| 58 |
/** @brief Protected constructor that allows to set string |
| 59 |
* |
| 60 |
* Used when parsing attributes from file. An StringAttribute class |
| 61 |
* object is made, which uses this constructor to signify that |
| 62 |
* it just holds string without parsing it. |
| 63 |
* |
| 64 |
* @note There should be no need for user class to ever use this constructor |
| 65 |
*/ |
| 66 |
//Note: m_event should be set to nullptr n case event is deleted! |
| 67 |
explicit Attribute(const string &st):m_is_parsed(false),m_string(st) { m_event=nullptr; } |
| 68 |
|
| 69 |
/** @brief GenEvent is a friend */ |
| 70 |
friend class GenEvent; |
| 71 |
|
| 72 |
// |
| 73 |
// Virtual Functions |
| 74 |
// |
| 75 |
public: |
| 76 |
/** @brief Fill class content from string. |
| 77 |
*/ |
| 78 |
virtual bool from_string(const string & att) = 0; |
| 79 |
|
| 80 |
/** @brief Optionally initialize the attribute after from_string. |
| 81 |
*/ |
| 82 |
virtual bool init() { |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
/** @brief Optionally initialize the attribute after from_string |
| 87 |
* |
| 88 |
* Is passed a reference to the GenRunInfo object to which the |
| 89 |
* Attribute belongs. |
| 90 |
*/ |
| 91 |
virtual bool init(const GenRunInfo & ) { |
| 92 |
return true; |
| 93 |
} |
| 94 |
|
| 95 |
/** @brief Fill string from class content */ |
| 96 |
virtual bool to_string(string &att) const = 0; |
| 97 |
|
| 98 |
// |
| 99 |
// Accessors |
| 100 |
// |
| 101 |
public: |
| 102 |
/** @brief Check if this attribute is parsed */ |
| 103 |
bool is_parsed() const { return m_is_parsed; } |
| 104 |
|
| 105 |
/** @brief Get unparsed string */ |
| 106 |
const string& unparsed_string() const { return m_string; } |
| 107 |
|
| 108 |
/** return the GenEvent to which this Attribute belongs, if at all. */ |
| 109 |
const GenEvent * event() const { |
| 110 |
return m_event; |
| 111 |
} |
| 112 |
|
| 113 |
/** return the GenParticle to which this Attribute belongs, if at all. */ |
| 114 |
GenParticlePtr particle() { |
| 115 |
return m_particle; |
| 116 |
} |
| 117 |
|
| 118 |
/** return the GenParticle to which this Attribute belongs, if at all. */ |
| 119 |
ConstGenParticlePtr particle() const { |
| 120 |
return std::const_pointer_cast<GenParticle>(m_particle); |
| 121 |
} |
| 122 |
|
| 123 |
/** return the GenVertex to which this Attribute belongs, if at all. */ |
| 124 |
GenVertexPtr vertex() { |
| 125 |
return m_vertex; |
| 126 |
} |
| 127 |
|
| 128 |
/** return the GenVertex to which this Attribute belongs, if at all. */ |
| 129 |
ConstGenVertexPtr vertex() const { |
| 130 |
return std::const_pointer_cast<GenVertex>(m_vertex); |
| 131 |
} |
| 132 |
|
| 133 |
protected: |
| 134 |
/** @brief Set is_parsed flag */ |
| 135 |
void set_is_parsed(bool flag) { m_is_parsed = flag; } |
| 136 |
|
| 137 |
/** @brief Set unparsed string */ |
| 138 |
void set_unparsed_string(const string &st) { m_string = st; } |
| 139 |
|
| 140 |
// |
| 141 |
// Fields |
| 142 |
// |
| 143 |
private: |
| 144 |
bool m_is_parsed; //!< Is this attribute parsed? |
| 145 |
string m_string; //!< Raw (unparsed) string |
| 146 |
const GenEvent * m_event; //!< Possibility to be aware of the |
| 147 |
//! controlling GenEvent object. |
| 148 |
GenParticlePtr m_particle; //!< Particle to which assigned. |
| 149 |
GenVertexPtr m_vertex; //!< Vertex to which assigned. |
| 150 |
}; |
| 151 |
|
| 152 |
/** |
| 153 |
* @class HepMC3::IntAttribute |
| 154 |
* @brief Attribute that holds an Integer implemented as an int |
| 155 |
* |
| 156 |
* @ingroup attributes |
| 157 |
*/ |
| 158 |
class IntAttribute : public Attribute { |
| 159 |
public: |
| 160 |
|
| 161 |
/** @brief Default constructor */ |
| 162 |
IntAttribute():Attribute(),m_val(0) {} |
| 163 |
|
| 164 |
/** @brief Constructor initializing attribute value */ |
| 165 |
IntAttribute(int val):Attribute(),m_val(val) {} |
| 166 |
|
| 167 |
/** @brief Implementation of Attribute::from_string */ |
| 168 |
bool from_string(const string &att) { |
| 169 |
m_val = atoi( att.c_str() ); |
| 170 |
return true; |
| 171 |
} |
| 172 |
|
| 173 |
/** @brief Implementation of Attribute::to_string */ |
| 174 |
bool to_string(string &att) const { |
| 175 |
att = std::to_string(m_val); |
| 176 |
return true; |
| 177 |
} |
| 178 |
|
| 179 |
/** @brief get the value associated to this Attribute. */ |
| 180 |
int value() const { |
| 181 |
return m_val; |
| 182 |
} |
| 183 |
|
| 184 |
/** @brief set the value associated to this Attribute. */ |
| 185 |
void set_value(const int& i) { |
| 186 |
m_val = i; |
| 187 |
} |
| 188 |
|
| 189 |
private: |
| 190 |
int m_val; ///< Attribute value |
| 191 |
}; |
| 192 |
|
| 193 |
/** |
| 194 |
* @class HepMC3::LongAttribute |
| 195 |
* @brief Attribute that holds an Integer implemented as an int |
| 196 |
* |
| 197 |
* @ingroup attributes |
| 198 |
*/ |
| 199 |
class LongAttribute : public Attribute { |
| 200 |
public: |
| 201 |
|
| 202 |
/** @brief Default constructor */ |
| 203 |
LongAttribute(): Attribute(), m_val(0) {} |
| 204 |
|
| 205 |
/** @brief Constructor initializing attribute value */ |
| 206 |
LongAttribute(long val): Attribute(), m_val(val) {} |
| 207 |
|
| 208 |
/** @brief Implementation of Attribute::from_string */ |
| 209 |
bool from_string(const string &att) { |
| 210 |
m_val = atol( att.c_str() ); |
| 211 |
return true; |
| 212 |
} |
| 213 |
|
| 214 |
/** @brief Implementation of Attribute::to_string */ |
| 215 |
bool to_string(string &att) const { |
| 216 |
att = std::to_string(m_val); |
| 217 |
return true; |
| 218 |
} |
| 219 |
|
| 220 |
/** @brief get the value associated to this Attribute. */ |
| 221 |
long value() const { |
| 222 |
return m_val; |
| 223 |
} |
| 224 |
|
| 225 |
/** @brief set the value associated to this Attribute. */ |
| 226 |
void set_value(const long& l) { |
| 227 |
m_val = l; |
| 228 |
} |
| 229 |
|
| 230 |
private: |
| 231 |
|
| 232 |
long m_val; ///< Attribute value |
| 233 |
|
| 234 |
}; |
| 235 |
|
| 236 |
/** |
| 237 |
* @class HepMC3::DoubleAttribute |
| 238 |
* @brief Attribute that holds a real number as a double. |
| 239 |
* |
| 240 |
* @ingroup attributes |
| 241 |
*/ |
| 242 |
class DoubleAttribute : public Attribute { |
| 243 |
public: |
| 244 |
|
| 245 |
/** @brief Default constructor */ |
| 246 |
DoubleAttribute(): Attribute(), m_val(0.0) {} |
| 247 |
|
| 248 |
/** @brief Constructor initializing attribute value */ |
| 249 |
DoubleAttribute(double val): Attribute(), m_val(val) {} |
| 250 |
|
| 251 |
/** @brief Implementation of Attribute::from_string */ |
| 252 |
bool from_string(const string &att) { |
| 253 |
m_val = atof( att.c_str() ); |
| 254 |
return true; |
| 255 |
} |
| 256 |
|
| 257 |
/** @brief Implementation of Attribute::to_string */ |
| 258 |
bool to_string(string &att) const { |
| 259 |
std::ostringstream oss; |
| 260 |
oss << std::setprecision(std::numeric_limits<double>::digits10) |
| 261 |
<< m_val; |
| 262 |
att = oss.str(); |
| 263 |
return true; |
| 264 |
} |
| 265 |
|
| 266 |
/** @brief get the value associated to this Attribute. */ |
| 267 |
double value() const { |
| 268 |
return m_val; |
| 269 |
} |
| 270 |
|
| 271 |
/** @brief set the value associated to this Attribute. */ |
| 272 |
void set_value(const double& d) { |
| 273 |
m_val = d; |
| 274 |
} |
| 275 |
|
| 276 |
private: |
| 277 |
|
| 278 |
double m_val; ///< Attribute value |
| 279 |
}; |
| 280 |
|
| 281 |
/** |
| 282 |
* @class HepMC3::FloatAttribute |
| 283 |
* @brief Attribute that holds a real number as a float. |
| 284 |
* |
| 285 |
* @ingroup attributes |
| 286 |
*/ |
| 287 |
class FloatAttribute : public Attribute { |
| 288 |
public: |
| 289 |
|
| 290 |
/** @brief Default constructor */ |
| 291 |
FloatAttribute(): Attribute(), m_val(0.0) {} |
| 292 |
|
| 293 |
/** @brief Constructor initializing attribute value */ |
| 294 |
FloatAttribute(float val): Attribute(), m_val(val) {} |
| 295 |
|
| 296 |
/** @brief Implementation of Attribute::from_string */ |
| 297 |
bool from_string(const string &att) { |
| 298 |
m_val = float(atof( att.c_str() )); |
| 299 |
return true; |
| 300 |
} |
| 301 |
|
| 302 |
/** @brief Implementation of Attribute::to_string */ |
| 303 |
bool to_string(string &att) const { |
| 304 |
std::ostringstream oss; |
| 305 |
oss << std::setprecision(std::numeric_limits<float>::digits10) |
| 306 |
<< m_val; |
| 307 |
att = oss.str(); |
| 308 |
return true; |
| 309 |
} |
| 310 |
|
| 311 |
/** @brief get the value associated to this Attribute. */ |
| 312 |
float value() const { |
| 313 |
return m_val; |
| 314 |
} |
| 315 |
|
| 316 |
/** @brief set the value associated to this Attribute. */ |
| 317 |
void set_value(const float& f) { |
| 318 |
m_val = f; |
| 319 |
} |
| 320 |
|
| 321 |
private: |
| 322 |
|
| 323 |
float m_val; ///< Attribute value |
| 324 |
}; |
| 325 |
|
| 326 |
/** |
| 327 |
* @class HepMC3::StringAttribute |
| 328 |
* @brief Attribute that holds a string |
| 329 |
* |
| 330 |
* Default attribute constructed when reading input files. |
| 331 |
* It can be then parsed by other attributes or left as a string. |
| 332 |
* |
| 333 |
* @ingroup attributes |
| 334 |
* |
| 335 |
*/ |
| 336 |
class StringAttribute : public Attribute { |
| 337 |
public: |
| 338 |
|
| 339 |
/** @brief Default constructor - empty string */ |
| 340 |
StringAttribute():Attribute() {} |
| 341 |
|
| 342 |
/** @brief String-based constructor |
| 343 |
* |
| 344 |
* The Attribute constructor used here marks that this is an unparsed |
| 345 |
* string that can be (but does not have to be) parsed |
| 346 |
* |
| 347 |
*/ |
| 348 |
StringAttribute(const string &st):Attribute(st) {} |
| 349 |
|
| 350 |
/** @brief Implementation of Attribute::from_string */ |
| 351 |
bool from_string(const string &att) { |
| 352 |
set_unparsed_string(att); |
| 353 |
return true; |
| 354 |
} |
| 355 |
|
| 356 |
/** @brief Implementation of Attribute::to_string */ |
| 357 |
bool to_string(string &att) const { |
| 358 |
att = unparsed_string(); |
| 359 |
return true; |
| 360 |
} |
| 361 |
|
| 362 |
/** @brief get the value associated to this Attribute. */ |
| 363 |
string value() const { |
| 364 |
return unparsed_string(); |
| 365 |
} |
| 366 |
|
| 367 |
/** @brief set the value associated to this Attribute. */ |
| 368 |
void set_value(const string& s) { |
| 369 |
set_unparsed_string(s); |
| 370 |
} |
| 371 |
|
| 372 |
}; |
| 373 |
|
| 374 |
/** |
| 375 |
* @class HepMC3::CharAttribute |
| 376 |
* @brief Attribute that holds an Chareger implemented as an int |
| 377 |
* |
| 378 |
* @ingroup attributes |
| 379 |
*/ |
| 380 |
class CharAttribute : public Attribute { |
| 381 |
public: |
| 382 |
|
| 383 |
/** @brief Default constructor */ |
| 384 |
CharAttribute():Attribute(),m_val(0) {} |
| 385 |
|
| 386 |
/** @brief Constructor initializing attribute value */ |
| 387 |
CharAttribute(char val):Attribute(),m_val(val) {} |
| 388 |
|
| 389 |
/** @brief Implementation of Attribute::from_string */ |
| 390 |
bool from_string(const string &att) { |
| 391 |
if (att.size()) |
| 392 |
{ |
| 393 |
m_val = att.at(0); |
| 394 |
return true; |
| 395 |
} |
| 396 |
return false; |
| 397 |
} |
| 398 |
|
| 399 |
/** @brief Implementation of Attribute::to_string */ |
| 400 |
bool to_string(string &att) const { |
| 401 |
att = std::to_string(m_val); |
| 402 |
return true; |
| 403 |
} |
| 404 |
|
| 405 |
/** @brief get the value associated to this Attribute. */ |
| 406 |
char value() const { |
| 407 |
return m_val; |
| 408 |
} |
| 409 |
|
| 410 |
/** @brief set the value associated to this Attribute. */ |
| 411 |
void set_value(const char& i) { |
| 412 |
m_val = i; |
| 413 |
} |
| 414 |
|
| 415 |
private: |
| 416 |
char m_val; ///< Attribute value |
| 417 |
}; |
| 418 |
|
| 419 |
/** |
| 420 |
* @class HepMC3::LongLongAttribute |
| 421 |
* @brief Attribute that holds an Integer implemented as an int |
| 422 |
* |
| 423 |
* @ingroup attributes |
| 424 |
*/ |
| 425 |
class LongLongAttribute : public Attribute { |
| 426 |
public: |
| 427 |
|
| 428 |
/** @brief Default constructor */ |
| 429 |
LongLongAttribute(): Attribute(), m_val(0) {} |
| 430 |
|
| 431 |
/** @brief Constructor initializing attribute value */ |
| 432 |
LongLongAttribute(long long val): Attribute(), m_val(val) {} |
| 433 |
|
| 434 |
/** @brief Implementation of Attribute::from_string */ |
| 435 |
bool from_string(const string &att) { |
| 436 |
m_val = atoll( att.c_str() ); |
| 437 |
return true; |
| 438 |
} |
| 439 |
|
| 440 |
/** @brief Implementation of Attribute::to_string */ |
| 441 |
bool to_string(string &att) const { |
| 442 |
att = std::to_string(m_val); |
| 443 |
return true; |
| 444 |
} |
| 445 |
|
| 446 |
/** @brief get the value associated to this Attribute. */ |
| 447 |
long long value() const { |
| 448 |
return m_val; |
| 449 |
} |
| 450 |
|
| 451 |
/** @brief set the value associated to this Attribute. */ |
| 452 |
void set_value(const long long& l) { |
| 453 |
m_val = l; |
| 454 |
} |
| 455 |
|
| 456 |
private: |
| 457 |
|
| 458 |
long long m_val; ///< Attribute value |
| 459 |
|
| 460 |
}; |
| 461 |
|
| 462 |
/** |
| 463 |
* @class HepMC3::LongDoubleAttribute |
| 464 |
* @brief Attribute that holds a real number as a double. |
| 465 |
* |
| 466 |
* @ingroup attributes |
| 467 |
*/ |
| 468 |
class LongDoubleAttribute : public Attribute { |
| 469 |
public: |
| 470 |
|
| 471 |
/** @brief Default constructor */ |
| 472 |
LongDoubleAttribute(): Attribute(), m_val(0.0) {} |
| 473 |
|
| 474 |
/** @brief Constructor initializing attribute value */ |
| 475 |
LongDoubleAttribute(long double val): Attribute(), m_val(val) {} |
| 476 |
|
| 477 |
/** @brief Implementation of Attribute::from_string */ |
| 478 |
bool from_string(const string &att) { |
| 479 |
m_val = strtold( att.c_str(),NULL); |
| 480 |
return true; |
| 481 |
} |
| 482 |
|
| 483 |
/** @brief Implementation of Attribute::to_string */ |
| 484 |
bool to_string(string &att) const { |
| 485 |
std::ostringstream oss; |
| 486 |
oss << std::setprecision(std::numeric_limits<long double>::digits10) |
| 487 |
<< m_val; |
| 488 |
att = oss.str(); |
| 489 |
return true; |
| 490 |
} |
| 491 |
|
| 492 |
/** @brief get the value associated to this Attribute. */ |
| 493 |
long double value() const { |
| 494 |
return m_val; |
| 495 |
} |
| 496 |
|
| 497 |
/** @brief set the value associated to this Attribute. */ |
| 498 |
void set_value(const long double& d) { |
| 499 |
m_val = d; |
| 500 |
} |
| 501 |
|
| 502 |
private: |
| 503 |
|
| 504 |
long double m_val; ///< Attribute value |
| 505 |
}; |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
/** |
| 510 |
* @class HepMC3::UIntAttribute |
| 511 |
* @brief Attribute that holds an unsigned int |
| 512 |
* |
| 513 |
* @ingroup attributes |
| 514 |
*/ |
| 515 |
class UIntAttribute : public Attribute { |
| 516 |
public: |
| 517 |
|
| 518 |
/** @brief Default constructor */ |
| 519 |
UIntAttribute():Attribute(),m_val(0) {} |
| 520 |
|
| 521 |
/** @brief Constructor initializing attribute value */ |
| 522 |
UIntAttribute(unsigned int val):Attribute(),m_val(val) {} |
| 523 |
|
| 524 |
/** @brief Implementation of Attribute::from_string */ |
| 525 |
bool from_string(const string &att) { |
| 526 |
m_val = strtoul(att.c_str(), NULL, 0); |
| 527 |
return true; |
| 528 |
} |
| 529 |
|
| 530 |
/** @brief Implementation of Attribute::to_string */ |
| 531 |
bool to_string(string &att) const { |
| 532 |
att = std::to_string(m_val); |
| 533 |
return true; |
| 534 |
} |
| 535 |
|
| 536 |
/** @brief get the value associated to this Attribute. */ |
| 537 |
unsigned int value() const { |
| 538 |
return m_val; |
| 539 |
} |
| 540 |
|
| 541 |
/** @brief set the value associated to this Attribute. */ |
| 542 |
void set_value(const unsigned int& i) { |
| 543 |
m_val = i; |
| 544 |
} |
| 545 |
|
| 546 |
private: |
| 547 |
unsigned int m_val; ///< Attribute value |
| 548 |
}; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
/** |
| 553 |
* @class HepMC3::ULongAttribute |
| 554 |
* @brief Attribute that holds an unsigned long |
| 555 |
* |
| 556 |
* @ingroup attributes |
| 557 |
*/ |
| 558 |
class ULongAttribute : public Attribute { |
| 559 |
public: |
| 560 |
|
| 561 |
/** @brief Default constructor */ |
| 562 |
ULongAttribute():Attribute(),m_val(0) {} |
| 563 |
|
| 564 |
/** @brief Constructor initializing attribute value */ |
| 565 |
ULongAttribute(unsigned long val):Attribute(),m_val(val) {} |
| 566 |
|
| 567 |
/** @brief Implementation of Attribute::from_string */ |
| 568 |
bool from_string(const string &att) { |
| 569 |
m_val = strtoul(att.c_str(), NULL, 0); |
| 570 |
return true; |
| 571 |
} |
| 572 |
|
| 573 |
/** @brief Implementation of Attribute::to_string */ |
| 574 |
bool to_string(string &att) const { |
| 575 |
att = std::to_string(m_val); |
| 576 |
return true; |
| 577 |
} |
| 578 |
|
| 579 |
/** @brief get the value associated to this Attribute. */ |
| 580 |
unsigned long value() const { |
| 581 |
return m_val; |
| 582 |
} |
| 583 |
|
| 584 |
/** @brief set the value associated to this Attribute. */ |
| 585 |
void set_value(const unsigned long& i) { |
| 586 |
m_val = i; |
| 587 |
} |
| 588 |
|
| 589 |
private: |
| 590 |
unsigned long m_val; ///< Attribute value |
| 591 |
}; |
| 592 |
|
| 593 |
|
| 594 |
/** |
| 595 |
* @class HepMC3::ULongLongAttribute |
| 596 |
* @brief Attribute that holds an unsigned long long |
| 597 |
* |
| 598 |
* @ingroup attributes |
| 599 |
*/ |
| 600 |
class ULongLongAttribute : public Attribute { |
| 601 |
public: |
| 602 |
|
| 603 |
/** @brief Default constructor */ |
| 604 |
ULongLongAttribute():Attribute(),m_val(0) {} |
| 605 |
|
| 606 |
/** @brief Constructor initializing attribute value */ |
| 607 |
ULongLongAttribute(unsigned long long val):Attribute(),m_val(val) {} |
| 608 |
|
| 609 |
/** @brief Implementation of Attribute::from_string */ |
| 610 |
bool from_string(const string &att) { |
| 611 |
m_val = strtoull(att.c_str(), NULL, 0); |
| 612 |
return true; |
| 613 |
} |
| 614 |
|
| 615 |
/** @brief Implementation of Attribute::to_string */ |
| 616 |
bool to_string(string &att) const { |
| 617 |
att = std::to_string(m_val); |
| 618 |
return true; |
| 619 |
} |
| 620 |
|
| 621 |
/** @brief get the value associated to this Attribute. */ |
| 622 |
unsigned long long value() const { |
| 623 |
return m_val; |
| 624 |
} |
| 625 |
|
| 626 |
/** @brief set the value associated to this Attribute. */ |
| 627 |
void set_value(const unsigned long long& i) { |
| 628 |
m_val = i; |
| 629 |
} |
| 630 |
|
| 631 |
private: |
| 632 |
unsigned long long m_val; ///< Attribute value |
| 633 |
}; |
| 634 |
/** |
| 635 |
* @class HepMC3::BoolAttribute |
| 636 |
* @brief Attribute that holds an Booleger implemented as an int |
| 637 |
* |
| 638 |
* @ingroup attributes |
| 639 |
*/ |
| 640 |
class BoolAttribute : public Attribute { |
| 641 |
public: |
| 642 |
|
| 643 |
/** @brief Default constructor */ |
| 644 |
BoolAttribute():Attribute(),m_val(false) {} |
| 645 |
|
| 646 |
/** @brief Constructor initializing attribute value */ |
| 647 |
BoolAttribute(bool val):Attribute(),m_val(val) {} |
| 648 |
|
| 649 |
/** @brief Implementation of Attribute::from_string */ |
| 650 |
bool from_string(const string &att) { |
| 651 |
if (att.size()!=1) return false; |
| 652 |
if(att==std::string("1")) {m_val = true; return true;} |
| 653 |
if(att==std::string("0")) {m_val = false; return true;} |
| 654 |
return false; |
| 655 |
} |
| 656 |
|
| 657 |
/** @brief Implementation of Attribute::to_string */ |
| 658 |
bool to_string(string &att) const { |
| 659 |
att = std::to_string(m_val); |
| 660 |
return true; |
| 661 |
} |
| 662 |
|
| 663 |
/** @brief get the value associated to this Attribute. */ |
| 664 |
bool value() const { |
| 665 |
return m_val; |
| 666 |
} |
| 667 |
|
| 668 |
/** @brief set the value associated to this Attribute. */ |
| 669 |
void set_value(const bool& i) { |
| 670 |
m_val = i; |
| 671 |
} |
| 672 |
|
| 673 |
private: |
| 674 |
bool m_val; ///< Attribute value |
| 675 |
}; |
| 676 |
|
| 677 |
|
| 678 |
} // namespace HepMC3 |
| 679 |
|
| 680 |
#endif |