Changeset 750cff for src/documentation/constructs/serialization.dox
- Timestamp:
- Oct 31, 2011, 5:13:52 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, Candidate_v1.7.0, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 5982c5
- Parents:
- 19bc74
- File:
-
- 1 edited
-
src/documentation/constructs/serialization.dox (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/documentation/constructs/serialization.dox
r19bc74 r750cff 14 14 * Author: heber 15 15 */ 16 17 /** \page serialization Serialization 18 * 19 * Serialization is a mighty concept. The is only possible within an object- 20 * oriented framework. The member variables of a class make up its internal 21 * state. By storing this state, creating another instance and restoring 22 * the variables to this state, we may in essence clone the instance. However, 23 * we obtain additional control as to the moment of restoration because the 24 * internal state is stored temporarily. To allow for this storage all of 25 * these variables have to be \e serialized. 26 * 27 * Serialization refers to putting one after another into a writable form 28 * (e.g. convert to string and write into a stringstream) and eventually 29 * in reverse order to read them one by one from this writable form and 30 * cast them back into their original type. 31 * 32 * Here, this is done via boost::serialization. 33 * 34 * \attention The serialization headers do not mingle well with \b MemDebug.hpp. 35 * Hence, place them before MemDebug.hpp as they do funny stuff with the 36 * new() operator. 37 * 38 * Serialization is so powerful because the stored state can be stored to 39 * disk, transfered to another thread or even to another computer. If received 40 * by a compatible code, the instance is recreated and computation can be 41 * continued elsewhere. 42 * 43 * For the moment we use it for creating an undo state within the Action's. 44 * I.e. we store the state of all instances that are modified by an Action's 45 * doings and may in Action::performUndo() just re-create the unmodified 46 * instance by loading them from the serializing archive. 47 * 48 * \section serialization-add How to make your class serializable. 49 * 50 * \subsection serialization-add-simple The simple case 51 * 52 * All you need to do with your newly created class foo is this: 53 * \code 54 * class foo { 55 * ... 56 * private: 57 * friend class boost::serialization::access; 58 * template<class Archive> 59 * void serialize(Archive & ar, const unsigned int version) const 60 * { 61 * ar & content; 62 * } 63 * ... 64 * double content; 65 * }; 66 * \endcode 67 * This will implement a serialization function for both directions for the 68 * member variable content. I.e. we may now store a class instance as this: 69 * \code 70 * #include <boost/archive/text_oarchive.hpp> 71 * std::stringstream stream; 72 * boost::archive::text_oarchive oa(stream); 73 * oa << diagonal; 74 * \endcode 75 * This will store the state of the class in the stringstream \a stream. 76 * Getting the instance back is then as easy as 77 * \code 78 * #include <boost/archive/text_iarchive.hpp> 79 * boost::archive::text_iarchive ia(stream); 80 * RealSpaceMatrix *newm; 81 * ia >> newm; 82 * \endcode 83 * 84 * \subsection serialization-add-complicated The more complicated case 85 * 86 * It gets trickier when load and store need to be done differently, e.h. 87 * \code 88 * class foo { 89 * ... 90 * private: 91 * friend class boost::serialization::access; 92 * // serialization 93 * template<class Archive> 94 * void save(Archive & ar, const unsigned int version) const 95 * { 96 * ar & content; 97 * } 98 * template<class Archive> 99 * void load(Archive & ar, const unsigned int version) 100 * { 101 * ar & content; 102 * createViews(); 103 * } 104 * BOOST_SERIALIZATION_SPLIT_MEMBER() 105 * ... 106 * } 107 * \endcode 108 * Here, we split serialize() function into distinct load() and save() because 109 * we have to call an additional function to fully re-store the instance, i.e. 110 * it creates some internal reference arrays (Views) in a specific manner. 111 * 112 * The serialize functions can also be added externally, i.e. outside of the 113 * scope of the class, but can then access only public members (except we 114 * again make it a friend). 115 * 116 * 117 * \date 2011-10-31 118 */
Note:
See TracChangeset
for help on using the changeset viewer.
