INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Auto generate get and set functions from class variables

Auto generate get and set functions from class variables

(OP)
I have created a site to ease the development of good object oriented code by automatically generating get and set functions

http://www.houen.net/codegenerator/index.php

Simply paste in all your instance variables and it will respond with get and set functions. It supports Java, C#, PHP, Flash and C++.

Java example:

private int num_users;
private String email;


generates

//-------------QUERIES-------------
public int get_num_users() {
   return this.num_users;
}
public String get_email() {
   return this.email;
}
//-------------COMMANDS------------
public void set_num_users(int num_users) {
   this.num_users = num_users;
}
public void set_email(String email) {
   this.email = email;
}

Whether you want camelCase or under_score in the function
name is up to you. I hope you find it useful

RE: Auto generate get and set functions from class variables

camelCase?
What if you want ThisKindOfCase() instead of thisKindOfCase()

Also, your C++ parser doesn't appear to be working.  If you put something like this in:

CODE

std::string m_Str;
std::vector<int> m_Vec;
int m_Int;
float m_Float;
it just says:

Quote:

No suitable instance variables found. Are they formatted right?

RE: Auto generate get and set functions from class variables

Actually, it's not completely broken.  Templates don't seem to work, but you need to show an example like this:

CODE

class Test
{
private:
  std::string m_Str;
  std::vector<int> m_Vec;
  float m_Float;
  int m_Int;
};
If I use that code, your site generates functions for everything except the vector.

BTW, it would be nice if it could generate non-C-style braces.  Ex.:

CODE

//-------------QUERIES-------------
public: string getStr()
{
   return m_Str;
}
Rather than:

CODE

//-------------QUERIES-------------
public: string getStr() {
   return m_Str;
}

RE: Auto generate get and set functions from class variables

(OP)
You're absolutely right. Duly noted and code fixed!
Vector, double colons, example and nextline braces are now added.
The option to start functions with an upper-case character will take more to implement, so i wont be adding that in the near future. Time to get some sleep :)

Thx for the corrections

RE: Auto generate get and set functions from class variables

Cool.
Almost working.  Now it recognizes the vector but leaves off the template type:

CODE

//-------------QUERIES-------------
public: std::vector getVec() {
   return m_Vec;
}
//-------------COMMANDS------------
public: void setVec(std::vector Vec) {
   m_Vec = Vec;
}
With the following input:

CODE

private:
    std::vector<int> m_Vec;
It should return:

CODE

//-------------QUERIES-------------
public: std::vector<int> getVec() {
   return m_Vec;
}
//-------------COMMANDS------------
public: void setVec(std::vector<int> Vec) {
   m_Vec = Vec;
}
Otherwise it won't compile.

RE: Auto generate get and set functions from class variables

(OP)
There we go :) Try it now. Turned out the problem wasnt the functions but the fact that <foobar> is a html tag and obviously had to be converted :S

Once again thx for the input

RE: Auto generate get and set functions from class variables

Fixed.

Now I tried a vector of vectors and it couldn't parse it:

CODE

private:
  std::vector<std::vector<int> > m_Vec;
NOTE: The space between the two '>' characters must be preserved.

RE: Auto generate get and set functions from class variables

(OP)
Hi

I added support for vector of vectors as in your example

RE: Auto generate get and set functions from class variables

Here's a couple more examples that don't work:

CODE

private:
  std::map<std::vector<int>, std::list<int> > m_Map1;
  std::map<std::vector<int>::iterator, std::list<int>::iterator> m_Map2;
Can you tell I've been doing QA for most of my career?  winky smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close