Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 1st, 2005, 2:41 PM   #1
Jhaqen
Newbie
 
Join Date: Nov 2005
Posts: 4
Rep Power: 0 Jhaqen is on a distinguished road
Access to private files.

Hello, if anyone could help me with this I'd be extremely grateful.

I have been asked to write a driver program, where I read symbols from a source file, and write a description of it to an output file.

I have three classes,

Host ~ contains methods for opening/closing, writing/reading from files.

SourceHandler ~ uses methods from the Host class to read from the source file and write to an output file in a certain format.

Analyser ~ Uses SourceHandler methods to read a symbol from the source file.

It has been specified that I must use the SourceHandler class to open the output file, I then use the analyser class to read a symbol from the source file, I now need to write a description to the output file, but the output file is declared as private in the SourceHandler class, so I cannot use methods from the Host class to write to it, and there is no public methods in the SourceHandler class that lets me write to it.

How can I get around this without modifying and of the three listed classes?

Thanks for any suggestions.
Jhaqen is offline   Reply With Quote
Old Nov 2nd, 2005, 2:33 PM   #2
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Is said output file a file that already exists? In other words, does the SourceHandler open an already existing file, or does it create one?

Either way I really don't see why the fact that the SourceHandler declares the file as private is a problem for your class. As long as SourceHandler closes out the file, then it should just save in the directory specified (or current directory if none is specified) and then your program should be able to open it up for writing as well. (Unless SourceHandler sets special permissions on that file...but that would be a whole different story.)

Now, if you program is trying to write to that file while SourceHandler still has it open...THAT would indeed prove to be a problem...the only way I can think around that is to have your class write to a different file altogether and then write a helper class to merge the two files for the desired end result.

Perhaps this is unhelpful...I may have misunderstood you're problem. Hope it adds some sort of insight though.
MegaArcon is offline   Reply With Quote
Old Nov 2nd, 2005, 3:35 PM   #3
Jhaqen
Newbie
 
Join Date: Nov 2005
Posts: 4
Rep Power: 0 Jhaqen is on a distinguished road
SourceHandler creates a file, it doesn't close it each time it writes to it, there is a method in SourceHandler to close the file that states that "Compilation was completed on... etc.", I use that at the end of my program.

If the output file was not private in SourceHandler, I could create/open it using a SourceHandler method, use a method from the Host class to write to it, then close it using a SourceHandler method, but as it is private, I cannot modify it using the Host method, unless I write a method in the SourceHandler class itself, which I am not allowed to do.

Thanks for the help.
Jhaqen is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC