I have a poorly written class which has about 300+ private data members.
I would like to know if there is a method that already exists somewhere within c++ that will take all the private data members and write them to a file.
Since I am a researcher and I am analyzing data, my code will never be implemented for public use, so for the sake of progress I would not like to spend much time on making my code look and work elegant. I just need to progress.
With that said, it is a pain for me to write each of the 300+ members by hand. ie. fHistogramPt->Write();
If I simply write the whole class I have to a file, then I have to ensure that I have written 300+ unique getters to access the private members.
I could always just make all the private data members public, and write the whole class to the file. But even I have some basic rules I do not like to break.
I was thinking of throwing all my private data members into a list instead and just saving the list. I've never bothered with lists before, can I put differnt objects in a list?
In case this helps: I have ensured that each data member has a unique name and title. So if lists were able to allow searching, I could search for the name when I want to retrieve the object, instead of remembering which index belongs to which object.
I hope this was clear enough. I just reread this post and it is indeed confusing, but it is a confusing matter.
Wait, are you trying to print out the data inside an object, or are you trying to print out the members of the class? A distinction must be drawn.
Be wary of this: http://en.wikipedia.org/wiki/God_object
So, if I understand correctly you have something like this :
1 2 3 4 5 6 7 8 9
class poorly_written_class {
public:
void print(); //for printing
private:
int i1;
int i2;
//..
int i300;
};
Are the types of the data members the same? Are their names have a pattern like mine?
The reason I ask because if they have some sort of similarity, then you can easily generate code, which would print the data out.
If the members have different types and/or names, then the generator *can* get a little more complicated.
Please post some example code, so we can get a more specific solution for you.
I'm sorry about my jargon.
I have never taken a computing class, so I sling out the wrong words all the time.
I am trying to write only the private data members of a class to a file.
For completeness here is a quick mock up of my class:
class class_name {
public:
member1;
private:
member2;
...
member367;
} object_names;
I would like to just write member 2 thorugh 367 to a file simply.
I've known about the God object syndrome. I still catch myself in that situation once in a while, but this is luckily not one of them