Results 1 to 14 of 14
Thread: /++ # ?!
Hybrid View
-
27th September 2007 23:13 #1
/++ # ?!
... ...
,
:
"" , , .. ident , ?
, :
.e. - , :Code:if(str == "1") 1(param1, param2...) else if(str == "2") 2(param1, param2...) else if...
"" /++ #...Code:idend id = string_to_ident(str); id(param1, param2...)
" , , , , ."
-
27th September 2007 23:34 #2
C . , , .
. , .
- , , . .
++- #- ...
, .
.EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
28th September 2007 00:39 #3
-
28th September 2007 01:16 #4
, , :
, C , , debug . C++ ( , RTTI). C# ( Java) , , Reflection , (.. , ). PHP .Code:// void typedef void (*funcPtr) (param1type, param2type); // (- ) #define FUNC_PROTO(funcname) void funcname(param1type, param2type) FUNC_PROTO(function1); FUNC_PROTO(function2); // struct { const char *funcName; funcPtr function; } map[] = { { "function1", function1 }, { "function2", function2 }, ... { NULL, NULL }, // ! }; // funcPtr get_function(const char* funcName) { int i; for (i = 0; map[i].funcName != NULL; i++) if (!strcmp(funcName, map[i].funcName)) return map[i].function; return NULL; } // funcPtr theFunction = get_function("blahblah"); if (theFunction != NULL) (*theFunction)(param1, param2); else { , ... }
, . - GetProcAddress (Win32) dlsym (POSIX).Last edited by icaci; 28th September 2007 at 01:25.
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
28th September 2007 01:29 #5
Last edited by Bombera; 28th September 2007 at 01:43.
EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
28th September 2007 01:33 #6
- ,
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
28th September 2007 01:55 #7EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
28th September 2007 09:47 #8
-
28th September 2007 10:56 #9
Bombera, . java.lang.Class , (introspection). , java.lang.reflect
Last edited by icaci; 28th September 2007 at 11:06. Reason: java, jala ;)
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
28th September 2007 11:13 #10
- , CVar- fract.
, :
funlist.h:
funs.h:Code:#ifndef DEFUN # error DEFUN not declared. Do not include <funlist.h> directly! #endif DEFUN(foo, int z = a + b; z *= z; printf("%d\n", z); ) DEFUN(bar, float x = sin((float)a); float y = cos((float)b); printf("%f\n", x + y); )
funs.h find_function, . :Code:#include <stdio.h> #include <string.h> // Part 1: Function definition #define DEFUN(name, body) static void name (int a, int b) { body } #include "funlist.h" #undef DEFUN // Part 2: Function index #define DEFUN(name, body) { name, #name }, typedef void (*my_fun_type)(int,int); struct function_entry { my_fun_type fun; const char *name; }; function_entry entries[] = { #include "funlist.h" NULL, NULL }; #undef DEFUN // Part 3: Utility static my_fun_type find_function(const char * name) { int i = 0; while (entries[i].name != NULL && 0 != strcmp(entries[i].name, name)) i++; return entries[i].fun; }
main.cpp
- ( ) , map<name, function>Code:#include <stdio.h> #include <math.h> #include "funs.h" int main(void) { char fun_name[300]; int a, b; while (1) { printf("a = "); scanf("%d", &a); printf("b = "); scanf("%d", &b); printf("function = "); scanf("%s", fun_name); my_fun_type f = find_function(fun_name); if (f != NULL) { printf("Result: "); f(a, b); } else { printf("Function not found!\n"); } } return 0; }
, , , std::map<std::string, my_fun_type>. , map `f', :
Code:f["foo"](5, 6);
Last edited by anrieff; 28th September 2007 at 11:19. Reason: std::map-
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
28th September 2007 11:16 #11
-
28th September 2007 12:23 #12
anrieff, , , , MFC, ,
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
28th September 2007 13:32 #13
-
28th September 2007 13:36 #14
icaci, java reflection, introspection bean introspection, .. BeanInfo .
http://java.sun.com/docs/books/tutor...ion/index.html




Reply With Quote


Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in