| 30 | #include <map> |
| 31 | |
| 32 | #if defined(TRACE_PROBLEMATIC_AWAR_USAGE) |
| 33 | |
| 34 | typedef std::map<std::string, std::string> AwarMapping; |
| 35 | typedef std::map<std::string, UsedInWidget> AwarUsage; |
| 36 | |
| 37 | static AwarMapping amap; |
| 38 | static AwarUsage usage; |
| 39 | |
| 40 | static void track_awars_mapped_with(std::string awar_name); |
| 41 | static void combine_awar_usage(std::string awar_name1, std::string awar_name2); |
| 42 | static void track_problematic_awar_usage_byname(std::string awar_name, UsedInWidget where) { |
| 43 | aw_assert(where != UIW_BOTH); |
| 44 | fprintf(stderr, "track_problematic_awar_usage_byname('%s', %i) [start]\n", awar_name.c_str(), int(where)); |
| 45 | |
| 46 | AwarUsage::iterator found = usage.find(awar_name); |
| 47 | if (found == usage.end()) { |
| 48 | usage[awar_name] = where; |
| 49 | track_awars_mapped_with(awar_name); |
| 50 | } |
| 51 | else { |
| 52 | if (found->second != where) { |
| 53 | if (found->second != UIW_BOTH) { |
| 54 | // detected problematic use of awar! (used in selection list and in input field) |
| 55 | usage[awar_name] = UIW_BOTH; |
| 56 | aw_assert(0); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | fprintf(stderr, "track_problematic_awar_usage_byname('%s', %i) [end]\n", awar_name.c_str(), int(where)); |
| 61 | } |
| 62 | static void combine_awar_usage(std::string awar_name1, std::string awar_name2) { |
| 63 | aw_assert(awar_name1 != awar_name2); |
| 64 | |
| 65 | AwarUsage::iterator found1 = usage.find(awar_name1); |
| 66 | AwarUsage::iterator found2 = usage.find(awar_name2); |
| 67 | |
| 68 | fprintf(stderr, "combine_awar_usage('%s', '%s') [start]\n", awar_name1.c_str(), awar_name2.c_str()); |
| 69 | |
| 70 | if (found1 == usage.end()) { |
| 71 | if (found2 == usage.end()) { |
| 72 | ; |
| 73 | } |
| 74 | else { // awar_name2 already tracked |
| 75 | if (found2->second != UIW_BOTH) { // do not warn twice |
| 76 | track_problematic_awar_usage_byname(awar_name1, found2->second); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | else { |
| 81 | if (found2 == usage.end()) { // awar_name1 already tracked |
| 82 | if (found1->second != UIW_BOTH) { // do not warn twice |
| 83 | track_problematic_awar_usage_byname(awar_name2, found1->second); |
| 84 | } |
| 85 | } |
| 86 | else { // both already tracked |
| 87 | if (found1->second != found2->second) { |
| 88 | UsedInWidget add1 = UsedInWidget(found2->second & ~found1->second); |
| 89 | UsedInWidget add2 = UsedInWidget(found1->second & ~found2->second); |
| 90 | |
| 91 | if (add1>0 && add1 != UIW_BOTH) track_problematic_awar_usage_byname(awar_name1, add1); |
| 92 | if (add2>0 && add2 != UIW_BOTH) track_problematic_awar_usage_byname(awar_name2, add2); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | fprintf(stderr, "combine_awar_usage('%s', '%s') [end]\n", awar_name1.c_str(), awar_name2.c_str()); |
| 97 | } |
| 98 | static void combine_awar_usage(AwarMapping::iterator& m) { |
| 99 | combine_awar_usage(m->first, m->second); |
| 100 | } |
| 101 | |
| 102 | static void track_awars_mapped_with(std::string awar_name) { |
| 103 | fprintf(stderr, "track_awars_mapped_with('%s') [start]\n", awar_name.c_str()); |
| 104 | for (AwarMapping::iterator i = amap.begin(); i != amap.end(); ++i) { |
| 105 | if (i->first == awar_name || i->second == awar_name) { |
| 106 | combine_awar_usage(i); |
| 107 | } |
| 108 | } |
| 109 | fprintf(stderr, "track_awars_mapped_with('%s') [end]\n", awar_name.c_str()); |
| 110 | } |
| 111 | |
| 112 | void track_problematic_awar_usage(AW_awar *awar, UsedInWidget where) { |
| 113 | track_problematic_awar_usage_byname(awar->get_name(), where); |
| 114 | } |
| 115 | void track_awar_mapping(std::string awarname_org, std::string awarname_mappedTo) { |
| 116 | fprintf(stderr, "track_awar_mapping('%s', '%s') [start]\n", awarname_org.c_str(), awarname_mappedTo.c_str()); |
| 117 | amap[awarname_org] = awarname_mappedTo; |
| 118 | combine_awar_usage(awarname_org, awarname_mappedTo); |
| 119 | fprintf(stderr, "track_awar_mapping('%s', '%s') [end]\n", awarname_org.c_str(), awarname_mappedTo.c_str()); |
| 120 | } |
| 121 | |
| 122 | #endif |
| 123 | |