Solved

Dumping content of object to a file/screen

Posted on 2002-04-17
12
248 Views
Last Modified: 2010-04-02
I have a class called 'EquSol' like

class EquSol  
{
private:
     int          m_CurrentOffset;
     EquVar*          m_Result;
     EquEquation**     m_Equations;
}


and I am using

EquSol  Obj;

I would like to dump the content of 'Obj' to a file so I am
thinking of adding a public method to class 'EquSol', that will
take input as object and dump its content to screen/file.

Any idea how to do this?

 
0
Comment
Question by:billclinton6
  • 3
  • 2
  • 2
  • +5
12 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6948697
What about

class EquSol; //foward decl.

class DumpEquSol {

 DumpEquSol ( ofstream* pos) : m_pos ( pos) {}; // ctor for file dumping
 DumpEquSol ( ) : m_pos ( 0) {}; // ctor for screendumping

 void operator << ( const EquSol&);

private:

 ofstream* m_pos;
};

class EquSol  
{
friend class DumpEquSol;
private:
    int          m_CurrentOffset;
    EquVar*          m_Result;
    EquEquation**     m_Equations;
}

void DumpEquSol::operator << ( const EquSol& r) {

 if ( !m_pos) { // dump to screen

   cout << "m_CurrentOffset" << r.m_CurrentOffset;

  //...
 } else {

  *m_pos << "m_CurrentOffset" << r.m_CurrentOffset;

 }
}

And use it like

DumpEquSol dumper;
EquSol obj;

dumper << obj;
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 6948951
You can use solution like this:
class EquSol  
{
   void Dump(ostream& out);
private:
    int          m_CurrentOffset;
    EquVar*          m_Result;
    EquEquation**     m_Equations;
}

void EquSol::Dump(ofstream& out)
{
   out << "m_CurrentOffset" << m_CurrentOffset;
  ....
}

main()
{
  EquSol obj;

obj.Dump(cout);
obj.Dump(file);

}
0
 
LVL 22

Expert Comment

by:ambience
ID: 6949793
just a thought

public:
void dump(ostream& out, int nlevel)
{
    switch(nlevel)
    {
        case 1: out << m_CurrentOffset;
                ...
                break;  // dump our own data
       
        case 2: out << m_CurrentOffset;
                m_Result->dump(out, 1);
                break;  // ask aggregates to dump their data

        case 3: out << m_CurrentOffset;
                m_Result->dump(out, 3);
                break;  // full dump
    };
}

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:monicalewinsky6
ID: 6952332
hey bill!  If that doesn't help, maybe i can think of some way to be of service.
0
 

Expert Comment

by:ComTech
ID: 7013464
We have seperated you two before, I have done it myself this time.  :>

ComTech
CS Admin @ EE

See ya Monica
0
 
LVL 86

Expert Comment

by:jkr
ID: 7013768
Would you mind to shed in some light, ComTech? :o)
0
 

Expert Comment

by:ComTech
ID: 7013898
The monica account is a joke, since this users name is bill clinton.

The Monica account is on hold.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7014042
Well, I did notice that - I thought I was missing something else :o)

Thanx!
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7036247
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,

** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7097484
Maybe I'm not a joke but billclinton6 is.  Hard to tell, don't you think?
0
 
LVL 11

Expert Comment

by:griessh
ID: 7122105
Dear billclinton6

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

If you think your question was not answered at all, you can explain here why you want to do this and post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/


PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7138056
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question