Add language description -> enum.
authorCarl Hetherington <cth@carlh.net>
Wed, 4 Jun 2014 09:50:57 +0000 (10:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 4 Jun 2014 09:50:57 +0000 (10:50 +0100)
src/stl_binary_tables.cc
src/stl_binary_tables.h

index 7fdad7b6121852acd55a8c3226e8ba098680466f..df571c46f069d385301a9d4befea4d7570114095 100644 (file)
@@ -33,7 +33,6 @@ code (map<F, STLBinaryCode<E> >& m, F k, E v, string d)
        m[k] = STLBinaryCode<E> (v, d);
 }
 
-
 template <class E, class F>
 E
 file_to_enum (F k, map<F, STLBinaryCode<E> > m, string name)
@@ -72,6 +71,19 @@ enum_to_description (E v, map<F, STLBinaryCode<E> > const & m)
 
        return "";
 }
+
+template <class E, class F>
+boost::optional<E>
+description_to_enum (string d, map<F, STLBinaryCode<E> > const & m)
+{
+       for (typename map<F, STLBinaryCode<E> >::const_iterator i = m.begin(); i != m.end(); ++i) {
+               if (i->second.description == d) {
+                       return i->second.value;
+               }
+       }
+
+       return boost::optional<E> ();
+}
              
 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<Language>
+STLBinaryTables::language_description_to_enum (string d) const
+{
+       return description_to_enum (d, _language_map);
+}
+
 STLBinaryTables::STLBinaryTables ()
 {
        code<DisplayStandard, string> (_display_standard_map, " ", DISPLAY_STANDARD_UNDEFINED, "Undefined");
index de9634baaaa1a5837582e6a7744e074449d13fc1..1ce7d62b0e347d5d33fce75dba28826c13dba893 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <string>
 #include <map>
+#include <boost/optional.hpp>
 
 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> language_description_to_enum (std::string) const;
+
 private:       
        std::map<std::string, STLBinaryCode<DisplayStandard> > _display_standard_map;
        std::map<std::string, STLBinaryCode<LanguageGroup> > _language_group_map;