Results 1 to 14 of 14

Thread: /++ # ?!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414

    Question /++ # ?!

    ... ...

    ,

    :
    "" , , .. ident , ?

    , :
    Code:
    if(str == "1")
          1(param1, param2...)
    else if(str == "2")
          2(param1, param2...)
    else if...
    .e. - , :
    Code:
    idend id = string_to_ident(str);
    id(param1, param2...)
    "" /++ #...
    " , , , , ."

  2. #2
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    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|

  3. #3
    Registered User JACK's Avatar
    Join Date: Mar:2004
    Location:
    Posts: 651
    C# reflection

  4. #4
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    , , :

    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
    { ,   ... }
    , C , , debug . C++ ( , RTTI). C# ( Java) , , Reflection , (.. , ). PHP .

    , . - 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

  5. #5
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    Quote Originally Posted by icaci View Post
    ... Reflection ... ...
    , , , . . ' , . reflection # ,

    - VCL, C++ Builder , RTTI. , .
    , OLE(COM) , - . CORBA , .

    - - , . , - , 2 . . , , -.

    NULL, NULL !
    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|

  6. #6
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    - ,
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  7. #7
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    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|

  8. #8
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    !

    !
    , , o ...
    " , , , , ."

  9. #9
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    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

  10. #10
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    - , CVar- fract.

    , :

    funlist.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:
    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;
    }
    funs.h find_function, . :

    main.cpp
    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;
    }
    - ( ) , map<name, function> , , , 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

  11. #11
    Registered User leechaa's Avatar
    Join Date: Aug:2007
    Location:
    Posts: 27
    , .

  12. #12
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    anrieff, , , , MFC, ,
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  13. #13
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    , !

    !
    ... - ? :
    " , , , , ."

  14. #14
    Registered User Annihilator's Avatar
    Join Date: Jun:2004
    Location: Sofia
    Posts: 1,316
    icaci, java reflection, introspection bean introspection, .. BeanInfo .
    http://java.sun.com/docs/books/tutor...ion/index.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |