SLHAea  0.1
containers for SUSY Les Houches Accord input/output
 All Classes Namespaces Files Functions Variables Typedefs
slhaea.h
Go to the documentation of this file.
1 // SLHAea - containers for SUSY Les Houches Accord input/output
2 // Copyright © 2009-2011 Frank S. Thomas <frank@timepit.eu>
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 #ifndef SLHAEA_H
9 #define SLHAEA_H
10 
11 #include <algorithm>
12 #include <cctype>
13 #include <cstddef>
14 #include <deque>
15 #include <functional>
16 #include <iomanip>
17 #include <iostream>
18 #include <iterator>
19 #include <limits>
20 #include <sstream>
21 #include <stdexcept>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 #include <boost/algorithm/string/classification.hpp>
26 #include <boost/algorithm/string/join.hpp>
27 #include <boost/algorithm/string/predicate.hpp>
28 #include <boost/algorithm/string/split.hpp>
29 #include <boost/lexical_cast.hpp>
30 
31 namespace SLHAea {
32 
33 // auxiliary functions
43 template<class Target, class Source> inline Target
44 to(const Source& arg)
45 { return boost::lexical_cast<Target>(arg); }
46 
55 template<class Source> inline std::string
56 to_string(const Source& arg)
57 { return boost::lexical_cast<std::string>(arg); }
58 
70 template<class Source> inline std::string
71 to_string(const Source& arg, int precision)
72 {
73  std::ostringstream output;
74  output << std::setprecision(precision) << std::scientific << arg;
75  return output.str();
76 }
77 
78 
79 namespace detail {
80 
81 inline bool
82 is_all_whitespace(const std::string& str)
83 { return str.find_first_not_of(" \t\n\v\f\r") == std::string::npos; }
84 
85 inline std::string
86 to_upper_copy(const std::string& str)
87 {
88  std::string str_upper(str.length(), char());
89  std::transform(str.begin(), str.end(), str_upper.begin(),
90  static_cast<int (*)(int)>(std::toupper));
91  return str_upper;
92 }
93 
94 inline void
95 trim_left(std::string& str)
96 {
97  const std::size_t startpos = str.find_first_not_of(" \t\n\v\f\r");
98  if (startpos != std::string::npos) str.erase(0, startpos);
99  else str.clear();
100 }
101 
102 inline void
103 trim_right(std::string& str)
104 {
105  const std::size_t endpos = str.find_last_not_of(" \t\n\v\f\r");
106  if (endpos != std::string::npos) str.erase(endpos + 1);
107  else str.clear();
108 }
109 
110 } // namespace detail
111 
112 
113 // forward declarations
114 class Line;
115 class Block;
116 class Coll;
117 struct Key;
118 
119 inline std::ostream& operator<<(std::ostream& os, const Line& line);
120 inline std::ostream& operator<<(std::ostream& os, const Block& block);
121 inline std::ostream& operator<<(std::ostream& os, const Coll& coll);
122 inline std::ostream& operator<<(std::ostream& os, const Key& key);
123 
124 
146 class Line
147 {
148 private:
149  typedef std::vector<std::string> impl_type;
150 
151 public:
152  typedef std::string value_type;
153  typedef std::string& reference;
154  typedef const std::string& const_reference;
155  typedef impl_type::iterator iterator;
156  typedef impl_type::const_iterator const_iterator;
157  typedef impl_type::reverse_iterator reverse_iterator;
158  typedef impl_type::const_reverse_iterator const_reverse_iterator;
159  typedef impl_type::pointer pointer;
160  typedef impl_type::const_pointer const_pointer;
161  typedef impl_type::difference_type difference_type;
162  typedef impl_type::size_type size_type;
163 
164  // NOTE: The compiler-generated copy constructor and assignment
165  // operator for this class are just fine, so we don't need to
166  // write our own.
167 
169  Line() : impl_(), columns_() {}
170 
176  Line(const std::string& line) : impl_(), columns_()
177  { str(line); }
178 
186  Line&
187  operator=(const std::string& line)
188  {
189  str(line);
190  return *this;
191  }
192 
200  Line&
201  operator+=(const std::string& arg)
202  {
203  append(arg);
204  return *this;
205  }
206 
216  template<class T> Line&
217  operator<<(const T& field)
218  {
219  std::string field_str = to_string(field);
220  detail::trim_right(field_str);
221  if (field_str.empty()) return *this;
222 
223  if (contains_comment())
224  { back() += field_str; }
225  else
226  {
227  detail::trim_left(field_str);
228  impl_.push_back(field_str);
229  reformat();
230  }
231  return *this;
232  }
233 
243  Line&
244  append(const std::string& arg)
245  {
246  str(str() + arg);
247  return *this;
248  }
249 
262  Line&
263  str(const std::string& line)
264  {
265  clear();
266  static const std::string whitespace = " \t\v\f\r";
267  const std::size_t last_non_ws =
268  line.substr(0, line.find('\n')).find_last_not_of(whitespace);
269  if (last_non_ws == std::string::npos) return *this;
270 
271  const std::string trimmed_line = line.substr(0, last_non_ws + 1);
272  const std::size_t comment_pos = trimmed_line.find('#');
273  const std::string data = trimmed_line.substr(0, comment_pos);
274 
275  std::size_t pos1 = data.find_first_not_of(whitespace, 0);
276  std::size_t pos2 = data.find_first_of(whitespace, pos1);
277 
278  while (pos1 != std::string::npos)
279  {
280  impl_.push_back(data.substr(pos1, pos2 - pos1));
281  columns_.push_back(pos1);
282 
283  pos1 = data.find_first_not_of(whitespace, pos2);
284  pos2 = data.find_first_of(whitespace, pos1);
285  }
286 
287  if (comment_pos != std::string::npos)
288  {
289  impl_.push_back(trimmed_line.substr(comment_pos));
290  columns_.push_back(comment_pos);
291  }
292  return *this;
293  }
294 
296  std::string
297  str() const
298  {
299  if (empty()) return "";
300 
301  std::ostringstream output;
302  int length = 0, spaces = 0;
303 
304  const_iterator field = begin();
305  std::vector<std::size_t>::const_iterator column = columns_.begin();
306  for (; field != end() && column != columns_.end(); ++field, ++column)
307  {
308  spaces = std::max(0, static_cast<int>(*column) - length + 1);
309  length += spaces + field->length();
310 
311  output << std::setw(spaces) << " " << *field;
312  }
313  return output.str().substr(1);
314  }
315 
316  // element access
326  reference
328  { return impl_[n]; }
329 
341  { return impl_[n]; }
342 
349  reference
351  { return impl_.at(n); }
352 
360  at(size_type n) const
361  { return impl_.at(n); }
362 
366  reference
368  { return impl_.front(); }
369 
375  front() const
376  { return impl_.front(); }
377 
381  reference
383  { return impl_.back(); }
384 
390  back() const
391  { return impl_.back(); }
392 
393  // iterators
398  iterator
400  { return impl_.begin(); }
401 
408  begin() const
409  { return impl_.begin(); }
410 
417  cbegin() const
418  { return impl_.begin(); }
419 
425  iterator
426  end()
427  { return impl_.end(); }
428 
435  end() const
436  { return impl_.end(); }
437 
444  cend() const
445  { return impl_.end(); }
446 
453  { return impl_.rbegin(); }
454 
461  rbegin() const
462  { return impl_.rbegin(); }
463 
470  crbegin() const
471  { return impl_.rbegin(); }
472 
480  { return impl_.rend(); }
481 
488  rend() const
489  { return impl_.rend(); }
490 
497  crend() const
498  { return impl_.rend(); }
499 
500  // introspection
505  bool
506  is_block_def() const
507  {
508  if (size() < 2) return false;
509 
510  const_iterator field = begin();
511  return is_block_specifier(*field) && !is_comment(*++field);
512  }
513 
515  bool
517  { return !empty() && is_comment(front()); }
518 
523  bool
524  is_data_line() const
525  { return !empty() && !is_comment(front()) && !is_block_specifier(front()); }
526 
527  // capacity
529  size_type
530  size() const
531  { return impl_.size(); }
532 
536  size_type
537  data_size() const
538  { return std::distance(begin(), std::find_if(begin(), end(), is_comment)); }
539 
541  size_type
542  max_size() const
543  { return impl_.max_size(); }
544 
546  bool
547  empty() const
548  { return impl_.empty(); }
549 
550  // modifiers
555  void
556  swap(Line& line)
557  {
558  impl_.swap(line.impl_);
559  columns_.swap(line.columns_);
560  }
561 
563  void
565  {
566  impl_.clear();
567  columns_.clear();
568  }
569 
571  void
573  {
574  if (empty()) return;
575 
576  columns_.clear();
577  const_iterator field = begin();
578  std::size_t pos1 = 0, pos2 = 0;
579 
580  if (is_block_specifier(*field))
581  {
582  pos1 = 0;
583  pos2 = pos1 + field->length();
584  columns_.push_back(pos1);
585 
586  if (++field == end()) return;
587 
588  pos1 = pos2 + 1;
589  pos2 = pos1 + field->length();
590  columns_.push_back(pos1);
591  }
592  else if (is_comment(*field))
593  {
594  pos1 = 0;
595  pos2 = pos1 + field->length();
596  columns_.push_back(pos1);
597  }
598  else
599  {
600  pos1 = shift_width_;
601  pos2 = pos1 + field->length();
602  columns_.push_back(pos1);
603  }
604 
605  while (++field != end())
606  {
607  pos1 = pos2 + calc_spaces_for_indent(pos2);
608  if (starts_with_sign(*field)) --pos1;
609  pos2 = pos1 + field->length();
610  columns_.push_back(pos1);
611  }
612  }
613 
618  void
620  { if (!empty()) str("#" + str()); }
621 
627  void
629  {
630  if (!empty() && is_comment(front()))
631  {
632  front().erase(0, 1);
633  str(str());
634  }
635  }
636 
637 private:
638  bool
639  contains_comment() const
640  { return std::find_if(rbegin(), rend(), is_comment) != rend(); }
641 
642  static std::size_t
643  calc_spaces_for_indent(const std::size_t& pos)
644  {
645  std::size_t width = shift_width_ - (pos % shift_width_);
646  if (width < min_width_) width += shift_width_;
647  return width;
648  }
649 
650  static bool
651  is_block_specifier(const value_type& field)
652  {
653  static const std::size_t specifier_length = 5;
654  if (field.length() != specifier_length) return false;
655 
656  const value_type field_upper = detail::to_upper_copy(field);
657  return (field_upper == "BLOCK") || (field_upper == "DECAY");
658  }
659 
660  static bool
661  is_comment(const value_type& field)
662  { return !field.empty() && field[0] == '#'; }
663 
664  template<class T> Line&
665  insert_fundamental_type(const T& arg)
666  {
667  static const int digits = std::numeric_limits<T>::digits10;
668  return *this << to_string(arg, digits);
669  }
670 
671  static bool
672  starts_with_sign(const value_type& field)
673  { return !field.empty() && (field[0] == '-' || field[0] == '+'); }
674 
675 private:
676  impl_type impl_;
677  std::vector<std::size_t> columns_;
678 
679  static const std::size_t shift_width_ = 4;
680  static const std::size_t min_width_ = 2;
681 };
682 
683 template<> inline Line&
684 Line::operator<< <float>(const float& number)
685 {
686  insert_fundamental_type(number);
687  return *this;
688 }
689 
690 template<> inline Line&
691 Line::operator<< <double>(const double& number)
692 {
693  insert_fundamental_type(number);
694  return *this;
695 }
696 
697 template<> inline Line&
698 Line::operator<< <long double>(const long double& number)
699 {
700  insert_fundamental_type(number);
701  return *this;
702 }
703 
704 
724 class Block
725 {
726 private:
727  typedef std::vector<Line> impl_type;
728 
729 public:
730  typedef std::vector<std::string> key_type;
731  typedef Line value_type;
732  typedef Line& reference;
733  typedef const Line& const_reference;
734  typedef impl_type::iterator iterator;
735  typedef impl_type::const_iterator const_iterator;
736  typedef impl_type::reverse_iterator reverse_iterator;
737  typedef impl_type::const_reverse_iterator const_reverse_iterator;
738  typedef impl_type::pointer pointer;
739  typedef impl_type::const_pointer const_pointer;
740  typedef impl_type::difference_type difference_type;
741  typedef impl_type::size_type size_type;
742 
743  // NOTE: The compiler-generated copy constructor and assignment
744  // operator for this class are just fine, so we don't need to
745  // write our own.
746 
751  explicit
752  Block(const std::string& name = "") : name_(name), impl_() {}
753 
759  explicit
760  Block(std::istream& is) : name_(), impl_()
761  { read(is); }
762 
767  static Block
768  from_str(const std::string& block)
769  {
770  std::istringstream input(block);
771  return Block(input);
772  }
773 
781  void
782  name(const std::string& newName)
783  { name_ = newName; }
784 
786  const std::string&
787  name() const
788  { return name_; }
789 
797  void
798  rename(const std::string& newName)
799  {
800  name(newName);
801  iterator block_def = find_block_def();
802  if (block_def != end()) (*block_def)[1] = newName;
803  }
804 
817  Block&
818  read(std::istream& is)
819  {
820  std::string line_str;
821  value_type line;
822 
823  std::size_t def_count = 0;
824  bool nameless = name().empty();
825 
826  while (std::getline(is, line_str))
827  {
828  if (detail::is_all_whitespace(line_str)) continue;
829 
830  line.str(line_str);
831  if (line.is_block_def())
832  {
833  if (++def_count > 1)
834  {
835  is.seekg(-line_str.length()-1, std::ios_base::cur);
836  break;
837  }
838  if (nameless)
839  {
840  name(line[1]);
841  nameless = false;
842  }
843  }
844  push_back(line);
845  }
846  return *this;
847  }
848 
861  Block&
862  str(const std::string& block)
863  {
864  std::istringstream input(block);
865  clear();
866  read(input);
867  return *this;
868  }
869 
871  std::string
872  str() const
873  {
874  std::ostringstream output;
875  output << *this;
876  return output.str();
877  }
878 
879  // element access
890  reference
891  operator[](const key_type& key)
892  {
893  iterator line = find(key);
894  if (line != end()) return *line;
895 
897  return back();
898  }
899 
911  reference
912  operator[](const std::vector<int>& key)
913  { return (*this)[cont_to_key(key)]; }
914 
924  reference
925  operator[](const std::string& key)
926  { return (*this)[key_type(1, key)]; }
927 
938  reference
939  operator[](int key)
940  { return (*this)[key_type(1, to_string(key))]; }
941 
952  reference
953  at(const key_type& key)
954  {
955  iterator line = find(key);
956  if (line != end()) return *line;
957 
958  throw std::out_of_range(
959  "SLHAea::Block::at(‘" + boost::join(key, ",") + "’)");
960  }
961 
973  at(const key_type& key) const
974  {
975  const_iterator line = find(key);
976  if (line != end()) return *line;
977 
978  throw std::out_of_range(
979  "SLHAea::Block::at(‘" + boost::join(key, ",") + "’)");
980  }
981 
992  reference
993  at(const std::vector<int>& key)
994  { return at(cont_to_key(key)); }
995 
1007  at(const std::vector<int>& key) const
1008  { return at(cont_to_key(key)); }
1009 
1022  reference
1023  at(const std::string& s0, const std::string& s1 = "",
1024  const std::string& s2 = "", const std::string& s3 = "",
1025  const std::string& s4 = "")
1026  { return at(strings_to_key(s0, s1, s2, s3, s4)); }
1027 
1041  at(const std::string& s0, const std::string& s1 = "",
1042  const std::string& s2 = "", const std::string& s3 = "",
1043  const std::string& s4 = "") const
1044  { return at(strings_to_key(s0, s1, s2, s3, s4)); }
1045 
1058  reference
1059  at(int i0, int i1 = no_index_, int i2 = no_index_,
1060  int i3 = no_index_, int i4 = no_index_)
1061  { return at(ints_to_key(i0, i1, i2, i3, i4)); }
1062 
1075  at(int i0, int i1 = no_index_, int i2 = no_index_,
1076  int i3 = no_index_, int i4 = no_index_) const
1077  { return at(ints_to_key(i0, i1, i2, i3, i4)); }
1078 
1083  reference
1085  { return impl_.front(); }
1086 
1092  front() const
1093  { return impl_.front(); }
1094 
1098  reference
1100  { return impl_.back(); }
1101 
1107  back() const
1108  { return impl_.back(); }
1109 
1110  // iterators
1115  iterator
1117  { return impl_.begin(); }
1118 
1125  begin() const
1126  { return impl_.begin(); }
1127 
1134  cbegin() const
1135  { return impl_.begin(); }
1136 
1142  iterator
1144  { return impl_.end(); }
1145 
1152  end() const
1153  { return impl_.end(); }
1154 
1161  cend() const
1162  { return impl_.end(); }
1163 
1171  { return impl_.rbegin(); }
1172 
1179  rbegin() const
1180  { return impl_.rbegin(); }
1181 
1188  crbegin() const
1189  { return impl_.rbegin(); }
1190 
1198  { return impl_.rend(); }
1199 
1206  rend() const
1207  { return impl_.rend(); }
1208 
1215  crend() const
1216  { return impl_.rend(); }
1217 
1218  // lookup
1231  iterator
1232  find(const key_type& key)
1233  { return std::find_if(begin(), end(), key_matches(key)); }
1234 
1248  find(const key_type& key) const
1249  { return std::find_if(begin(), end(), key_matches(key)); }
1250 
1264  template<class InputIterator> static InputIterator
1265  find(InputIterator first, InputIterator last, const key_type& key)
1266  { return std::find_if(first, last, key_matches(key)); }
1267 
1273  iterator
1275  {
1276  return std::find_if(begin(), end(),
1277  std::mem_fun_ref(&value_type::is_block_def));
1278  }
1279 
1287  {
1288  return std::find_if(begin(), end(),
1289  std::mem_fun_ref(&value_type::is_block_def));
1290  }
1291 
1292  // introspection
1298  size_type
1299  count(const key_type& key) const
1300  { return std::count_if(begin(), end(), key_matches(key)); }
1301 
1302  // capacity
1304  size_type
1305  size() const
1306  { return impl_.size(); }
1307 
1309  size_type
1310  data_size() const
1311  {
1312  return std::count_if(begin(), end(),
1313  std::mem_fun_ref(&value_type::is_data_line));
1314  }
1315 
1317  size_type
1318  max_size() const
1319  { return impl_.max_size(); }
1320 
1322  bool
1323  empty() const
1324  { return impl_.empty(); }
1325 
1326  // modifiers
1334  void
1335  push_back(const value_type& line)
1336  { impl_.push_back(line); }
1337 
1346  void
1347  push_back(const std::string& line)
1348  { impl_.push_back(value_type(line)); }
1349 
1354  void
1356  { impl_.pop_back(); }
1357 
1367  iterator
1368  insert(iterator position, const value_type& line)
1369  { return impl_.insert(position, line); }
1370 
1381  template<class InputIterator> void
1382  insert(iterator position, InputIterator first, InputIterator last)
1383  { impl_.insert(position, first, last); }
1384 
1393  iterator
1394  erase(iterator position)
1395  { return impl_.erase(position); }
1396 
1408  iterator
1409  erase(iterator first, iterator last)
1410  { return impl_.erase(first, last); }
1411 
1423  iterator
1424  erase_first(const key_type& key)
1425  {
1426  iterator line = find(key);
1427  return (line != end()) ? erase(line) : line;
1428  }
1429 
1441  iterator
1442  erase_last(const key_type& key)
1443  {
1444  reverse_iterator line = find(rbegin(), rend(), key);
1445  return (line != rend()) ? erase((++line).base()) : end();
1446  }
1447 
1457  size_type
1458  erase(const key_type& key)
1459  {
1460  const key_matches pred(key);
1461  size_type erased_count = 0;
1462 
1463  for (iterator line = begin(); line != end();)
1464  {
1465  if (pred(*line))
1466  {
1467  line = erase(line);
1468  ++erased_count;
1469  }
1470  else ++line;
1471  }
1472  return erased_count;
1473  }
1474 
1479  void
1480  swap(Block& block)
1481  {
1482  name_.swap(block.name_);
1483  impl_.swap(block.impl_);
1484  }
1485 
1490  void
1492  {
1493  name_.clear();
1494  impl_.clear();
1495  }
1496 
1501  void
1503  { std::for_each(begin(), end(), std::mem_fun_ref(&value_type::reformat)); }
1504 
1509  void
1511  { std::for_each(begin(), end(), std::mem_fun_ref(&value_type::comment)); }
1512 
1517  void
1519  { std::for_each(begin(), end(), std::mem_fun_ref(&value_type::uncomment)); }
1520 
1522  struct key_matches : public std::unary_function<value_type, bool>
1523  {
1524  explicit
1525  key_matches(const key_type& key) : key_(key) {}
1526 
1527  bool
1528  operator()(const value_type& line) const
1529  {
1530  return (key_.empty() || key_.size() > line.size()) ? false :
1531  std::equal(key_.begin(), key_.end(), line.begin(), parts_equal);
1532  }
1533 
1534  void
1535  set_key(const key_type& key)
1536  { key_ = key; }
1537 
1538  private:
1539  static bool
1540  parts_equal(const std::string& key_part, const std::string& field)
1541  { return (key_part == "(any)") || boost::iequals(key_part, field); }
1542 
1543  private:
1544  key_type key_;
1545  };
1546 
1547 private:
1548  template<class Container> static key_type
1549  cont_to_key(const Container& cont)
1550  {
1551  key_type key;
1552  key.reserve(cont.size());
1553  std::string (*to_string)(const typename Container::value_type&) =
1554  boost::lexical_cast<std::string, typename Container::value_type>;
1555  std::transform(cont.begin(), cont.end(), std::back_inserter(key),
1556  to_string);
1557  return key;
1558  }
1559 
1560  static key_type
1561  strings_to_key(const std::string& s0, const std::string& s1,
1562  const std::string& s2, const std::string& s3,
1563  const std::string& s4)
1564  {
1565  key_type key;
1566  key.reserve(5);
1567  if (s0.empty()) return key; key.push_back(s0);
1568  if (s1.empty()) return key; key.push_back(s1);
1569  if (s2.empty()) return key; key.push_back(s2);
1570  if (s3.empty()) return key; key.push_back(s3);
1571  if (s4.empty()) return key; key.push_back(s4);
1572  return key;
1573  }
1574 
1575  static key_type
1576  ints_to_key(int i0, int i1, int i2, int i3, int i4)
1577  {
1578  key_type key;
1579  key.reserve(5);
1580  if (i0 == no_index_) return key; key.push_back(to_string(i0));
1581  if (i1 == no_index_) return key; key.push_back(to_string(i1));
1582  if (i2 == no_index_) return key; key.push_back(to_string(i2));
1583  if (i3 == no_index_) return key; key.push_back(to_string(i3));
1584  if (i4 == no_index_) return key; key.push_back(to_string(i4));
1585  return key;
1586  }
1587 
1588 private:
1589  std::string name_;
1590  impl_type impl_;
1591  static const int no_index_ = -32768;
1592 };
1593 
1594 
1607 class Coll
1608 {
1609 private:
1610  typedef std::deque<Block> impl_type;
1611 
1612 public:
1613  typedef std::string key_type;
1615  typedef Block& reference;
1616  typedef const Block& const_reference;
1617  typedef impl_type::iterator iterator;
1618  typedef impl_type::const_iterator const_iterator;
1619  typedef impl_type::reverse_iterator reverse_iterator;
1620  typedef impl_type::const_reverse_iterator const_reverse_iterator;
1621  typedef impl_type::pointer pointer;
1622  typedef impl_type::const_pointer const_pointer;
1623  typedef impl_type::difference_type difference_type;
1624  typedef impl_type::size_type size_type;
1625 
1626  // NOTE: The compiler-generated copy constructor and assignment
1627  // operator for this class are just fine, so we don't need to
1628  // write our own.
1629 
1631  Coll() : impl_() {}
1632 
1638  explicit
1639  Coll(std::istream& is) : impl_()
1640  { read(is); }
1641 
1646  static Coll
1647  from_str(const std::string& coll)
1648  {
1649  std::istringstream input(coll);
1650  return Coll(input);
1651  }
1652 
1662  Coll&
1663  read(std::istream& is)
1664  {
1665  std::string line_str;
1666  Line line;
1667 
1668  const size_type orig_size = size();
1669  pointer block = push_back_named_block("");
1670 
1671  while (std::getline(is, line_str))
1672  {
1673  if (detail::is_all_whitespace(line_str)) continue;
1674 
1675  line.str(line_str);
1676  if (line.is_block_def()) block = push_back_named_block(line[1]);
1677  block->push_back(line);
1678  }
1679 
1680  erase_if_empty("", orig_size);
1681  return *this;
1682  }
1683 
1689  Coll&
1690  str(const std::string& coll)
1691  {
1692  std::istringstream input(coll);
1693  clear();
1694  read(input);
1695  return *this;
1696  }
1697 
1699  std::string
1700  str() const
1701  {
1702  std::ostringstream output;
1703  output << *this;
1704  return output.str();
1705  }
1706 
1707  // element access
1718  reference
1719  operator[](const key_type& blockName)
1720  {
1721  iterator block = find(blockName);
1722  if (block != end()) return *block;
1723 
1724  push_back(value_type(blockName));
1725  return back();
1726  }
1727 
1735  reference
1736  at(const key_type& blockName)
1737  {
1738  iterator block = find(blockName);
1739  if (block != end()) return *block;
1740 
1741  throw std::out_of_range("SLHAea::Coll::at(‘" + blockName + "’)");
1742  }
1743 
1752  at(const key_type& blockName) const
1753  {
1754  const_iterator block = find(blockName);
1755  if (block != end()) return *block;
1756 
1757  throw std::out_of_range("SLHAea::Coll::at(‘" + blockName + "’)");
1758  }
1759 
1773  reference
1775  {
1776  iterator block = find(key);
1777  if (block != end()) return *block;
1778 
1779  throw std::out_of_range(
1780  "SLHAea::Coll::at(‘" + boost::join(key, ",") + "’)");
1781  }
1782 
1797  at(const value_type::key_type& key) const
1798  {
1799  const_iterator block = find(key);
1800  if (block != end()) return *block;
1801 
1802  throw std::out_of_range(
1803  "SLHAea::Coll::at(‘" + boost::join(key, ",") + "’)");
1804  }
1805 
1809  reference
1811  { return impl_.front(); }
1812 
1818  front() const
1819  { return impl_.front(); }
1820 
1824  reference
1826  { return impl_.back(); }
1827 
1833  back() const
1834  { return impl_.back(); }
1835 
1836  // (nested) element access via Key
1844  reference
1845  block(const Key& key);
1846 
1856  block(const Key& key) const;
1857 
1865  line(const Key& key);
1866 
1875  line(const Key& key) const;
1876 
1885  field(const Key& key);
1886 
1896  field(const Key& key) const;
1897 
1898  // iterators
1903  iterator
1905  { return impl_.begin(); }
1906 
1913  begin() const
1914  { return impl_.begin(); }
1915 
1922  cbegin() const
1923  { return impl_.begin(); }
1924 
1930  iterator
1932  { return impl_.end(); }
1933 
1940  end() const
1941  { return impl_.end(); }
1942 
1949  cend() const
1950  { return impl_.end(); }
1951 
1958  { return impl_.rbegin(); }
1959 
1966  rbegin() const
1967  { return impl_.rbegin(); }
1968 
1975  crbegin() const
1976  { return impl_.rbegin(); }
1977 
1985  { return impl_.rend(); }
1986 
1993  rend() const
1994  { return impl_.rend(); }
1995 
2002  crend() const
2003  { return impl_.rend(); }
2004 
2005  // lookup
2017  iterator
2018  find(const key_type& blockName)
2019  { return std::find_if(begin(), end(), key_matches(blockName)); }
2020 
2033  find(const key_type& blockName) const
2034  { return std::find_if(begin(), end(), key_matches(blockName)); }
2035 
2049  template<class InputIterator> static InputIterator
2050  find(InputIterator first, InputIterator last, const key_type& blockName)
2051  { return std::find_if(first, last, key_matches(blockName)); }
2052 
2066  iterator
2068  { return std::find_if(begin(), end(), key_matches_block_def(key)); }
2069 
2084  find(const value_type::key_type& key) const
2085  { return std::find_if(begin(), end(), key_matches_block_def(key)); }
2086 
2102  template<class InputIterator> static InputIterator
2103  find(InputIterator first, InputIterator last,
2104  const value_type::key_type& key)
2105  { return std::find_if(first, last, key_matches_block_def(key)); }
2106 
2107  // introspection
2113  size_type
2114  count(const key_type& blockName) const
2115  { return std::count_if(begin(), end(), key_matches(blockName)); }
2116 
2117  // capacity
2119  size_type
2120  size() const
2121  { return impl_.size(); }
2122 
2124  size_type
2125  max_size() const
2126  { return impl_.max_size(); }
2127 
2129  bool
2130  empty() const
2131  { return impl_.empty(); }
2132 
2133  // modifiers
2141  void
2143  { impl_.push_back(block); }
2144 
2153  void
2154  push_back(const std::string& blockString)
2155  {
2156  value_type block;
2157  block.str(blockString);
2158  impl_.push_back(block);
2159  }
2160 
2168  void
2170  { impl_.push_front(block); }
2171 
2180  void
2181  push_front(const std::string& blockString)
2182  {
2183  value_type block;
2184  block.str(blockString);
2185  impl_.push_front(block);
2186  }
2187 
2192  void
2194  { impl_.pop_back(); }
2195 
2205  iterator
2206  insert(iterator position, const value_type& block)
2207  { return impl_.insert(position, block); }
2208 
2219  template<class InputIterator> void
2220  insert(iterator position, InputIterator first, InputIterator last)
2221  { impl_.insert(position, first, last); }
2222 
2231  iterator
2232  erase(iterator position)
2233  { return impl_.erase(position); }
2234 
2246  iterator
2247  erase(iterator first, iterator last)
2248  { return impl_.erase(first, last); }
2249 
2260  iterator
2261  erase_first(const key_type& blockName)
2262  {
2263  iterator block = find(blockName);
2264  return (block != end()) ? erase(block) : block;
2265  }
2266 
2277  iterator
2278  erase_last(const key_type& blockName)
2279  {
2280  reverse_iterator block = find(rbegin(), rend(), blockName);
2281  return (block != rend()) ? erase((++block).base()) : end();
2282  }
2283 
2289  size_type
2290  erase(const key_type& blockName)
2291  {
2292  const key_matches pred(blockName);
2293  size_type erased_count = 0;
2294 
2295  for (iterator block = begin(); block != end();)
2296  {
2297  if (pred(*block))
2298  {
2299  block = erase(block);
2300  ++erased_count;
2301  }
2302  else ++block;
2303  }
2304  return erased_count;
2305  }
2306 
2311  void
2312  swap(Coll& coll)
2313  { impl_.swap(coll.impl_); }
2314 
2316  void
2318  { impl_.clear(); }
2319 
2324  void
2326  { std::for_each(begin(), end(), std::mem_fun_ref(&value_type::reformat)); }
2327 
2332  void
2334  { std::for_each(begin(), end(), std::mem_fun_ref(&value_type::comment)); }
2335 
2340  void
2342  { std::for_each(begin(), end(), std::mem_fun_ref(&value_type::uncomment)); }
2343 
2348  struct key_matches : public std::unary_function<value_type, bool>
2349  {
2350  explicit
2351  key_matches(const key_type& blockName) : name_(blockName) {}
2352 
2353  bool
2355  { return boost::iequals(name_, block.name()); }
2356 
2357  void
2358  set_key(const key_type& blockName)
2359  { name_ = blockName; }
2360 
2361  private:
2362  key_type name_;
2363  };
2364 
2369  struct key_matches_block_def : public std::unary_function<value_type, bool>
2370  {
2371  explicit
2373  : key_matches_(key) {}
2374 
2375  bool
2377  {
2378  value_type::const_iterator block_def = block.find_block_def();
2379  return (block_def == block.end()) ? false : key_matches_(*block_def);
2380  }
2381 
2382  void
2384  { key_matches_.set_key(key); }
2385 
2386  private:
2387  value_type::key_matches key_matches_;
2388  };
2389 
2390 private:
2391  pointer
2392  push_back_named_block(const key_type& blockName)
2393  {
2394  push_back(value_type(blockName));
2395  return &back();
2396  }
2397 
2398  iterator
2399  erase_if_empty(const key_type& blockName, const size_type& offset = 0)
2400  {
2401  iterator block = find(begin() + offset, end(), blockName);
2402  return (block != end() && block->empty()) ? erase(block) : block;
2403  }
2404 
2405 private:
2406  impl_type impl_;
2407 };
2408 
2409 
2426 struct Key
2427 {
2428 public:
2431 
2434 
2437 
2444  Key(const Coll::key_type& _block,
2445  const Block::key_type& _line,
2446  const Line::size_type& _field)
2447  : block(_block), line(_line), field(_field) {}
2448 
2454  Key(const std::string& keyString)
2455  { str(keyString); }
2456 
2462  Key(const char* keyString)
2463  { str(keyString); }
2464 
2470  Key&
2471  str(const std::string& keyString)
2472  {
2473  std::vector<std::string> keys;
2474  boost::split(keys, keyString, boost::is_any_of(";"));
2475 
2476  if (keys.size() != 3)
2477  { throw std::invalid_argument("SLHAea::Key::str(‘" + keyString + "’)"); }
2478 
2479  block = keys[0];
2480  line.clear();
2481  boost::split(line, keys[1], boost::is_any_of(","));
2482  field = to<Line::size_type>(keys[2]);
2483 
2484  return *this;
2485  }
2486 
2491  std::string
2492  str() const
2493  {
2494  std::ostringstream output;
2495  output << block << ";" << boost::join(line, ",") << ";" << field;
2496  return output.str();
2497  }
2498 };
2499 
2500 
2501 inline Coll::reference
2502 Coll::block(const Key& key)
2503 { return at(key.block); }
2504 
2505 inline Coll::const_reference
2506 Coll::block(const Key& key) const
2507 { return at(key.block); }
2508 
2509 inline Block::reference
2510 Coll::line(const Key& key)
2511 { return block(key).at(key.line); }
2512 
2514 Coll::line(const Key& key) const
2515 { return block(key).at(key.line); }
2516 
2517 inline Line::reference
2518 Coll::field(const Key& key)
2519 { return line(key).at(key.field); }
2520 
2521 inline Line::const_reference
2522 Coll::field(const Key& key) const
2523 { return line(key).at(key.field); }
2524 
2525 
2526 // stream operators
2527 inline std::istream&
2528 operator>>(std::istream& is, Block& block)
2529 {
2530  block.read(is);
2531  return is;
2532 }
2533 
2534 inline std::istream&
2535 operator>>(std::istream& is, Coll& coll)
2536 {
2537  coll.read(is);
2538  return is;
2539 }
2540 
2541 inline std::ostream&
2542 operator<<(std::ostream& os, const Line& line)
2543 { return os << line.str(); }
2544 
2545 inline std::ostream&
2546 operator<<(std::ostream& os, const Block& block)
2547 {
2548  std::copy(block.begin(), block.end(),
2549  std::ostream_iterator<Block::value_type>(os, "\n"));
2550  return os;
2551 }
2552 
2553 inline std::ostream&
2554 operator<<(std::ostream& os, const Coll& coll)
2555 {
2556  std::copy(coll.begin(), coll.end(),
2557  std::ostream_iterator<Coll::value_type>(os));
2558  return os;
2559 }
2560 
2561 inline std::ostream&
2562 operator<<(std::ostream& os, const Key& key)
2563 { return os << key.str(); }
2564 
2565 
2566 // relational operators for Line
2567 inline bool
2568 operator==(const Line& a, const Line& b)
2569 {
2570  return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin())
2571  && a.str() == b.str();
2572 }
2573 
2574 inline bool
2575 operator<(const Line& a, const Line& b)
2576 {
2577  const bool a_is_block_def = a.is_block_def();
2578 
2579  return (a_is_block_def != b.is_block_def()) ? a_is_block_def :
2580  std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
2581 }
2582 
2583 inline bool
2584 operator!=(const Line& a, const Line& b)
2585 { return !(a == b); }
2586 
2587 inline bool
2588 operator>(const Line& a, const Line& b)
2589 { return b < a; }
2590 
2591 inline bool
2592 operator<=(const Line& a, const Line& b)
2593 { return !(b < a); }
2594 
2595 inline bool
2596 operator>=(const Line& a, const Line& b)
2597 { return !(a < b); }
2598 
2599 
2600 // relational operators for Block
2601 inline bool
2602 operator==(const Block& a, const Block& b)
2603 {
2604  return a.size() == b.size() && a.name() == b.name()
2605  && std::equal(a.begin(), a.end(), b.begin());
2606 }
2607 
2608 inline bool
2609 operator<(const Block& a, const Block& b)
2610 {
2611  return (a.name() != b.name()) ? a.name() < b.name() :
2612  std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
2613 }
2614 
2615 inline bool
2616 operator!=(const Block& a, const Block& b)
2617 { return !(a == b); }
2618 
2619 inline bool
2620 operator>(const Block& a, const Block& b)
2621 { return b < a; }
2622 
2623 inline bool
2624 operator<=(const Block& a, const Block& b)
2625 { return !(b < a); }
2626 
2627 inline bool
2628 operator>=(const Block& a, const Block& b)
2629 { return !(a < b); }
2630 
2631 
2632 // relational operators for Coll
2633 inline bool
2634 operator==(const Coll& a, const Coll& b)
2635 { return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin()); }
2636 
2637 inline bool
2638 operator<(const Coll& a, const Coll& b)
2639 {
2640  return std::lexicographical_compare(a.begin(), a.end(),
2641  b.begin(), b.end());
2642 }
2643 
2644 inline bool
2645 operator!=(const Coll& a, const Coll& b)
2646 { return !(a == b); }
2647 
2648 inline bool
2649 operator>(const Coll& a, const Coll& b)
2650 { return b < a; }
2651 
2652 inline bool
2653 operator<=(const Coll& a, const Coll& b)
2654 { return !(b < a); }
2655 
2656 inline bool
2657 operator>=(const Coll& a, const Coll& b)
2658 { return !(a < b); }
2659 
2660 } // namespace SLHAea
2661 
2662 #endif // SLHAEA_H
size_type max_size() const
Returns the size() of the largest possible Block.
Definition: slhaea.h:1318
const_reference operator[](size_type n) const
Subscript access to the strings contained in the Line.
Definition: slhaea.h:340
key_matches(const key_type &key)
Definition: slhaea.h:1525
const Block & const_reference
Definition: slhaea.h:1616
size_type size() const
Returns the number of elements in the Block.
Definition: slhaea.h:1305
iterator insert(iterator position, const value_type &block)
Inserts a Block before given position.
Definition: slhaea.h:2206
reference at(size_type n)
Provides access to the strings contained in the Line.
Definition: slhaea.h:350
iterator erase(iterator first, iterator last)
Erases a range of elements.
Definition: slhaea.h:2247
void push_front(const std::string &blockString)
Adds a Block to the begin of the Coll.
Definition: slhaea.h:2181
Line & append(const std::string &arg)
Appends a string to the end of the Line.
Definition: slhaea.h:244
impl_type::reverse_iterator reverse_iterator
Definition: slhaea.h:1619
const_iterator begin() const
Returns a read-only (constant) iterator that points to the first element in the Line.
Definition: slhaea.h:408
const_iterator begin() const
Returns a read-only (constant) iterator that points to the first element in the Coll.
Definition: slhaea.h:1913
Coll & str(const std::string &coll)
Assigns content from a string to the Coll.
Definition: slhaea.h:1690
Line value_type
Definition: slhaea.h:731
void push_back(const value_type &block)
Adds a Block to the end of the Coll.
Definition: slhaea.h:2142
const_reverse_iterator crend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the Co...
Definition: slhaea.h:2002
const_reference at(const std::string &s0, const std::string &s1="", const std::string &s2="", const std::string &s3="", const std::string &s4="") const
Locates a Line in the Block.
Definition: slhaea.h:1041
static Block from_str(const std::string &block)
Constructs a Block with content from a string.
Definition: slhaea.h:768
reference operator[](const std::vector< int > &key)
Locates a Line in the Block.
Definition: slhaea.h:912
void push_back(const std::string &blockString)
Adds a Block to the end of the Coll.
Definition: slhaea.h:2154
void swap(Line &line)
Swaps data with another Line.
Definition: slhaea.h:556
const_reference front() const
Returns a read-only (constant) reference to the first element of the Coll.
Definition: slhaea.h:1818
void clear()
Erases all the elements in the Line.
Definition: slhaea.h:564
iterator erase(iterator position)
Erases element at given position.
Definition: slhaea.h:1394
impl_type::difference_type difference_type
Definition: slhaea.h:1623
reference back()
Returns a read/write reference to the last element of the Block.
Definition: slhaea.h:1099
impl_type::iterator iterator
Definition: slhaea.h:1617
bool operator()(const value_type &line) const
Definition: slhaea.h:1528
reference block(const Key &key)
Accesses a Block in the Coll.
Definition: slhaea.h:2502
std::string str() const
Returns a formatted string representation of the Line.
Definition: slhaea.h:297
void rename(const std::string &newName)
Changes the name and definition of the Block.
Definition: slhaea.h:798
bool is_block_def() const
Returns true if the Line begins with "BLOCK" or "DECAY" followed by a block name. ...
Definition: slhaea.h:506
reference operator[](size_type n)
Subscript access to the strings contained in the Line.
Definition: slhaea.h:327
void set_key(const key_type &key)
Definition: slhaea.h:1535
const_reference back() const
Returns a read-only (constant) reference to the last element of the Block.
Definition: slhaea.h:1107
std::string str() const
Returns a string representation of the Block.
Definition: slhaea.h:872
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Coll...
Definition: slhaea.h:1984
iterator begin()
Returns a read/write iterator that points to the first element in the Block.
Definition: slhaea.h:1116
iterator begin()
Returns a read/write iterator that points to the first element in the Coll.
Definition: slhaea.h:1904
reference at(const std::vector< int > &key)
Locates a Line in the Block.
Definition: slhaea.h:993
Block & read(std::istream &is)
Assigns content from an input stream to the Block.
Definition: slhaea.h:818
iterator find_block_def()
Returns a read/write iterator that points to the first Line in the Block which is a block definition...
Definition: slhaea.h:1274
impl_type::iterator iterator
Definition: slhaea.h:155
impl_type::reverse_iterator reverse_iterator
Definition: slhaea.h:157
bool operator<(const Line &a, const Line &b)
Definition: slhaea.h:2575
std::ostream & operator<<(std::ostream &os, const Line &line)
Definition: slhaea.h:2542
impl_type::const_reverse_iterator const_reverse_iterator
Definition: slhaea.h:1620
const_reference at(const key_type &blockName) const
Locates a Block in the Coll.
Definition: slhaea.h:1752
std::string value_type
Definition: slhaea.h:152
const Line & const_reference
Definition: slhaea.h:733
Line::size_type field
Index of the field in the Line.
Definition: slhaea.h:2436
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Coll.
Definition: slhaea.h:1957
iterator erase(iterator position)
Erases element at given position.
Definition: slhaea.h:2232
reference operator[](int key)
Locates a Line in the Block.
Definition: slhaea.h:939
void swap(Block &block)
Swaps data with another Block.
Definition: slhaea.h:1480
bool operator!=(const Line &a, const Line &b)
Definition: slhaea.h:2584
const_reverse_iterator crbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the Block...
Definition: slhaea.h:1188
reference operator[](const key_type &blockName)
Locates a Block in the Coll.
Definition: slhaea.h:1719
const_reverse_iterator rbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the Line...
Definition: slhaea.h:461
const_iterator find_block_def() const
Returns a read-only (constant) iterator that points to the first Line in the Block which is a block d...
Definition: slhaea.h:1286
const_reference back() const
Returns a read-only (constant) reference to the last element of the Coll.
Definition: slhaea.h:1833
Container of strings that represents a line in a SLHA structure.
Definition: slhaea.h:146
const_iterator find(const key_type &key) const
Tries to locate a Line in the Block.
Definition: slhaea.h:1248
impl_type::pointer pointer
Definition: slhaea.h:1621
impl_type::size_type size_type
Definition: slhaea.h:741
iterator find(const key_type &blockName)
Tries to locate a Block in the Coll.
Definition: slhaea.h:2018
void trim_left(std::string &str)
Definition: slhaea.h:95
bool is_comment_line() const
Returns true if the Line begins with "#".
Definition: slhaea.h:516
static InputIterator find(InputIterator first, InputIterator last, const key_type &blockName)
Tries to locate a Block in a range.
Definition: slhaea.h:2050
Key(const std::string &keyString)
Constructs a Key from a string.
Definition: slhaea.h:2454
const_reference at(const value_type::key_type &key) const
Locates a Block in the Coll.
Definition: slhaea.h:1797
size_type max_size() const
Returns the size() of the largest possible Line.
Definition: slhaea.h:542
void uncomment()
Uncomments all Blocks in the Coll.
Definition: slhaea.h:2341
bool operator>(const Line &a, const Line &b)
Definition: slhaea.h:2588
void clear()
Erases all the elements in the Coll.
Definition: slhaea.h:2317
Line()
Constructs an empty Line.
Definition: slhaea.h:169
size_type erase(const key_type &blockName)
Erases all Blocks with a given name.
Definition: slhaea.h:2290
const_iterator cbegin() const
Returns a read-only (constant) iterator that points to the first element in the Line.
Definition: slhaea.h:417
std::vector< std::string > key_type
Definition: slhaea.h:730
Container of Lines that resembles a block in a SLHA structure.
Definition: slhaea.h:724
Block & str(const std::string &block)
Assigns content from a string to the Block.
Definition: slhaea.h:862
impl_type::size_type size_type
Definition: slhaea.h:1624
size_type max_size() const
Returns the size() of the largest possible Coll.
Definition: slhaea.h:2125
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Line...
Definition: slhaea.h:479
impl_type::difference_type difference_type
Definition: slhaea.h:740
const_reference front() const
Returns a read-only (constant) reference to the first element of the Line.
Definition: slhaea.h:375
Coll(std::istream &is)
Constructs a Coll with content from an input stream.
Definition: slhaea.h:1639
void pop_back()
Removes the last element.
Definition: slhaea.h:2193
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Block.
Definition: slhaea.h:1170
size_type size() const
Returns the number of elements in the Coll.
Definition: slhaea.h:2120
void uncomment()
Uncomments all Lines in the Block.
Definition: slhaea.h:1518
reference front()
Returns a read/write reference to the first element of the Coll.
Definition: slhaea.h:1810
impl_type::const_pointer const_pointer
Definition: slhaea.h:1622
size_type erase(const key_type &key)
Erases all Lines that match the provided key.
Definition: slhaea.h:1458
static InputIterator find(InputIterator first, InputIterator last, const key_type &key)
Tries to locate a Line in a range.
Definition: slhaea.h:1265
size_type count(const key_type &key) const
Counts all Lines that match a given key.
Definition: slhaea.h:1299
Reference to a single field in a SLHA structure.
Definition: slhaea.h:2426
bool empty() const
Returns true if the Block is empty.
Definition: slhaea.h:1323
impl_type::reverse_iterator reverse_iterator
Definition: slhaea.h:736
bool is_data_line() const
Returns true if the Line is not empty and if it does not begin with "#", "BLOCK" or "DECAY"...
Definition: slhaea.h:524
iterator erase_last(const key_type &blockName)
Erases last Block with a given name.
Definition: slhaea.h:2278
impl_type::difference_type difference_type
Definition: slhaea.h:161
const_iterator cend() const
Returns a read-only (constant) iterator that points one past the last element in the Line...
Definition: slhaea.h:444
const_reverse_iterator rend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the Bl...
Definition: slhaea.h:1206
void insert(iterator position, InputIterator first, InputIterator last)
Inserts a range into the Coll.
Definition: slhaea.h:2220
void trim_right(std::string &str)
Definition: slhaea.h:103
const_reverse_iterator rbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the Coll...
Definition: slhaea.h:1966
Line & str(const std::string &line)
Assigns content to the Line based on a string.
Definition: slhaea.h:263
iterator erase_last(const key_type &key)
Erases last Line that matches the provided key.
Definition: slhaea.h:1442
Target to(const Source &arg)
Converts an object of type Source to an object of type Target.
Definition: slhaea.h:44
const_iterator cbegin() const
Returns a read-only (constant) iterator that points to the first element in the Block.
Definition: slhaea.h:1134
void push_back(const std::string &line)
Adds a Line to the end of the Block.
Definition: slhaea.h:1347
Key(const char *keyString)
Constructs a Key from a string.
Definition: slhaea.h:2462
const_reverse_iterator crend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the Bl...
Definition: slhaea.h:1215
iterator find(const value_type::key_type &key)
Tries to locate a Block in the Coll.
Definition: slhaea.h:2067
impl_type::const_iterator const_iterator
Definition: slhaea.h:156
size_type data_size() const
Returns the number of elements without the comment in the Line.
Definition: slhaea.h:537
std::string to_string(const Source &arg)
Converts an object of type Source to a string.
Definition: slhaea.h:56
bool operator>=(const Line &a, const Line &b)
Definition: slhaea.h:2596
reference operator[](const std::string &key)
Locates a Line in the Block.
Definition: slhaea.h:925
reference at(const value_type::key_type &key)
Locates a Block in the Coll.
Definition: slhaea.h:1774
void set_key(const key_type &blockName)
Definition: slhaea.h:2358
const_reverse_iterator crbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the Line...
Definition: slhaea.h:470
const_reference front() const
Returns a read-only (constant) reference to the first element of the Block.
Definition: slhaea.h:1092
reference at(const key_type &key)
Locates a Line in the Block.
Definition: slhaea.h:953
Line & reference
Definition: slhaea.h:732
void uncomment()
Uncomments the Line.
Definition: slhaea.h:628
std::string to_upper_copy(const std::string &str)
Definition: slhaea.h:86
static Coll from_str(const std::string &coll)
Constructs a Coll with content from a string.
Definition: slhaea.h:1647
const_reference at(const key_type &key) const
Locates a Line in the Block.
Definition: slhaea.h:973
impl_type::pointer pointer
Definition: slhaea.h:738
void push_back(const value_type &line)
Adds a Line to the end of the Block.
Definition: slhaea.h:1335
key_matches(const key_type &blockName)
Definition: slhaea.h:2351
size_type count(const key_type &blockName) const
Counts all Blocks with a given name.
Definition: slhaea.h:2114
void pop_back()
Removes the last element.
Definition: slhaea.h:1355
iterator erase(iterator first, iterator last)
Erases a range of elements.
Definition: slhaea.h:1409
const std::string & const_reference
Definition: slhaea.h:154
Coll & read(std::istream &is)
Assigns content from an input stream to the Coll.
Definition: slhaea.h:1663
const_iterator end() const
Returns a read-only (constant) iterator that points one past the last element in the Block...
Definition: slhaea.h:1152
impl_type::const_pointer const_pointer
Definition: slhaea.h:160
std::istream & operator>>(std::istream &is, Block &block)
Definition: slhaea.h:2528
const_reverse_iterator crend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the Li...
Definition: slhaea.h:497
Block value_type
Definition: slhaea.h:1614
void reformat()
Reformats all Blocks in the Coll.
Definition: slhaea.h:2325
Block::reference line(const Key &key)
Accesses a single Line in the Coll.
Definition: slhaea.h:2510
const_reference at(size_type n) const
Provides access to the strings contained in the Line.
Definition: slhaea.h:360
impl_type::size_type size_type
Definition: slhaea.h:162
const_reverse_iterator crbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the Coll...
Definition: slhaea.h:1975
iterator end()
Returns a read/write iterator that points one past the last element in the Block. ...
Definition: slhaea.h:1143
Unary predicate that checks if a provided key matches a Line.
Definition: slhaea.h:1522
iterator insert(iterator position, const value_type &line)
Inserts a Line before given position.
Definition: slhaea.h:1368
void set_key(const value_type::key_type &key)
Definition: slhaea.h:2383
iterator begin()
Returns a read/write iterator that points to the first element in the Line.
Definition: slhaea.h:399
Coll()
Constructs an empty Coll.
Definition: slhaea.h:1631
bool operator<=(const Line &a, const Line &b)
Definition: slhaea.h:2592
void swap(Coll &coll)
Swaps data with another Coll.
Definition: slhaea.h:2312
const_iterator end() const
Returns a read-only (constant) iterator that points one past the last element in the Coll...
Definition: slhaea.h:1940
iterator end()
Returns a read/write iterator that points one past the last element in the Coll.
Definition: slhaea.h:1931
void comment()
Comments all Lines in the Block.
Definition: slhaea.h:1510
key_matches_block_def(const value_type::key_type &key)
Definition: slhaea.h:2372
const std::string & name() const
Returns the name of the Block.
Definition: slhaea.h:787
reference at(const key_type &blockName)
Locates a Block in the Coll.
Definition: slhaea.h:1736
impl_type::const_reverse_iterator const_reverse_iterator
Definition: slhaea.h:737
iterator end()
Returns a read/write iterator that points one past the last element in the Line.
Definition: slhaea.h:426
Line & operator<<(const T &field)
Inserts an element at the end of the Line.
Definition: slhaea.h:217
Block & reference
Definition: slhaea.h:1615
impl_type::const_iterator const_iterator
Definition: slhaea.h:735
const_reverse_iterator rend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the Li...
Definition: slhaea.h:488
const_iterator begin() const
Returns a read-only (constant) iterator that points to the first element in the Block.
Definition: slhaea.h:1125
const_iterator cend() const
Returns a read-only (constant) iterator that points one past the last element in the Coll...
Definition: slhaea.h:1949
impl_type::const_iterator const_iterator
Definition: slhaea.h:1618
void name(const std::string &newName)
Sets the name of the Block.
Definition: slhaea.h:782
Key & str(const std::string &keyString)
Converts a string to a Key.
Definition: slhaea.h:2471
reference back()
Returns a read/write reference to the last element of the Coll.
Definition: slhaea.h:1825
bool empty() const
Returns true if the Line is empty.
Definition: slhaea.h:547
const_reference at(int i0, int i1=no_index_, int i2=no_index_, int i3=no_index_, int i4=no_index_) const
Locates a Line in the Block.
Definition: slhaea.h:1075
std::string & reference
Definition: slhaea.h:153
reference front()
Returns a read/write reference to the first element of the Line.
Definition: slhaea.h:367
void clear()
Erases all the elements in the Block and set its name to an empty string.
Definition: slhaea.h:1491
Coll::key_type block
Name of the Block that contains the field.
Definition: slhaea.h:2430
impl_type::const_reverse_iterator const_reverse_iterator
Definition: slhaea.h:158
Unary predicate that checks if a provided name matches the name of a Block.
Definition: slhaea.h:2348
Line(const std::string &line)
Constructs a Line from a string.
Definition: slhaea.h:176
reference back()
Returns a read/write reference to the last element of the Line.
Definition: slhaea.h:382
iterator erase_first(const key_type &key)
Erases first Line that matches the provided key.
Definition: slhaea.h:1424
void comment()
Comments all Blocks in the Coll.
Definition: slhaea.h:2333
static InputIterator find(InputIterator first, InputIterator last, const value_type::key_type &key)
Tries to locate a Block in a range.
Definition: slhaea.h:2103
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Block...
Definition: slhaea.h:1197
bool operator==(const Line &a, const Line &b)
Definition: slhaea.h:2568
reference at(int i0, int i1=no_index_, int i2=no_index_, int i3=no_index_, int i4=no_index_)
Locates a Line in the Block.
Definition: slhaea.h:1059
Block(const std::string &name="")
Constructs an empty Block.
Definition: slhaea.h:752
iterator find(const key_type &key)
Tries to locate a Line in the Block.
Definition: slhaea.h:1232
Block(std::istream &is)
Constructs a Block with content from an input stream.
Definition: slhaea.h:760
void insert(iterator position, InputIterator first, InputIterator last)
Inserts a range into the Block.
Definition: slhaea.h:1382
Line & operator+=(const std::string &arg)
Appends a string to the end of the Line.
Definition: slhaea.h:201
Key(const Coll::key_type &_block, const Block::key_type &_line, const Line::size_type &_field)
Constructs a Key from explicit key values.
Definition: slhaea.h:2444
Block::key_type line
First field(s) of the Line that contains the field.
Definition: slhaea.h:2433
bool operator()(const value_type &block) const
Definition: slhaea.h:2376
bool is_all_whitespace(const std::string &str)
Definition: slhaea.h:82
const_reverse_iterator rend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the Co...
Definition: slhaea.h:1993
Line::reference field(const Key &key)
Accesses a single field in the Coll.
Definition: slhaea.h:2518
void push_front(const value_type &block)
Adds a Block to the begin of the Coll.
Definition: slhaea.h:2169
const_reference at(const std::vector< int > &key) const
Locates a Line in the Block.
Definition: slhaea.h:1007
void reformat()
Reformats the string representation of the Line.
Definition: slhaea.h:572
const_iterator find(const key_type &blockName) const
Tries to locate a Block in the Coll.
Definition: slhaea.h:2033
std::string key_type
Definition: slhaea.h:1613
size_type size() const
Returns the number of elements in the Line.
Definition: slhaea.h:530
const_iterator cend() const
Returns a read-only (constant) iterator that points one past the last element in the Block...
Definition: slhaea.h:1161
const_iterator cbegin() const
Returns a read-only (constant) iterator that points to the first element in the Coll.
Definition: slhaea.h:1922
void reformat()
Reformats all Lines in the Block.
Definition: slhaea.h:1502
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Line.
Definition: slhaea.h:452
std::string str() const
Returns a string representation of the Coll.
Definition: slhaea.h:1700
size_type data_size() const
Returns the number of data Lines in the Block.
Definition: slhaea.h:1310
const_iterator find(const value_type::key_type &key) const
Tries to locate a Block in the Coll.
Definition: slhaea.h:2084
Unary predicate that checks if a provided key matches the block definition of a Block.
Definition: slhaea.h:2369
bool operator()(const value_type &block) const
Definition: slhaea.h:2354
Container of Blocks that resembles a complete SLHA structure.
Definition: slhaea.h:1607
const_iterator end() const
Returns a read-only (constant) iterator that points one past the last element in the Line...
Definition: slhaea.h:435
impl_type::const_pointer const_pointer
Definition: slhaea.h:739
iterator erase_first(const key_type &blockName)
Erases first Block with a given name.
Definition: slhaea.h:2261
reference operator[](const key_type &key)
Locates a Line in the Block.
Definition: slhaea.h:891
void comment()
Comments the Line.
Definition: slhaea.h:619
Line & operator=(const std::string &line)
Assigns content from a string to the Line.
Definition: slhaea.h:187
bool empty() const
Returns true if the Coll is empty.
Definition: slhaea.h:2130
impl_type::iterator iterator
Definition: slhaea.h:734
impl_type::pointer pointer
Definition: slhaea.h:159
const_reverse_iterator rbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the Block...
Definition: slhaea.h:1179
reference front()
Returns a read/write reference to the first element of the Block.
Definition: slhaea.h:1084
reference at(const std::string &s0, const std::string &s1="", const std::string &s2="", const std::string &s3="", const std::string &s4="")
Locates a Line in the Block.
Definition: slhaea.h:1023
std::string str() const
Converts a Key into its string representation.
Definition: slhaea.h:2492
const_reference back() const
Returns a read-only (constant) reference to the last element of the Line.
Definition: slhaea.h:390