Author Topic: C++ resources - free functions and template  (Read 3292 times)

W. J. La Cholter

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
C++ resources - free functions and template
« on: March 21, 2009, 12:24:19 pm »
I'm interested in approaches/resources in Enterprise Architect for a couple of techniques in C++ that get a little less play in the UML world: free functions and C++ metaprogramming.

I've successfully reverse-engineered C code into Enterprise Architect, but I haven't found anything on how to reverse engineer or generate C++ free (non-member) functions. For example, is there a way to generate the following Standard library function (which is not a member of a class)?

UnaryFunction for_each( iterator start, iterator end, UnaryFunction f );
http://www.cppreference.com/wiki/stl/algorithm/for_each


With Rational Rose, I've seen utility classes. It looks like I might be able to customize the generation template to generate free functions. But using anonymous with utility stereotype does not work out of the box (it generates an error stating that anonymous class generation is unsupported).

Is there an approach out there?

On the metaprogramming side, are there any approaches to model C++ template metaprograms, such as those written with Boost MPL, http://www.boost.org/doc/libs/release/libs/mpl/doc/index.html?
Metaprograms are a little different in that they're functional. From an implementor's perspect, that's more motivation to have a UML modeling approach to get a handle on things. For example, I'd love to see a UML model of the Boost MPL, including sequences.

Thanks,
William

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: C++ resources - free functions and template
« Reply #1 on: March 23, 2009, 09:06:46 am »
EA will not reverse engineer non-member functions.

I haven't really looked at metaprogramming, but as a guide, if it's recognizable as classes, then it's likely to be reverse engineered.  Otherwise it's not.

W. J. La Cholter

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: C++ resources - free functions and template
« Reply #2 on: March 26, 2009, 11:25:07 pm »
Quote
EA will not reverse engineer non-member functions.

Does the scripting engineer included in EA 7.5 Corporate or any other feature now provide a workaround? E.g., could I inject hooks on generation to have anonymous classes generate functions and other items? Is there a way to invoke a script on the reverse-engineering side?

Quote
I haven't really looked at metaprogramming, but as a guide, if it's recognizable as classes, then it's likely to be reverse engineered.  Otherwise it's not.

The purpose would be to model them differently from plain old classes. Conceptually the classes are functions, the template parameters are function parameters, and specifying a class becomes a function call. Rather than just modeling them like template classes that have parameters, they could be better modeled as free functions, given an appropriate transformation. For example type information can be calculated at compile time:
// short-hands
struct true_type { static const bool value = true; };
struct false_type { static const bool value = false; };
template <typename T>
struct is_integral: public boost::false_type{}; // default
template <>
struct is_integral<int>: public boost::true_type; // partial specialization
struct is_integral<short>: public boost::true_type;

The naive representation is a bunch of classes.
A better representation is a set of free functions and constants with a stereotype to indicate they're template metafunctions, which would result in a different transformation.

It looks like EA 7.1 Professional allows some customization via generation templates. It does not appear to offer round-trip engineering. Would the new script customizations allow that?

Would there also be a way to improve parsing of C++ member data pointers, which cause an error in the code below?
struct Foo { int bar; }

void assign_foos_bar(int (Foo::*member), Foo & foo, int v) {
    foo.*member = v;
}
void invoke {
    Foo foo;
    assign_foos_bar(&Foo::bar, foo, 42);
    cout << foo.bar << endl; // prints 42
}

I realize these are the nether reaches of a 20 year-old programming language, but they're important things to model for a project of mine.

Thank you,
William La Cholter