Changeset 4181 for proto


Ignore:
Timestamp:
Sep 20, 2014, 11:01:52 PM (4 years ago)
Author:
cameron
Message:

vector<string> value_name; vector<unordered_map> property_value_alias_map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/UCD/UCD_properties.py

    r4180 r4181  
    184184PropertyValueAliases_template = r"""
    185185namespace UCD {
    186   namespace %s {
    187     enum value_t {
    188 %s
    189     };
    190     const std::string value_name[] = {
    191 %s
    192     };
    193     const std::unordered_map<std::string, value_t> alias_map = {
    194 %s
    195     };
    196   }
     186  enum binary_value_t {N, Y};
     187%s
     188
     189  const std::vector<std::string> value_name[] = {
     190%s};
     191
     192  const std::unordered_map<std::string, int> property_value_alias_map[] = {
     193%s};
     194
    197195}
    198196"""
     197
    199198
    200199
     
    215214   write_imports(f, ["<string>", "<unordered_map>", '"unicode_set.h"', '"PropertyAliases.h"'])
    216215   #  Generate the aliases for all Binary properties.
    217    enum_text = multiline_join(['N', 'Y'], 4, ',','', 6)
    218216   full_name_text = multiline_join(['"No"', '"Yes"'], 4, ',',  '', 6)
    219    map_text = multiline_join(['{"n", N}', '{"y", Y}', '{"no", N}', '{"yes", Y}', '{"f", N}', '{"t", Y}', '{"false", N}', '{"true", Y}'], 4, ',', '', 6)
    220    f.write(PropertyValueAliases_template % ('Binary', enum_text, full_name_text, map_text))
    221    #
     217   binary_map_text = multiline_join(['{"n", N}', '{"y", Y}', '{"no", N}', '{"yes", Y}', '{"f", N}', '{"t", Y}', '{"false", N}', '{"true", Y}'], 4, ',', '', 6)
     218   #
     219   enum_text = ""
     220   name_vectors = []
     221   alias_maps = []
    222222   for p in property_enum_name_list:
    223223     if property_value_list.has_key(p):
    224        if property_value_list[p] == ['N', 'Y']: continue # skip boolean properties
    225        enum_text = multiline_join(property_value_list[p], 4, ',','', 6)
    226        if p == 'ccc': # Special case: add numeric value information for ccc.
    227          enum_text += r"""
     224       if property_value_list[p] == ['N', 'Y']:
     225         name_vectors.append('    {"No", "Yes"}')
     226         alias_maps.append("    {%s}" % binary_map_text)
     227       else:
     228         enum_text += "  namespace %s {\n    enum value_t {\n" % p.upper()
     229         enum_text += multiline_join(property_value_list[p], 4, ',','', 6)
     230         if p == 'ccc': # Special case: add numeric value information for ccc.
     231           enum_text += r"""
    228232    };
    229233    const uint8_t enum_val[] = {
    230234"""
    231          enum_text += multiline_join(["%s" % (property_value_enum_integer[p][e]) for e in property_value_list['ccc']], 4, ',', '', 6)
    232        full_name_text = multiline_join(['"%s"' % (property_value_full_name_map[p][e]) for e in property_value_list[p]], 4, ',',  '', 6)
    233        map_text = multiline_join(['{"%s", %s}' % (k, property_value_lookup_map[p][k]) for k in sorted(property_value_lookup_map[p].keys())], 4, ',', '', 6)
    234        f.write(PropertyValueAliases_template % (p.upper(), enum_text, full_name_text, map_text))
    235    close_header_file(f)
     235           enum_text += multiline_join(["%s" % (property_value_enum_integer[p][e]) for e in property_value_list['ccc']], 4, ',', '', 6)
     236         enum_text += "};\n  }\n"
     237         full_name_text = multiline_join(['"%s"' % (property_value_full_name_map[p][e]) for e in property_value_list[p]], 4, ',',  '', 6)
     238         name_vectors.append("    {%s}" % full_name_text)
     239         map_text = multiline_join(['{"%s", %s::%s}' % (k, p.upper(), property_value_lookup_map[p][k]) for k in sorted(property_value_lookup_map[p].keys())], 4, ',', '', 6)
     240         alias_maps.append("    {%s}" % map_text)
     241     else:
     242       name_vectors.append("    {}")
     243       alias_maps.append("    {}")
     244   f.write(PropertyValueAliases_template % (enum_text, ",\n".join(name_vectors), ",\n".join(alias_maps)))
     245   close_header_file(f)
     246
     247
     248
     249
    236250
    237251def generate_PropertyValueSets_h(property_enum_name_list, property_value_list, property_value_enum_integer, property_value_full_name_map, property_value_lookup_map):
Note: See TracChangeset for help on using the changeset viewer.