parameter_initializer.cxx

Go to the documentation of this file.
00001 //    sampalib.org ESL library and tools
00002 //    Copyright (C) 2007  Thierry Grellier
00003 //
00004 //    This program is free software; you can redistribute it and/or modify
00005 //    it under the terms of the GNU General Public License version 2 as
00006 //    published by the Free Software Foundation.
00007 //
00008 //    This program is distributed in the hope that it will be useful,
00009 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //    GNU General Public License for more details.
00012 //
00013 //    You should have received a copy of the GNU General Public License along
00014 //    with this program; if not, write to the Free Software Foundation, Inc.,
00015 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016 //
00017 //    contact: www.sampalib.org
00018 
00019 #include "sampa/core/parameter_initializer.h"
00020 #include "sampa/core/lua_interpreter.h"
00021 #include "sampa/core/persistence.cxx"
00022 #include <cstring>
00023 #include <cctype>
00024 
00025 namespace Sampa {
00026 
00027 template <typename Enumerated>
00028 int EnumeratedParameterInitializer<Enumerated>::retrieve(LuaInterpreter* interpreter, const std::string& full_name)
00029 {
00030   std::string val;
00031   int ret = interpreter->get_string(full_name, val); 
00032   if (ret == 0) {
00033     char tmp[val.size()+1];
00034     strcpy(tmp, val.c_str());
00035     for (size_t l = 0; l < val.size(); l++)
00036       tmp[l] = tmp[l] == ' ' ? '_' : toupper(tmp[l]);
00037     val = tmp;
00038     for (int i = 0; M_enum_labels[i] != 0; i++) {
00039       if (val == M_enum_labels[i]) {
00040         m_parm->m_value = M_enum_consts[i];
00041         return 0;
00042       }
00043     }
00044     ret = -1;
00045   }
00046   return ret;
00047 }
00048 
00049 template <typename Enumerated>
00050 std::string EnumeratedParameterInitializer<Enumerated>::to_string() const {
00051   int i = 0;
00052   while (M_enum_consts[i] != m_parm->m_value)
00053     i++;
00054   return M_enum_labels[i];
00055 }
00056 
00057 template <typename Enumerated>
00058 EnumeratedParameter<Enumerated>::EnumeratedParameter(const char* name, Enumerated default_value)
00059 { m_value = default_value;
00060   EnumeratedParameterInitializer<Enumerated> my_initializer(this);
00061   my_initializer.initialize(name, true);
00062 }
00063 
00064 template <typename Enumerated>
00065 EnumeratedParameter<Enumerated>::EnumeratedParameter(const char* name)
00066 {
00067   EnumeratedParameterInitializer<Enumerated> my_initializer(this);
00068   my_initializer.initialize(name, false);
00069 }
00070 
00071 template <typename Enumerated>
00072 void EnumeratedParameter<Enumerated>::update(const char* name)
00073 {
00074   EnumeratedParameterInitializer<Enumerated> my_initializer(this);
00075   my_initializer.initialize(name, true);
00076 }
00077 
00078 } // namespace Sampa
00079 
00080 #define ENUM_CONSTS_INIT_1(Scope, Enumerated, e1) \
00081 template<>                                                                                   \
00082 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00083   #e1                                                                                        \
00084 };                                                                                           \
00085 template<>                                                                                   \
00086 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00087   Scope e1                                                                                         \
00088 };                                                                                           \
00089 template class EnumeratedParameter<Scope Enumerated>;                                       \
00090 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00091 template class EnumeratedParameterInitializer<Scope Enumerated>
00092 
00093 #define ENUM_CONSTS_INIT_2(Scope, Enumerated, e1, e2) \
00094 template<>                                                                                   \
00095 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00096   #e1, #e2, 0                                                                                   \
00097 };                                                                                           \
00098 template<>                                                                                   \
00099 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00100   Scope e1, Scope e2                                                                                     \
00101 };                                                                                           \
00102 template class EnumeratedParameter<Scope Enumerated>;                                       \
00103 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00104 template class EnumeratedParameterInitializer<Scope Enumerated>
00105 
00106 #define ENUM_CONSTS_INIT_3(Scope, Enumerated, e1, e2, e3) \
00107 template<>                                                                                   \
00108 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00109   #e1, #e2, #e3, 0                                                                              \
00110 };                                                                                           \
00111 template<>                                                                                   \
00112 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00113   Scope e1, Scope e2, Scope e3                                                                                 \
00114 };                                                                                           \
00115 template class EnumeratedParameter<Scope Enumerated>;                                       \
00116 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00117 template class EnumeratedParameterInitializer<Scope Enumerated>
00118 
00119 #define ENUM_CONSTS_INIT_4(Scope, Enumerated, e1, e2, e3, e4) \
00120 template<>                                                                                   \
00121 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00122   #e1, #e2, #e3, #e4, 0                                                                         \
00123 };                                                                                           \
00124 template<>                                                                                   \
00125 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00126   Scope e1, Scope e2, Scope e3, Scope e4                                                                             \
00127 };                                                                                           \
00128 template class EnumeratedParameter<Scope Enumerated>;                                       \
00129 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00130 template class EnumeratedParameterInitializer<Scope Enumerated>
00131 
00132 #define ENUM_CONSTS_INIT_5(Scope, Enumerated, e1, e2, e3, e4, e5) \
00133 template<>                                                                                   \
00134 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00135   #e1, #e2, #e3, #e4, #e5, 0                                                                    \
00136 };                                                                                           \
00137 template<>                                                                                   \
00138 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00139   Scope e1, Scope e2, Scope e3, Scope e4, Scope e5                                                                         \
00140 };                                                                                           \
00141 template class EnumeratedParameter<Scope Enumerated>;                                       \
00142 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00143 template class EnumeratedParameterInitializer<Scope Enumerated>
00144 
00145 #define ENUM_CONSTS_INIT_6(Scope, Enumerated, e1, e2, e3, e4, e5, e6) \
00146 template<>                                                                                   \
00147 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00148   #e1, #e2, #e3, #e4, #e5, #e6, 0                                                               \
00149 };                                                                                           \
00150 template<>                                                                                   \
00151 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00152   Scope e1, Scope e2, Scope e3, Scope e4, Scope e5, Scope e6                                                                     \
00153 };                                                                                           \
00154 template class EnumeratedParameter<Scope Enumerated>;                                       \
00155 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00156 template class EnumeratedParameterInitializer<Scope Enumerated>
00157 
00158 #define ENUM_CONSTS_INIT_7(Scope, Enumerated, e1, e2, e3, e4, e5, e6, e7) \
00159 template<>                                                                                   \
00160 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00161   #e1, #e2, #e3, #e4, #e5, #e6, #e7, 0                                                          \
00162 };                                                                                           \
00163 template<>                                                                                   \
00164 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00165   Scope e1, Scope e2, Scope e3, Scope e4, Scope e5, Scope e6, Scope e7                                                                 \
00166 };                                                                                           \
00167 template class EnumeratedParameter<Scope Enumerated>;                                       \
00168 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00169 template class EnumeratedParameterInitializer<Scope Enumerated>
00170 
00171 #define ENUM_CONSTS_INIT_8(Scope, Enumerated, e1, e2, e3, e4, e5, e6, e7, e8) \
00172 template<>                                                                                   \
00173 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00174   #e1, #e2, #e3, #e4, #e5, #e6, #e7, #e8, 0                                                     \
00175 };                                                                                           \
00176 template<>                                                                                   \
00177 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00178   Scope e1, Scope e2, Scope e3, Scope e4, Scope e5, Scope e6, Scope e7, Scope e8                                                             \
00179 };                                                                                           \
00180 template class EnumeratedParameter<Scope Enumerated>;                                       \
00181 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00182 template class EnumeratedParameterInitializer<Scope Enumerated>
00183 
00184 #define ENUM_CONSTS_INIT_9(Enumerated, e1, e2, e3, e4, e5, e6, e7, e8, e9) \
00185 template<>                                                                                   \
00186 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00187   #e1, #e2, #e3, #e4, #e5, #e6, #e7, #e8, #e9, 0                                                \
00188 };                                                                                           \
00189 template<>                                                                                   \
00190 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00191   Scope e1, Scope e2, Scope e3, Scope e4, Scope e5, Scope e6, Scope e7, Scope e8, Scope e9                                                         \
00192 };                                                                                           \
00193 template class EnumeratedParameter<Scope Enumerated>;                                       \
00194 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00195 template class EnumeratedParameterInitializer<Scope Enumerated>
00196 
00197 #define ENUM_CONSTS_INIT_10(Scope, Enumerated, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10) \
00198 template<>                                                                                   \
00199 const char* EnumeratedParameterInitializer<Scope Enumerated>::M_enum_labels[] = {           \
00200   #e1, #e2, #e3, #e4, #e5, #e6, #e7, #e8, #e9, #e10, 0                                          \
00201 };                                                                                           \
00202 template<>                                                                                   \
00203 Scope Enumerated  EnumeratedParameterInitializer<Scope Enumerated>::M_enum_consts[] = {           \
00204   Scope e1, Scope e2, Scope e3, Scope e4, Scope e5, Scope e6, Scope e7, Scope e8, Scope e9, Scope e10                                                    \
00205 };                                                                                           \
00206 template class EnumeratedParameter<Scope Enumerated>;                                       \
00207 SAMPA_MAKE_TMPL_PERSISTENT(EnumeratedParameter<Scope Enumerated>, EnumeratedParameter, NO_REFS);     \
00208 template class EnumeratedParameterInitializer<Scope Enumerated>

Generated on Sat Feb 16 16:23:15 2008 for Sampa by  doxygen 1.5.3