fx.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00042 #ifndef FX_H
00043 #define FX_H
00044 
00045 #include "fastlib/fx/datanode.h"
00046 #include "fastlib/fx/stopwatch.h"
00047 //#include "datanode.h"
00048 //#include "stopwatch.h"
00049 
00050 #include "fastlib/base/common.h"
00051 
00052 EXTERN_C_BEGIN
00053 
00055 typedef struct datanode fx_module;
00057 typedef struct stopwatch fx_timer;
00058 
00060 extern fx_module *fx_root;
00061 
00063 extern int fx_docs_nagging;
00064 
00065 /*
00066  * TODO: Consider adding support for printing params, timers, and
00067  * results to stdout upon accessing/stopping/writing them.
00068  */
00069 
00083 typedef enum {
00085   FX_UNKNOWN = 0,
00087   FX_MODULE,
00089   FX_PARAM,
00091   FX_REQUIRED,
00093   FX_RESERVED,
00095   FX_PROVIDED,
00097   FX_DEFAULT,
00099   FX_RESULT,
00101   FX_TIMER
00102 } fx_mod_t;
00103 
00105 extern char fx_mod_marker[];
00107 extern const char *fx_mod_name[];
00108 
00118 typedef enum {
00120   FX_STR = 0,
00122   FX_DOUBLE,
00124   FX_INT,
00126   FX_BOOL,
00128   FX_STR_LIST,
00130   FX_DOUBLE_LIST,
00132   FX_INT_LIST,
00134   FX_BOOL_LIST,
00136   FX_CUSTOM = -1
00137 } fx_val_t;
00138 
00140 extern const char *fx_val_name[];
00141 
00142 struct fx_module_doc;
00143 
00153 typedef struct fx_entry_doc {
00155   const char *key;
00157   fx_mod_t mod_type;
00159   fx_val_t val_type;
00161   const char *meta;
00163   const char *text;
00164 } fx_entry_doc;
00165 
00175 typedef struct fx_submodule_doc {
00177   const char *key;
00179   const struct fx_module_doc *doc;
00181   const char *text;
00182 } fx_submodule_doc;
00183 
00257 typedef struct fx_module_doc {
00259   const struct fx_entry_doc *entries;
00261   const struct fx_submodule_doc *submodules;
00263   const char *text;
00264 } fx_module_doc;
00265 
00267 #define FX_ENTRY_DOC_DONE {NULL, (fx_mod_t)0, (fx_val_t)0, NULL}
00268 
00270 #define FX_SUBMODULE_DOC_DONE {NULL, NULL, NULL}
00271 
00300 int fx_module_is_type(fx_module *entry, fx_mod_t type);
00301 
00307 const char *fx_param_str_req(fx_module *mod, const char *key);
00313 double fx_param_double_req(fx_module *mod, const char *key);
00319 long long fx_param_int_req(fx_module *mod, const char *key);
00325 int fx_param_bool_req(fx_module *mod, const char *key);
00326 
00332 const char **fx_param_str_list_req(fx_module *mod, const char *key,
00333                                    size_t *size_ptr);
00340 double *fx_param_double_list_req(fx_module *mod, const char *key,
00341                                  size_t *size_ptr);
00348 long long *fx_param_list_int_req(fx_module *mod, const char *key,
00349                                  size_t *size_ptr);
00356 int *fx_param_bool_list_req(fx_module *mod, const char *key,
00357                             size_t *size_ptr);
00358 
00372 const char *fx_param_str(fx_module *mod, const char *key, const char *def);
00385 double fx_param_double(fx_module *mod, const char *key, double def);
00398 long long fx_param_int(fx_module *mod, const char *key, long long def);
00416 int fx_param_bool(fx_module *mod, const char *key, int def);
00417 
00443 const char **fx_param_str_list(fx_module *mod, const char *key,
00444                                size_t *size_ptr, size_t def_size, ...);
00466 double *fx_param_double_list(fx_module *mod, const char *key,
00467                              size_t *size_ptr, size_t def_size, ...);
00489 long long *fx_param_int_list(fx_module *mod, const char *key,
00490                              size_t *size_ptr, size_t def_size, ...);
00512 int *fx_param_bool_list(fx_module *mod, const char *key,
00513                         size_t *size_ptr, size_t def_size, ...);
00514 
00521 const char **fx_param_str_array(fx_module *mod, const char *key,
00522                                 size_t *size_ptr, size_t def_size,
00523                                 const char *const *def_array);
00530 double *fx_param_double_array(fx_module *mod, const char *key,
00531                               size_t *size_ptr, size_t def_size,
00532                               const double *def_array);
00539 long long *fx_param_int_array(fx_module *mod, const char *key,
00540                               size_t *size_ptr, size_t def_size,
00541                               const long long *def_array);
00548 int *fx_param_bool_array(fx_module *mod, const char *key,
00549                          size_t *size_ptr, size_t def_size,
00550                          const int *def_array);
00551 
00558 void fx_set_param_str(fx_module *mod, const char *key, const char *val);
00564 void fx_set_param_double(fx_module *mod, const char *key, double val);
00570 void fx_set_param_int(fx_module *mod, const char *key, long long val);
00576 void fx_set_param_bool(fx_module *mod, const char *key, int val);
00577 
00584 void fx_set_param_str_list(fx_module *mod, const char *key,
00585                            size_t size, ...);
00592 void fx_set_param_double_list(fx_module *mod, const char *key,
00593                               size_t size, ...);
00600 void fx_set_param_int_list(fx_module *mod, const char *key,
00601                            size_t size, ...);
00608 void fx_set_param_bool_list(fx_module *mod, const char *key,
00609                             size_t size, ...);
00610 
00616 void fx_set_param_str_array(fx_module *mod, const char *key,
00617                             size_t size, const char *const *array);
00623 void fx_set_param_double_array(fx_module *mod, const char *key,
00624                                size_t size, const double *array);
00630 void fx_set_param_int_array(fx_module *mod, const char *key,
00631                             size_t size, const long long *array);
00637 void fx_set_param_bool_array(fx_module *mod, const char *key,
00638                              size_t size, const int *array);
00639 
00645 COMPILER_PRINTF(3, 4)
00646 void fx_default_param(fx_module *mod, const char *key,
00647                       const char *def_format, ...);
00664 void fx_default_param_list(fx_module *mod, const char *key,
00665                            size_t *size_ptr, size_t def_size, ...);
00671 COMPILER_PRINTF(3, 4)
00672 void fx_format_param(fx_module *mod, const char *key,
00673                      const char *format, ...);
00683 void fx_format_param_list(fx_module *mod, const char *key,
00684                           size_t size, ...);
00685 
00694 void fx_clear_param(fx_module *mod, const char *key);
00704 int fx_param_exists(fx_module *mod, const char *key);
00705 
00715 const char *fx_get_result_str(fx_module *mod, const char *key);
00725 double fx_get_result_double(fx_module *mod, const char *key);
00735 long long fx_get_result_int(fx_module *mod, const char *key);
00745 int fx_get_result_bool(fx_module *mod, const char *key);
00746 
00752 const char **fx_get_result_str_list(fx_module *mod, const char *key,
00753                                     size_t *size_ptr);
00761 double *fx_get_result_double_list(fx_module *mod, const char *key,
00762                                   size_t *size_ptr);
00769 long long *fx_get_result_list_int(fx_module *mod, const char *key,
00770                                   size_t *size_ptr);
00777 int *fx_get_result_bool_list(fx_module *mod, const char *key,
00778                              size_t *size_ptr);
00779 
00787 void fx_result_str(fx_module *mod, const char *key, const char *val);
00794 void fx_result_double(fx_module *mod, const char *key, double val);
00801 void fx_result_int(fx_module *mod, const char *key, long long val);
00808 void fx_result_bool(fx_module *mod, const char *key, int val);
00809 
00816 void fx_result_str_list(fx_module *mod, const char *key,
00817                         size_t size, ...);
00824 void fx_result_double_list(fx_module *mod, const char *key,
00825                            size_t size, ...);
00832 void fx_result_int_list(fx_module *mod, const char *key,
00833                         size_t size, ...);
00840 void fx_result_bool_list(fx_module *mod, const char *key,
00841                          size_t size, ...);
00842 
00848 void fx_result_str_array(fx_module *mod, const char *key,
00849                          size_t size, const char *const *array);
00855 void fx_result_double_array(fx_module *mod, const char *key,
00856                             size_t size, const double *array);
00862 void fx_result_int_array(fx_module *mod, const char *key,
00863                          size_t size, const long long *array);
00869 void fx_result_bool_array(fx_module *mod, const char *key,
00870                           size_t size, const int *array);
00871 
00877 COMPILER_PRINTF(3, 4)
00878 void fx_format_result(fx_module *mod, const char *key,
00879                       const char *format, ...);
00888 void fx_format_result_list(fx_module *mod, const char *key,
00889                            size_t size, ...);
00890 
00899 void fx_clear_result(fx_module *mod, const char *key);
00909 int fx_result_exists(fx_module *mod, const char *key);
00910 
00920 fx_timer *fx_get_timer(fx_module *mod, const char *key);
00930 void fx_timer_start(fx_module *mod, const char *key);
00939 void fx_timer_stop(fx_module *mod, const char *key);
00948 void fx_reset_timer(fx_module *mod, const char *key);
00949 
00988 fx_module *fx_submodule(fx_module *mod, const char *key);
01042 COMPILER_PRINTF(3, 4)
01043 fx_module *fx_copy_module(fx_module *mod, const char *src_key,
01044                           const char *dest_format, ...);
01045 
01063 success_t fx_help(const fx_module_doc *doc, const char *key);
01064 
01092 fx_module *fx_init(int argc, char **argv, const fx_module_doc *doc);
01109 void fx_done(fx_module *root);
01110 
01111 EXTERN_C_END
01112 
01113 #endif
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3