File indexing completed on 2025-01-18 10:01:11
0001
0002
0003
0004
0005
0006 #ifndef HEPMC3_ATTRIBUTE_H
0007 #define HEPMC3_ATTRIBUTE_H
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
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
0033 using std::string;
0034
0035 namespace HepMC3 {
0036
0037
0038 class GenEvent;
0039
0040
0041 class GenRunInfo;
0042
0043
0044 class Attribute {
0045
0046
0047
0048 public:
0049
0050
0051 Attribute():m_is_parsed(true) { m_event=nullptr; }
0052
0053
0054 virtual ~Attribute() {}
0055
0056 protected:
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 explicit Attribute(const std::string &st):m_is_parsed(false),m_string(st) { m_event=nullptr; }
0067
0068
0069 friend class GenEvent;
0070
0071
0072
0073
0074 public:
0075
0076
0077 virtual bool from_string(const std::string & att) = 0;
0078
0079
0080
0081 virtual bool init() {
0082 return true;
0083 }
0084
0085
0086
0087
0088
0089
0090 virtual bool init(const GenRunInfo & ) {
0091 return true;
0092 }
0093
0094
0095 virtual bool to_string(std::string &att) const = 0;
0096
0097
0098
0099
0100 public:
0101
0102 bool is_parsed() const { return m_is_parsed; }
0103
0104
0105 const std::string& unparsed_string() const { return m_string; }
0106
0107
0108 const GenEvent * event() const {
0109 return m_event;
0110 }
0111
0112
0113 GenParticlePtr particle() {
0114 return m_particle;
0115 }
0116
0117
0118 ConstGenParticlePtr particle() const {
0119 return std::const_pointer_cast<GenParticle>(m_particle);
0120 }
0121
0122
0123 GenVertexPtr vertex() {
0124 return m_vertex;
0125 }
0126
0127
0128 ConstGenVertexPtr vertex() const {
0129 return std::const_pointer_cast<GenVertex>(m_vertex);
0130 }
0131
0132 protected:
0133
0134 void set_is_parsed(bool flag) { m_is_parsed = flag; }
0135
0136
0137 void set_unparsed_string(const std::string &st) { m_string = st; }
0138
0139
0140
0141
0142 private:
0143 bool m_is_parsed;
0144 std::string m_string;
0145 const GenEvent * m_event;
0146
0147 GenParticlePtr m_particle;
0148 GenVertexPtr m_vertex;
0149 };
0150
0151
0152
0153
0154
0155
0156
0157 class IntAttribute : public Attribute {
0158 public:
0159
0160
0161 IntAttribute():Attribute(),m_val(0) {}
0162
0163
0164 IntAttribute(int val):Attribute(),m_val(val) {}
0165
0166
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
0174 bool to_string(std::string &att) const override {
0175 att = std::to_string(m_val);
0176 return true;
0177 }
0178
0179
0180 int value() const {
0181 return m_val;
0182 }
0183
0184
0185 void set_value(const int& i) {
0186 m_val = i;
0187 set_is_parsed(true);
0188 }
0189
0190 private:
0191 int m_val;
0192 };
0193
0194
0195
0196
0197
0198
0199
0200 class LongAttribute : public Attribute {
0201 public:
0202
0203
0204 LongAttribute(): Attribute(), m_val(0) {}
0205
0206
0207 LongAttribute(long val): Attribute(), m_val(val) {}
0208
0209
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
0217 bool to_string(std::string &att) const override {
0218 att = std::to_string(m_val);
0219 return true;
0220 }
0221
0222
0223 long value() const {
0224 return m_val;
0225 }
0226
0227
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;
0236
0237 };
0238
0239
0240
0241
0242
0243
0244
0245 class DoubleAttribute : public Attribute {
0246 public:
0247
0248
0249 DoubleAttribute(): Attribute(), m_val(0.0) {}
0250
0251
0252 DoubleAttribute(double val): Attribute(), m_val(val) {}
0253
0254
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
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
0271 double value() const {
0272 return m_val;
0273 }
0274
0275
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;
0284 };
0285
0286
0287
0288
0289
0290
0291
0292 class FloatAttribute : public Attribute {
0293 public:
0294
0295
0296 FloatAttribute(): Attribute(), m_val(0.0) {}
0297
0298
0299 FloatAttribute(float val): Attribute(), m_val(val) {}
0300
0301
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
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
0318 float value() const {
0319 return m_val;
0320 }
0321
0322
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;
0331 };
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343 class StringAttribute : public Attribute {
0344 public:
0345
0346
0347 StringAttribute():Attribute() {}
0348
0349
0350
0351
0352
0353
0354
0355 StringAttribute(const std::string &st):Attribute(st) {}
0356
0357
0358 bool from_string(const std::string &att) override {
0359 set_unparsed_string(att);
0360 return true;
0361 }
0362
0363
0364 bool to_string(std::string &att) const override {
0365 att = unparsed_string();
0366 return true;
0367 }
0368
0369
0370 std::string value() const {
0371 return unparsed_string();
0372 }
0373
0374
0375 void set_value(const std::string& s) {
0376 set_unparsed_string(s);
0377 }
0378
0379 };
0380
0381
0382
0383
0384
0385
0386
0387 class CharAttribute : public Attribute {
0388 public:
0389
0390
0391 CharAttribute():Attribute(),m_val(0) {}
0392
0393
0394 CharAttribute(char val):Attribute(),m_val(val) {}
0395
0396
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
0408 bool to_string(std::string &att) const override {
0409 att = std::to_string(m_val);
0410 return true;
0411 }
0412
0413
0414 char value() const {
0415 return m_val;
0416 }
0417
0418
0419 void set_value(const char& i) {
0420 m_val = i;
0421 set_is_parsed(true);
0422 }
0423
0424 private:
0425 char m_val;
0426 };
0427
0428
0429
0430
0431
0432
0433
0434 class LongLongAttribute : public Attribute {
0435 public:
0436
0437
0438 LongLongAttribute(): Attribute(), m_val(0) {}
0439
0440
0441 LongLongAttribute(long long val): Attribute(), m_val(val) {}
0442
0443
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
0451 bool to_string(std::string &att) const override {
0452 att = std::to_string(m_val);
0453 return true;
0454 }
0455
0456
0457 long long value() const {
0458 return m_val;
0459 }
0460
0461
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;
0470
0471 };
0472
0473
0474
0475
0476
0477
0478
0479 class LongDoubleAttribute : public Attribute {
0480 public:
0481
0482
0483 LongDoubleAttribute(): Attribute(), m_val(0.0) {}
0484
0485
0486 LongDoubleAttribute(long double val): Attribute(), m_val(val) {}
0487
0488
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
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
0505 long double value() const {
0506 return m_val;
0507 }
0508
0509
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;
0518 };
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528 class UIntAttribute : public Attribute {
0529 public:
0530
0531
0532 UIntAttribute():Attribute(),m_val(0) {}
0533
0534
0535 UIntAttribute(unsigned int val):Attribute(),m_val(val) {}
0536
0537
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
0545 bool to_string(std::string &att) const override {
0546 att = std::to_string(m_val);
0547 return true;
0548 }
0549
0550
0551 unsigned int value() const {
0552 return m_val;
0553 }
0554
0555
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;
0563 };
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573 class ULongAttribute : public Attribute {
0574 public:
0575
0576
0577 ULongAttribute():Attribute(),m_val(0) {}
0578
0579
0580 ULongAttribute(unsigned long val):Attribute(),m_val(val) {}
0581
0582
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
0590 bool to_string(std::string &att) const override {
0591 att = std::to_string(m_val);
0592 return true;
0593 }
0594
0595
0596 unsigned long value() const {
0597 return m_val;
0598 }
0599
0600
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;
0608 };
0609
0610
0611
0612
0613
0614
0615
0616
0617 class ULongLongAttribute : public Attribute {
0618 public:
0619
0620
0621 ULongLongAttribute():Attribute(),m_val(0) {}
0622
0623
0624 ULongLongAttribute(unsigned long long val):Attribute(),m_val(val) {}
0625
0626
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
0634 bool to_string(std::string &att) const override {
0635 att = std::to_string(m_val);
0636 return true;
0637 }
0638
0639
0640 unsigned long long value() const {
0641 return m_val;
0642 }
0643
0644
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;
0652 };
0653
0654
0655
0656
0657
0658
0659
0660 class BoolAttribute : public Attribute {
0661 public:
0662
0663
0664 BoolAttribute():Attribute(),m_val(false) {}
0665
0666
0667 BoolAttribute(bool val):Attribute(),m_val(val) {}
0668
0669
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
0679 bool to_string(std::string &att) const override {
0680 att = std::to_string(m_val);
0681 return true;
0682 }
0683
0684
0685 bool value() const {
0686 return m_val;
0687 }
0688
0689
0690 void set_value(const bool& i) {
0691 m_val = i;
0692 set_is_parsed(true);
0693 }
0694
0695 private:
0696 bool m_val;
0697 };
0698
0699
0700
0701
0702
0703
0704
0705 class VectorCharAttribute : public Attribute {
0706 public:
0707
0708
0709 VectorCharAttribute():Attribute(),m_val() {}
0710
0711
0712 VectorCharAttribute(std::vector<char> val):Attribute(),m_val(val) {}
0713
0714
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
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
0732 std::vector<char> value() const {
0733 return m_val;
0734
0735 }
0736
0737
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;
0745 };
0746
0747
0748
0749
0750
0751
0752
0753 class VectorFloatAttribute : public Attribute {
0754 public:
0755
0756
0757 VectorFloatAttribute():Attribute(),m_val() {}
0758
0759
0760 VectorFloatAttribute(std::vector<float> val):Attribute(),m_val(val) {}
0761
0762
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
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
0780 std::vector<float> value() const {
0781 return m_val;
0782 }
0783
0784
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;
0792 };
0793
0794
0795
0796
0797
0798
0799
0800
0801 class VectorLongDoubleAttribute : public Attribute {
0802 public:
0803
0804
0805 VectorLongDoubleAttribute():Attribute(),m_val() {}
0806
0807
0808 VectorLongDoubleAttribute(std::vector<long double> val):Attribute(),m_val(val) {}
0809
0810
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
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
0828 std::vector<long double> value() const {
0829 return m_val;
0830 }
0831
0832
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;
0840 };
0841
0842
0843
0844
0845
0846
0847
0848
0849
0850 class VectorLongLongAttribute : public Attribute {
0851 public:
0852
0853
0854 VectorLongLongAttribute():Attribute(),m_val() {}
0855
0856
0857 VectorLongLongAttribute(std::vector<long long> val):Attribute(),m_val(val) {}
0858
0859
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
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
0877 std::vector<long long> value() const {
0878 return m_val;
0879 }
0880
0881
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;
0889 };
0890
0891
0892
0893
0894
0895
0896
0897 class VectorUIntAttribute : public Attribute {
0898 public:
0899
0900
0901 VectorUIntAttribute():Attribute(),m_val() {}
0902
0903
0904 VectorUIntAttribute(std::vector<unsigned int> val):Attribute(),m_val(val) {}
0905
0906
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
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
0924 std::vector<unsigned int> value() const {
0925 return m_val;
0926 }
0927
0928
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;
0936 };
0937
0938
0939
0940
0941
0942
0943
0944 class VectorULongAttribute : public Attribute {
0945 public:
0946
0947
0948 VectorULongAttribute():Attribute(),m_val() {}
0949
0950
0951 VectorULongAttribute(std::vector<unsigned long> val):Attribute(),m_val(val) {}
0952
0953
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
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
0971 std::vector<unsigned long> value() const {
0972 return m_val;
0973 }
0974
0975
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;
0983 };
0984
0985
0986
0987
0988
0989
0990
0991
0992 class VectorULongLongAttribute : public Attribute {
0993 public:
0994
0995
0996 VectorULongLongAttribute():Attribute(),m_val() {}
0997
0998
0999 VectorULongLongAttribute(std::vector<unsigned long long> val):Attribute(),m_val(val) {}
1000
1001
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
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
1019 std::vector<unsigned long long> value() const {
1020 return m_val;
1021 }
1022
1023
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;
1031 };
1032
1033
1034
1035
1036
1037
1038
1039 class VectorIntAttribute : public Attribute {
1040 public:
1041
1042
1043 VectorIntAttribute():Attribute(),m_val() {}
1044
1045
1046 VectorIntAttribute(std::vector<int> val):Attribute(),m_val(val) {}
1047
1048
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
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
1066 std::vector<int> value() const {
1067 return m_val;
1068
1069 }
1070
1071
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;
1079 };
1080
1081
1082
1083
1084
1085
1086
1087 class VectorLongIntAttribute : public Attribute {
1088 public:
1089
1090
1091 VectorLongIntAttribute():Attribute(),m_val() {}
1092
1093
1094 VectorLongIntAttribute(std::vector<long int> val):Attribute(),m_val(val) {}
1095
1096
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
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
1114 std::vector<long int> value() const {
1115 return m_val;
1116 }
1117
1118
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;
1126 };
1127
1128
1129
1130
1131
1132
1133
1134 class VectorDoubleAttribute : public Attribute {
1135 public:
1136
1137
1138 VectorDoubleAttribute():Attribute(),m_val() {}
1139
1140
1141 VectorDoubleAttribute(std::vector<double> val):Attribute(),m_val(val) {}
1142
1143
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
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
1161 std::vector<double> value() const {
1162 return m_val;
1163 }
1164
1165
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;
1173 };
1174
1175
1176
1177
1178
1179
1180
1181
1182 class VectorStringAttribute : public Attribute {
1183 public:
1184
1185
1186 VectorStringAttribute():Attribute(),m_val() {}
1187
1188
1189 VectorStringAttribute(std::vector<std::string> val):Attribute(),m_val(val) {}
1190
1191
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
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
1211 std::vector<std::string> value() const {
1212 return m_val;
1213 }
1214
1215
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;
1223 };
1224
1225
1226 }
1227
1228 #endif