Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29286 Discussions

Recognising changes in Data Structures

acar
Beginner
1,048 Views
Hi, the application that I'm developing is an engineering application. Users open an existing model database file, do some work, and then save the file. I need a feature to check whether or not the user has actually changed the data in a model so that he/she can be prompted appropriately to save before closing/quiting the application. I have created a rudimentary way of doing this by writing out the structure to file before and after editing and then comparing checksums. This method is not particularly elegant and the checksum routine I obtained is a stand alone executable that I need to run via the SYSTEM command (and thus temporarily throws up a console window over my application). I also have a suspicion that the method is not bomb-proof.
I wonder therefore if anyone has any suggestions or recommendations on how one might implement this?
Thanks,
Angus.
0 Kudos
8 Replies
Arjen_Markus
Honored Contributor II
1,048 Views
You could keep track of changes (at least in a rough way) by setting a flag each time the user
presses an OK button or whatever is relevant in your application. Irealise that this is
not always possible or reliable and then saving the data in a file is indeed a much easier
way.
To compare the contents of two files, you could use an MPD5 checksum orSHA1 or any of
these cryptographic keys. You ought to be able to find plenty of implementations on the Internet
for them. It would then be a matter of creating an interface to the routine(s) and then you'd
be independent of an external program

Regards,

Arjen
0 Kudos
IanH
Honored Contributor III
1,048 Views
In a GUI application this would often be handled by having every event handling procedure that could modify the data set a document-global file-has-been-changed flag. This same flag is cleared when the document is saved, or if the entire undo stack since the last save gets popped.

(In your case, every "user entry point" style procedure in the "do some work" part of your description would need to set this flag.)

0 Kudos
anthonyrichards
New Contributor III
1,048 Views
Let's hope that you hold a protected master copy of the data file that user's cannot screw up and replace with the screwed-up version?
0 Kudos
acar
Beginner
1,048 Views
Thanks arjenmarkus, the software already knows where a data structure might change so I just need a checking routine. I'll take another look for an implementation of the checksum routines you suggest.
0 Kudos
acar
Beginner
1,048 Views
Thanks IanH, yes I already know when the data might change using my own flag model_database_changed. I just need a quick and reliable method for making the check as to whether or not the data in a structure has changed.
0 Kudos
acar
Beginner
1,048 Views
Good point - hopefully my software will protect the user against this .... but that is yet to be tried in practise! I have not yet coded an undo/redo facility into the software but that is probably something I need to consider for the future.
0 Kudos
Paul_Curtis
Valued Contributor I
1,048 Views
All edit dialogs should operate on a copy of the original data structure. If the user ends the edit with "ok/accept", the edited copy then replaces the original and sets the "changed" flag; if the user cancels the dialog, the edited material simply vaporises and the original is left intact.
0 Kudos
acar
Beginner
1,048 Views
Thanks Paul. It took me some time to recognise that this is what I should be doing but I do now operate in this way.
0 Kudos
Reply