UML representation for C/C++ function pointers

后端 未结 7 1283
梦谈多话
梦谈多话 2021-02-13 00:21

What would be the best representation of a C/C++ function pointer (fp) in an UML structural diagram?

I\'m thinking about using an interface element, may be even if \'deg

相关标签:
7条回答
  • 2021-02-13 00:49

    I have been able to get something sort of working with Enterprise Architect. Its a bit of a hacky solution, but it meets my needs. What I did:

    1. Create a new class stereotype named FuncPtr. I followed the guide here: http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/addingelementsandmetaclass.html When I did this I made a new view for the profile. So I can keep it contained outside of my main project.

    2. Modified the Class code templates. Basically selecting the C language and start with the Class Template and hit the 'Add New Stereotype Override' and add in FuncPtr as a new override.

    3. Add in the following code to that new template:

    %PI="\n"%
    %ClassNotes%
    typedef %classTag:"returnType"% (*%className%)(
    %list="Attribute" @separator=",\n" @indent="    "%
    );
    
    1. Modified the Attribute Declaration code template. Same way as before, adding in a new Stereotype

    2. Add in the following code to the new template:

    %PI=""% %attConst=="T" ? "const" : ""%

    %attType%

    %attContainment=="By Reference" ? "*" : ""%

    %attName%

    That's all that I had to do to get function pointers in place in Enterprise Architect. When I want to define a function pointer I just:

    1. Create a regular class
    2. Add in the tag 'returnType' with the type of return I want
    3. Add in attributes for the parameters.

    This way it'll create a new type that can be included as attributes or parameters in other classes (structures), and operators. I didn't make it an operator itself because then it wouldn't have been referenced inside the tool as a type you can select.

    So its a bit hacky, using special stereotyped classes as typedefs to function pointers.

    0 讨论(0)
提交回复
热议问题