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

Class DitherPatternIndexConverter

src/laybasic/laybasic/layLayerProperties.cc:1732–1764  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1730 * @brief A helper class for XML parser: convert a string to a integer index and vice versa
1731 */
1732struct DitherPatternIndexConverter
1733{
1734 std::string to_string (int b) const
1735 {
1736 if (b < 0) {
1737 return "";
1738 } else if (b < std::distance (lay::DitherPattern::default_pattern ().begin (), lay::DitherPattern::default_pattern ().begin_custom ())) {
1739 // intrinsic pattern
1740 return "I" + tl::to_string (b);
1741 } else {
1742 // custom pattern
1743 return "C" + tl::to_string (b - std::distance (lay::DitherPattern::default_pattern ().begin (), lay::DitherPattern::default_pattern ().begin_custom ()));
1744 }
1745 }
1746
1747 void from_string (const std::string &s, int &b) const
1748 {
1749 if (s.empty ()) {
1750 b = -1;
1751 } else if (s[0] == 'I') {
1752 tl::from_string (s.c_str () + 1, b);
1753 } else if (s[0] == 'C') {
1754 tl::from_string (s.c_str () + 1, b);
1755 b = b + std::distance (lay::DitherPattern::default_pattern ().begin (), lay::DitherPattern::default_pattern ().begin_custom ());
1756 } else {
1757 tl::from_string (s, b);
1758 if (b >= 16) {
1759 // backward compatibility to older versions
1760 b = b - 16 + std::distance (lay::DitherPattern::default_pattern ().begin (), lay::DitherPattern::default_pattern ().begin_custom ());
1761 }
1762 }
1763 }
1764};
1765
1766/**
1767 * @brief A helper class for XML parser: convert a style string to a integer index and vice versa

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected