write TAGLIB_GET_VALUE
authorPeng Wu <alexepico@gmail.com>
Thu, 6 Sep 2012 05:16:50 +0000 (13:16 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 6 Sep 2012 05:16:50 +0000 (13:16 +0800)
utils/storage/import_interpolation.cpp
utils/training/import_k_mixture_model.cpp

index d0ac36a1f343e4dc8f0656b2886631474594cfc8..9295096d1ba266eabe43d53bb7b80d7aca77ae9b 100644 (file)
 #include "pinyin_internal.h"
 #include "utils_helper.h"
 
+#define TAGLIB_GET_VALUE(var, index)                                    \
+    phrase_token_t var = null_token;                                    \
+    {                                                                   \
+        const char * string = (const char *) g_ptr_array_index          \
+            (values, index);                                            \
+        var = taglib_string_to_token                                    \
+            (phrase_table, phrase_index, string);                       \
+    }
+
+
 enum LINE_TYPE{
     BEGIN_LINE = 1,
     END_LINE,
@@ -125,9 +135,8 @@ bool parse_unigram(FILE * input, PhraseLargeTable2 * phrase_table,
         switch (line_type) {
         case GRAM_1_ITEM_LINE:{
             /* handle \item in \1-gram */
-            const char * string = (const char *) g_ptr_array_index(values, 0);
-            phrase_token_t token = taglib_string_to_token
-                (phrase_table, phrase_index, string);
+            TAGLIB_GET_VALUE(token, 0);
+
             gpointer value = NULL;
             assert(g_hash_table_lookup_extended(required, "count", NULL, &value));
             glong count = atol((const char *)value);
@@ -162,12 +171,8 @@ bool parse_bigram(FILE * input, PhraseLargeTable2 * phrase_table,
         case GRAM_2_ITEM_LINE:{
             /* handle \item in \2-gram */
             /* two tokens */
-            const char * string = (const char *) g_ptr_array_index(values, 0);
-            phrase_token_t token1 = taglib_string_to_token
-                (phrase_table, phrase_index, string);
-            string = (const char *) g_ptr_array_index(values, 1);
-            phrase_token_t token2 = taglib_string_to_token
-                (phrase_table, phrase_index, string);
+            TAGLIB_GET_VALUE(token1, 0);
+            TAGLIB_GET_VALUE(token2, 1);
 
             gpointer value = NULL;
             /* tag: count */
index 59c311f18f664e05d187aa52bee4306402f752f8..5bbd6037aefd503c4281d86d5ffd72187d787e2f 100644 (file)
 #include "utils_helper.h"
 #include "k_mixture_model.h"
 
+#define TAGLIB_GET_VALUE(var, index)                                    \
+    phrase_token_t var = null_token;                                    \
+    {                                                                   \
+        const char * string = (const char *) g_ptr_array_index          \
+            (values, index);                                            \
+        var = taglib_string_to_token                                    \
+            (phrase_table, phrase_index, string);                       \
+    }
+
 enum LINE_TYPE{
     BEGIN_LINE = 1,
     END_LINE,
@@ -145,9 +154,8 @@ bool parse_unigram(FILE * input, PhraseLargeTable2 * phrase_table,
         switch (line_type) {
         case GRAM_1_ITEM_LINE:{
             /* handle \item in \1-gram */
-            const char * string = (const char *) g_ptr_array_index(values, 0);
-            phrase_token_t token = taglib_string_to_token
-                (phrase_table, phrase_index, string);
+            TAGLIB_GET_VALUE(token, 0);
+
             gpointer value = NULL;
             assert(g_hash_table_lookup_extended(required, "count",
                                                 NULL, &value));
@@ -192,12 +200,8 @@ bool parse_bigram(FILE * input, PhraseLargeTable2 * phrase_table,
         case GRAM_2_ITEM_LINE:{
             /* handle \item in \2-gram */
             /* two tokens */
-            const char * string = (const char *) g_ptr_array_index(values, 0);
-            phrase_token_t token1 = taglib_string_to_token
-                (phrase_table, phrase_index, string);
-            string = (const char *) g_ptr_array_index(values, 1);
-            phrase_token_t token2 = taglib_string_to_token
-                (phrase_table, phrase_index, string);
+            TAGLIB_GET_VALUE(token1, 0);
+            TAGLIB_GET_VALUE(token2, 1);
 
             gpointer value = NULL;
             /* tag: count */