How can I save references to a file?

Hi,
I just ran into a really tricky problem where I'm trying to write objects to a file. The problem is like :
class A
B b1;
B b2;
The two B objects may be references to the same object, they don't have to be. How can I write this structure to a file? I want to be able to recreate it exactly, with references to objects kept intact. If the two B objects were referencing the same object I still want them to reference the same object after reading in from a file.
Naturally, the above example is an oversimplified one. My problem is actually much more complex involving superclasses, subclasses, bla bla bla, but this is the fundamental thing I can't do.
If anyone has any ideas whatsoever please share them. I'm really desperate, filehandling is key to my project and my teacher couldn't help me.
Thank you to anyone that replies.

Is there a way to do it without Serializable?
Strictly speaking I'm allowed to use Serializable,
I'm supposed to write out the ints and floats myself,
but if all else fails maybe I can plead to the
teacher. =)Then basically the teacher wants you to replicate what serialization already does.
Presumably what you are writing is very simple.
Say you have the following...
           class Data
                 int i;
                 String s;
           class Holder
                 Data d1;
                 Data d2;
The first task is write out a Data. So you figure out how to write an int and how to write a String. This could look something like this in the file(all text, each item on a different line)
          int:i: 47
          string:s: test
  Next you need to identify a reference. Notice that a reference is a type, just as int and String is.
A reference is a pointer. And you need some way to point.
So one way is to add another element to each class which is a unique id. Thus when you write a Data out it would look like the following...
          id::  1
          int:i: 47
          string:s: test
  And then when you write out Holder it would look like this...
          id:: 3
          ref:d1:  1
          ref:d2:  2
  So your entire file for the code sample given would look like this...
          id::  1
          int:i: 47
          string:s: test
          id::  2
          int:i: 53
          string:s: test other
          id:: 3
          ref:d1:  1
          ref:d2:  2
   Keep in mind that you must write the referenced objects first. Thus Holder must always come after Data.

Similar Messages

  • How can I sav an emailed .mov file to my iPad?

    How can I sav an emailed .mov file to my iPad?

    Yes there is, if you hold down the attachment widget in the email once the video is downloaded, it will give you a series of options to save it to, including camera roll. 
    Hope this solves your question. 
    Cheers,
    Allen

  • How can I save a Motion 5 file as a video?

    How can I save a Motion 5 file as a video? I want to use it in an iMovie Project.

    Everything about using Motion, including exporting a video (and much more), is available either in the application or online:
    Help Menu> Motion 5 Help: see the Share Motion Projects chapter.
    The manual can also be found online here: http://www.apple.com/support/motion/
    Finally there is also this link to the manual: http://help.apple.com/motion/mac/5.1/

  • Email attachments: whenever someone sends me a file the Ipad labels it winmail.dat and wont allow me to open it...these are Word, Exce or jpgs.  Does anyone know why this is and how to fix it?  Also, how can you save attachments to a file on the IPad2

    whenever someone sends me a file the Ipad labels it winmail.dat and wont allow me to open it...these are Word, Exce or jpgs.  Does anyone know why this is and how to fix it?  Also, how can you save attachments to a file on the IPad2

    Is this a particular sender, or all of your attchments?  Google winmail.dat and you will see a number of returns that can explain this, but in short, this is the way some e mail providers deal with attachments.  If all of your e mail is coming that way, you need to change a setting on your isp set up.  Perhaps stary here...
    http://www.nytimes.com/2010/11/25/technology/personaltech/25askk.html

  • HT4623 How can I save the update download file as I have several devises to upgrade and cant afford the bandwidth to do each via iTunes

    How can I save the update download file as I have several devises to upgrade and cant afford the bandwidth to do each via iTunes.
    There does not appeare to be any doenloadable files in the download section.

    "Well that's totally unacceptable."
    Actually you can only accept it, as it is the way it is.  You may not like it, but it is so.  Sorry.
    " your seriously telling me that Apple expect me to download the same huge file 8 TIMES"
    That is exactly what I am telling you.
    " No way."
    Still true.
    "Apple are going to have to come up with another solution."
    No.  They do not have to do any such thing.  They may choose to do so in the future, but there is no reason to believe that they will.

  • How can I save a rotated pdf file?

    I have received a pdf file of many pages in landscape orientation that need to be saved in portrait orientation.  I know how to rotate the file, but how can I save the rotated document?
    [This is my first entry, so apologies if I have got my entries mixed up]
    Laurie

    Hello Laurie,
    Unfortunately this does not work with Adobe Reader, but with Adobe Acrobat or similar programs (Google could be your friend ) BUT you could try Acrobat free for 30 days, if you'd like. See www.adobe.com/products/acrobat.html for more information.
    Hans-Günter

  • How can I save an edited converted file?

    How can I save an edited converted (from PDF) file?

    Hi alisonr1825446,
    When you convert a PDF file to Word/Excel, it's automatically saved to your Acrobat.com online account. From there, you can download it to your desktop to edit it, and then save it. To download your file, log in to https://cloud.acrobat.com/files. Select the file, and then click the Download link at the top of the file list. Your file will be downloaded to the Downloads folder on your computer.
    Please let us know how it goes.
    Best,
    Sara

  • How can i save my work pdf files and personal pdf files separately in my ipadmini

    Hi,
    I would like some help on separating my personal and work pdf files in my ipad. Currently i saved everything in ibook but find it unprofessional when i have to show my clients my work
    Is there any other way to save my work pdf files separately?
    trena.c

    If you still would like to use Ibooks you can add Collections. i.e.. work pdf's
    View your collections, add a new one.
    Now go to the pdf's you want to add to that collection and move them to the new collection you have just created.
    Hope this helps.
    PJRS

  • How can I save a CYMK PSD file as a PDF in CS5?

    I am able to make the file in CS4 on another computer I use (PC).  However when I try to save a CYMK PSD file as a PDF in Photoshop CS5 I don't see the option in the drop down menu?  Any ideas?  Here are some of the file details
    CMYK
    PSD
    8 bits/channel
    Thanks
    Evren

    For some reason when I started my computer this morning and went to take a screen grab of my intent the option was there.  Could it be because I had to install Adobe Acrobat Pro?  I guess that would more than likely be a obvious thing-?
    For some reason when I was given Adobe Master Suite at work Acrobat didn't come with.
    Thanks for your assistance.

  • How can I save an attached ZIP file

    I cannot access an attached ZIP file in Acrobat XI Pro. Please help as this is becoming a huge time waster.

    Hi alisonr1825446,
    When you convert a PDF file to Word/Excel, it's automatically saved to your Acrobat.com online account. From there, you can download it to your desktop to edit it, and then save it. To download your file, log in to https://cloud.acrobat.com/files. Select the file, and then click the Download link at the top of the file list. Your file will be downloaded to the Downloads folder on your computer.
    Please let us know how it goes.
    Best,
    Sara

  • How can I save or export the file containing stored usernames and passwords?

    I'm about to update my desktop computer's operating system, which will mean my hard drive will be wiped. I want to save any file Firefox might have that contains usernames and passwords so I don't have to rebuild that file once Firefox is reinstalled. I've found such files for extensions and bookmarks but not for passwords.

    In article: http://kb.mozillazine.org/Password_Manager#Backing_up_and_restoring_passwords
    *'''Backing up and restoring passwords '''
    **Firefox '''''3.5 and later versions''''', including current beta and nightly builds, use '''''signons.sqlite'''''.
    *'''Troubleshooting'''
    **Firefox '''''3.5 and later versions''''' use the file '''''signons.sqlite''''' to store the encrypted names and passwords. passwords.
    **You can rename '''''signons.sqlite''''' to signons.sqlite.sav to make Firefox '''''3.5+''''' versions use the file signons#.txt from a previous Firefox 3 or 2 version.
    ***'''''3.5+''''' = same as '''''3.5 and later versions'''''
    Also:
    *http://kb.mozillazine.org/Profile_folder_-_Firefox#Files_and_folders_in_the_profile
    *https://support.mozilla.com/en-US/kb/Backing+up+your+information
    *http://kb.mozillazine.org/Profile_backup
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox
    *http://support.mozilla.com/en-US/kb/Recovering+important+data+from+an+old+profile
    *

  • How can i save and load .txt files

    right now i am writing an encryption prog but can't figure out how to save the encrypted text or load encrypted text for decrypting. can someone help me?

    java.io.FileWriter/FileReader

  • How can I save a Quicktime 7 file to be read by Quicktime 6.5.2?

    Hi, I have quicktime 7.5 and must save an avi file in a format that can be read by my friend's computer. He is using Quicktime 6.5.2 and running OSX.2.8.
    Please help!
    Thanks

    It does not have to be an avi file. As long as Quicktime 6.5.2 can read it.
    Almost any currently exportable "native" QT compression format other than H.264 should be compatible with QT 6.5.2 playback. MPEG4/AAC, for instance, should be good all the way back to QT v6.0 if you want to use it. Legacy codecs will take you back even further if needed.
    I don't have Quicktime Pro and neither does he.
    Use the free MPEG Streamclip converter application as your "front-end" to access QT Pro export options. It is still compatible with OS 10.2 (Jaguar) and later.

  • How can i save a book organized files from CS5 to CS4?

    I have a problem – a client has catalogues in CS5 and their translations agency work in CS4.
    Catalogues are book organised and everyone contains 30-40 files so opening each one saving as idml, opening in CS4, saving in CS4, adding to book and looking for problems takes really long time.
    Is there any short cut to make this faster!?
    Thank you in advance.

    Sorry, it'll be impossible for any of us (the forum regulars) to post in this thread without making obvious suggestions like this; it's safe to ignore these suggestions, I understand that you are powerless here to make reasonable suggestions like "Fire the incompetent translation firm that can't keep up with its clients and retain one that actually has the licenses for the apps necessary to complete the project."  If nothing else, all of the people who search Google for the phrase "translation downsave CS5 CS4 book" will learn that the best answer is "tell your translation supplier that they will lose your business if they fail to upgrade."
    But in your case - no, I know of no such script to re-save a CS4 book from IDMLs spat out of CS5. The scripting forum is thataway; maybe they know of a script someone else has already written for this purpose. Mostly because, especically in a book file, one of the steps before saving the INDDs and book in CS4 should be "a human compares the IDML opened in CS4 against the INDDs in CS5, or PDFs generated from same, before Saving As CS4 INDD."

  • How can I save an Acrobat X file back to Acrobat 8

    Hello,
    What is the best way to save back a version or two, when you are creating Acrobat X files.
    I need to get a few back to 8.0 and 9.0.
    Is there any way to do this from within Acroabt X?
    Thanks
    Babs

    ACTUALLY!!! You got me on the right track, with one minor adjustment.
    I was already using the Save As, Optimize PDF for something and didn't see the compatibility option right there on the top!
    This way I do not have to worry about the quality.
    This will do it!!
    Thanks so much to both of you!
    babs

Maybe you are looking for