467,081 Members | 1,251 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

Tool to convert public mem var RWs to use accessor methods?

I've inherited two "C++" code bases that I have to tie together
and both of them make frequest use of public member variables
in spite of all the information saying this limits flexibility. Well,
their lack of foresight has bit me of course! I'd like to start off
by converting all their public member variable accesses to the
use of accessor methods. Then, I can reimplement selected
accessor methods to provide the necessary glue between the
code bases.

The question is....is there a tool that can automatically perform
this sort of transformation to accessor methods from public
member variables?

thanks,

Todd
Jul 19 '05 #1
  • viewed: 1891
Share:
2 Replies
Sounds like a job for regular expressions, e.g., in C++ or Perl.

Todd A. Anderson wrote:
I've inherited two "C++" code bases that I have to tie together
and both of them make frequest use of public member variables
in spite of all the information saying this limits flexibility. Well,
their lack of foresight has bit me of course! I'd like to start off
by converting all their public member variable accesses to the
use of accessor methods. Then, I can reimplement selected
accessor methods to provide the necessary glue between the
code bases.

The question is....is there a tool that can automatically perform
this sort of transformation to accessor methods from public
member variables?

thanks,

Todd


Jul 19 '05 #2
In article <bd**********@news01.intel.com>, dr****@aaahawk.com says...

[ ... ]
The question is....is there a tool that can automatically perform
this sort of transformation to accessor methods from public
member variables?


I don't know of anything that does it entirely automatically, but right
now operator overloading just became one of your best friends.

Instead of attempting to find every place every variable is used, look
only for where they're declared, which is usually a LOT easier. Convert
each from its current type to an instance of a class that overloads
operator=(T const &) and operator T (where T is the original type).
These are your new "accessor" functions -- operator T converts your type
to the original type just before its value gets assigned, and operator=
gets called (of course) to assign some value to your object.

IMO, even if this didn't save a tremendous amount of work, it would
still be the way to go -- using accessor and mutator functions is almost
always quite ugly.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by jerrygarciuh | last post: by
22 posts views Thread by mirandacascade@yahoo.com | last post: by
22 posts views Thread by Generic Usenet Account | last post: by
10 posts views Thread by Zap | last post: by
3 posts views Thread by James | last post: by
27 posts views Thread by thomasp@msala.net | last post: by
8 posts views Thread by Tim Sprout | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.