MCPcopy Create free account
hub / github.com/KLayout/klayout / LineStyleIndexConverter

Class LineStyleIndexConverter

src/laybasic/laybasic/layLayerProperties.cc:1769–1801  ·  view source on GitHub ↗

* @brief A helper class for XML parser: convert a style string to a integer index and vice versa */

Source from the content-addressed store, hash-verified

1767 * @brief A helper class for XML parser: convert a style string to a integer index and vice versa
1768 */
1769struct LineStyleIndexConverter
1770{
1771 std::string to_string (int b) const
1772 {
1773 if (b < 0) {
1774 return "";
1775 } else if (b < std::distance (lay::LineStyles::default_style ().begin (), lay::LineStyles::default_style ().begin_custom ())) {
1776 // intrinsic pattern
1777 return "I" + tl::to_string (b);
1778 } else {
1779 // custom pattern
1780 return "C" + tl::to_string (b - std::distance (lay::LineStyles::default_style ().begin (), lay::LineStyles::default_style ().begin_custom ()));
1781 }
1782 }
1783
1784 void from_string (const std::string &s, int &b) const
1785 {
1786 if (s.empty ()) {
1787 b = -1;
1788 } else if (s[0] == 'I') {
1789 tl::from_string (s.c_str () + 1, b);
1790 } else if (s[0] == 'C') {
1791 tl::from_string (s.c_str () + 1, b);
1792 b = b + std::distance (lay::LineStyles::default_style ().begin (), lay::LineStyles::default_style ().begin_custom ());
1793 } else {
1794 tl::from_string (s, b);
1795 if (b >= 16) {
1796 // backward compatibility to older versions
1797 b = b - 16 + std::distance (lay::LineStyles::default_style ().begin (), lay::LineStyles::default_style ().begin_custom ());
1798 }
1799 }
1800 }
1801};
1802
1803static const tl::XMLElementList layer_element = tl::XMLElementList (
1804 // HINT: these make_member calls want to be qualified: otherwise an internal error

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected