00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef LOBOT_CONFIG_HELPERS_DOT_H
00052 #define LOBOT_CONFIG_HELPERS_DOT_H
00053
00054
00055
00056
00057 #include "Robots/LoBot/config/LoConfig.H"
00058 #include "Robots/LoBot/config/LoDefaults.H"
00059
00060 #include "Robots/LoBot/misc/LoTypes.H"
00061 #include "Robots/LoBot/util/LoString.H"
00062 #include "Robots/LoBot/util/triple.hh"
00063 #include "Robots/LoBot/util/range.hh"
00064
00065
00066 #include <string>
00067 #include <utility>
00068
00069
00070
00071 namespace lobot {
00072
00073
00074
00075
00076
00077 template<typename T>
00078 inline T get_conf(const std::string& section, const std::string& key,
00079 const T& default_value = T())
00080 {
00081 return Configuration::get(section, key, default_value) ;
00082 }
00083
00084
00085
00086 template<>
00087 PixelType get_conf(const std::string& section, const std::string& key,
00088 const PixelType& defval)
00089 {
00090 int color[3] ;
00091 const int default_color[] = {defval.red(), defval.green(), defval.blue()} ;
00092 Configuration::get(section, key, color, default_color, 3) ;
00093 return PixelType(color[0], color[1], color[2]) ;
00094 }
00095
00096
00097
00098 template<typename T>
00099 std::pair<T, T>
00100 get_conf(const std::string& section, const std::string& key,
00101 const std::pair<T, T>& defval = std::pair<T, T>(T(), T()))
00102 {
00103 T pair[2] ;
00104 const T defaults[] = {defval.first, defval.second} ;
00105 Configuration::get<T>(section, key, pair, defaults, 2) ;
00106 return std::pair<T, T>(pair[0], pair[1]) ;
00107 }
00108
00109
00110
00111 template<typename T>
00112 triple<T, T, T>
00113 get_conf(const std::string& section, const std::string& key,
00114 const triple<T, T, T>& defval = make_triple(T(), T(), T()))
00115 {
00116 T triple[3] ;
00117 const T defaults[] = {defval.first, defval.second, defval.third} ;
00118 Configuration::get<T>(section, key, triple, defaults, 3) ;
00119 return make_triple(triple[0], triple[1], triple[2]) ;
00120 }
00121
00122
00123
00124 template<typename T>
00125 range<T> get_conf(const std::string& section, const std::string& key,
00126 const range<T>& defval = range<T>(T(), T()))
00127 {
00128 std::pair<T, T> r =
00129 get_conf<T>(section, key, std::make_pair(defval.min(), defval.max())) ;
00130 return make_range(r.first, r.second) ;
00131 }
00132
00133
00134 template<typename T>
00135 inline T global_conf(const std::string& key, const T& default_value = T())
00136 {
00137 return Configuration::get_global<T>(key, default_value) ;
00138 }
00139
00140
00141
00142 template<typename T>
00143 inline T internal_conf(const std::string& key, const T& default_value = T())
00144 {
00145 return get_conf<T>(LOCD_INTERNAL, key, default_value) ;
00146 }
00147
00148
00149
00150
00151 template<typename T>
00152 inline T robot_conf(const std::string& key, const T& default_value = T())
00153 {
00154 return get_conf<T>("robot", key, default_value) ;
00155 }
00156
00157
00158 inline bool robot_enabled()
00159 {
00160 return robot_conf("use_robot", true) ;
00161 }
00162
00163
00164 inline std::string robot_platform()
00165 {
00166 return downstring(robot_conf<std::string>("platform", "roomba_cm")) ;
00167 }
00168
00169
00170 bool robot_platform_is_roomba() ;
00171
00172
00173
00174
00175 inline std::string locust_input()
00176 {
00177 return downstring(global_conf<std::string>("locust_input", "laser")) ;
00178 }
00179
00180
00181 inline bool video_input()
00182 {
00183 return locust_input() == "video" ;
00184 }
00185
00186
00187 inline bool laser_input()
00188 {
00189 return locust_input() == "laser" ;
00190 }
00191
00192
00193 template<typename T>
00194 inline T laser_conf(const std::string& key, const T& default_value = T())
00195 {
00196 return get_conf<T>("laser", key, default_value) ;
00197 }
00198
00199
00200 inline std::string locust_model()
00201 {
00202 return downstring(global_conf<std::string>("locust_model",
00203 LOBOT_DEFAULT_LOCUST_MODEL)) ;
00204 }
00205
00206
00207
00208
00209 template<typename T>
00210 inline T ui_conf(const std::string& key, const T& default_value = T())
00211 {
00212 return get_conf<T>("ui", key, default_value) ;
00213 }
00214
00215
00216
00217
00218
00219 inline bool visualize(const std::string& section)
00220 {
00221 return get_conf(section, "visualization", false) ;
00222 }
00223
00224
00225
00226
00227 template<typename T>
00228 inline T video_conf(const std::string& key, const T& default_value = T())
00229 {
00230 return get_conf<T>("video", key, default_value) ;
00231 }
00232
00233
00234 template<typename T>
00235 inline T optical_flow_conf(const std::string& key, const T& default_value)
00236 {
00237 return get_conf<T>("optical_flow", key, default_value) ;
00238 }
00239
00240
00241
00242 }
00243
00244 #endif
00245
00246
00247
00248
00249