From: Carl Hetherington Date: Wed, 4 Jun 2014 09:50:57 +0000 (+0100) Subject: Add language description -> enum. X-Git-Tag: v1.1.0~96 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=df5e7ee155351ecd6e7ef52b1764149b5fcb258a;p=libsub.git Add language description -> enum. --- diff --git a/src/stl_binary_tables.cc b/src/stl_binary_tables.cc index 7fdad7b..df571c4 100644 --- a/src/stl_binary_tables.cc +++ b/src/stl_binary_tables.cc @@ -33,7 +33,6 @@ code (map >& m, F k, E v, string d) m[k] = STLBinaryCode (v, d); } - template E file_to_enum (F k, map > m, string name) @@ -72,6 +71,19 @@ enum_to_description (E v, map > const & m) return ""; } + +template +boost::optional +description_to_enum (string d, map > const & m) +{ + for (typename map >::const_iterator i = m.begin(); i != m.end(); ++i) { + if (i->second.description == d) { + return i->second.value; + } + } + + return boost::optional (); +} DisplayStandard STLBinaryTables::display_standard_file_to_enum (string s) const @@ -181,6 +193,12 @@ STLBinaryTables::comment_enum_to_description (Comment v) const return enum_to_description (v, _comment_map); } +boost::optional +STLBinaryTables::language_description_to_enum (string d) const +{ + return description_to_enum (d, _language_map); +} + STLBinaryTables::STLBinaryTables () { code (_display_standard_map, " ", DISPLAY_STANDARD_UNDEFINED, "Undefined"); diff --git a/src/stl_binary_tables.h b/src/stl_binary_tables.h index de9634b..1ce7d62 100644 --- a/src/stl_binary_tables.h +++ b/src/stl_binary_tables.h @@ -19,6 +19,7 @@ #include #include +#include namespace sub { @@ -216,6 +217,8 @@ public: std::string justification_enum_to_description (Justification) const; std::string comment_enum_to_description (Comment) const; + boost::optional language_description_to_enum (std::string) const; + private: std::map > _display_standard_map; std::map > _language_group_map;