Mercurial > octave-nkf
comparison src/graphics.cc @ 9185:1e5c11890f85
check for invalid property names when setting defaults
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 May 2009 15:14:19 -0400 |
parents | 86ae7e50dc5d |
children | 0ae2b6617005 |
comparison
equal
deleted
inserted
replaced
9184:9861b3ec72a6 | 9185:1e5c11890f85 |
---|---|
1168 std::string pname = name.substr (offset); | 1168 std::string pname = name.substr (offset); |
1169 | 1169 |
1170 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); | 1170 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
1171 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); | 1171 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
1172 | 1172 |
1173 bool remove = false; | 1173 bool has_property = false; |
1174 if (val.is_string ()) | 1174 if (pfx == "axes") |
1175 { | 1175 has_property = axes::properties::has_property (pname); |
1176 caseless_str tval = val.string_value (); | 1176 else if (pfx == "line") |
1177 | 1177 has_property = line::properties::has_property (pname); |
1178 remove = tval.compare ("remove"); | 1178 else if (pfx == "text") |
1179 } | 1179 has_property = text::properties::has_property (pname); |
1180 | 1180 else if (pfx == "image") |
1181 pval_map_type& pval_map = plist_map[pfx]; | 1181 has_property = image::properties::has_property (pname); |
1182 | 1182 else if (pfx == "patch") |
1183 if (remove) | 1183 has_property = patch::properties::has_property (pname); |
1184 { | 1184 else if (pfx == "figure") |
1185 pval_map_iterator p = pval_map.find (pname); | 1185 has_property = figure::properties::has_property (pname); |
1186 | 1186 else if (pfx == "surface") |
1187 if (p != pval_map.end ()) | 1187 has_property = surface::properties::has_property (pname); |
1188 pval_map.erase (p); | 1188 else if (pfx == "hggroup") |
1189 has_property = hggroup::properties::has_property (pname); | |
1190 | |
1191 if (has_property) | |
1192 { | |
1193 bool remove = false; | |
1194 if (val.is_string ()) | |
1195 { | |
1196 caseless_str tval = val.string_value (); | |
1197 | |
1198 remove = tval.compare ("remove"); | |
1199 } | |
1200 | |
1201 pval_map_type& pval_map = plist_map[pfx]; | |
1202 | |
1203 if (remove) | |
1204 { | |
1205 pval_map_iterator p = pval_map.find (pname); | |
1206 | |
1207 if (p != pval_map.end ()) | |
1208 pval_map.erase (p); | |
1209 } | |
1210 else | |
1211 pval_map[pname] = val; | |
1189 } | 1212 } |
1190 else | 1213 else |
1191 pval_map[pname] = val; | 1214 error ("invalid %s property `%s'", pfx.c_str (), pname.c_str ()); |
1192 } | 1215 } |
1193 } | 1216 } |
1194 | 1217 |
1195 if (offset == 0) | 1218 if (! error_state && offset == 0) |
1196 error ("invalid default property specification"); | 1219 error ("invalid default property specification"); |
1197 } | 1220 } |
1198 | 1221 |
1199 octave_value | 1222 octave_value |
1200 property_list::lookup (const caseless_str& name) const | 1223 property_list::lookup (const caseless_str& name) const |
1701 m.assign (it->second.get_name (), it->second.get ()); | 1724 m.assign (it->second.get_name (), it->second.get ()); |
1702 | 1725 |
1703 return m; | 1726 return m; |
1704 } | 1727 } |
1705 | 1728 |
1706 void | 1729 std::map<std::string, std::set<std::string> > base_properties::all_dynamic_properties; |
1707 base_properties::set_dynamic (const caseless_str& name, const octave_value& val) | 1730 |
1708 { | 1731 bool |
1709 std::map<caseless_str, property, cmp_caseless_str>::iterator it = all_props.find (name); | 1732 base_properties::has_dynamic_property (const std::string& pname, |
1733 const std::string& cname) | |
1734 { | |
1735 // FIXME -- we need to maintain a static map of class names to sets | |
1736 // of dynamic property names, then look up the set for the given | |
1737 // cname, then see if the set contains the given pname. Doing that | |
1738 // implies changes to set_dynamic, I think. Where is set_dynamic | |
1739 // ever used? | |
1740 | |
1741 std::set<std::string>& dynprops = all_dynamic_properties[cname]; | |
1742 | |
1743 return dynprops.find (pname) != dynprops.end (); | |
1744 } | |
1745 | |
1746 void | |
1747 base_properties::set_dynamic (const caseless_str& pname, | |
1748 const std::string& cname, | |
1749 const octave_value& val) | |
1750 { | |
1751 std::map<caseless_str, property, cmp_caseless_str>::iterator it = all_props.find (pname); | |
1710 | 1752 |
1711 if (it != all_props.end ()) | 1753 if (it != all_props.end ()) |
1712 it->second.set (val); | 1754 it->second.set (val); |
1713 else | 1755 else |
1714 error ("set: unknown property \"%s\"", name.c_str ()); | 1756 error ("set: unknown property \"%s\"", pname.c_str ()); |
1715 | 1757 |
1716 if (! error_state) | 1758 if (! error_state) |
1717 mark_modified (); | 1759 { |
1760 all_dynamic_properties[cname].insert (pname); | |
1761 | |
1762 mark_modified (); | |
1763 } | |
1718 } | 1764 } |
1719 | 1765 |
1720 property | 1766 property |
1721 base_properties::get_property_dynamic (const caseless_str& name) | 1767 base_properties::get_property_dynamic (const caseless_str& name) |
1722 { | 1768 { |