source: src/Parser/FormatParserStorage.cpp@ 60239f

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 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
Last change on this file since 60239f was 60239f, checked in by Frederik Heber <heber@…>, 15 years ago

MEMFIX: output streams in FormatParserStorage::SaveAll() were not free'd

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/** \file FormatParserStorage.cpp
2 *
3 * date: Jun, 22 2010
4 * author: heber
5 *
6 */
7
8#include <iostream>
9#include <fstream>
10
11#include "Parser/FormatParserStorage.hpp"
12
13#include "Parser/FormatParser.hpp"
14#include "Parser/MpqcParser.hpp"
15#include "Parser/PcpParser.hpp"
16#include "Parser/TremoloParser.hpp"
17#include "Parser/XyzParser.hpp"
18
19#include "log.hpp"
20#include "verbose.hpp"
21
22#include "Helpers/Assert.hpp"
23
24#include "Patterns/Singleton_impl.hpp"
25
26/** Increment operator for the enumeration ParserTypes to allow loops.
27 * \param &type value
28 * \return value incremented by one
29 */
30ParserTypes &operator++(ParserTypes &type)
31{
32 return type = ParserTypes(type+1);
33}
34
35/** Constructor of class FormatParserStorage.
36 */
37FormatParserStorage::FormatParserStorage()
38{
39 ParserList.resize(ParserTypes_end, NULL);
40 ParserStream.resize(ParserTypes_end, NULL);
41 ParserPresent.resize(ParserTypes_end, false);
42 ParserSuffix.resize(ParserTypes_end, "");
43
44 ParserSuffix[mpqc] = "conf.in";
45 ParserSuffix[pcp] = "conf";
46 ParserSuffix[tremolo] = "conf.data";
47 ParserSuffix[xyz] = "conf.xyz";
48}
49
50/** Destructor of class FormatParserStorage.
51 * Free all stored FormatParsers.
52 * Save on Exit.
53 */
54FormatParserStorage::~FormatParserStorage()
55{
56 for (ParserTypes iter = ParserTypes_begin; iter < ParserTypes_end; ++iter)
57 if (ParserPresent[iter]) {
58 if (ParserStream[iter]->is_open())
59 ParserStream[iter]->close();
60 delete ParserStream[iter];
61 delete ParserList[iter];
62 }
63}
64
65/** Sets the filename of all current parsers in storage to prefix.suffix.
66 * \param &prefix prefix to use.
67 */
68void FormatParserStorage::SetOutputPrefixForAll(std::string &_prefix)
69{
70 prefix=_prefix;
71};
72
73
74void FormatParserStorage::SaveAll()
75{
76 std::string filename;
77 for (ParserTypes iter = ParserTypes_begin; iter < ParserTypes_end; ++iter)
78 if (ParserPresent[iter]) {
79 filename = prefix;
80 filename += ".";
81 filename += ParserSuffix[iter];
82 ParserStream[iter] = new std::ofstream(filename.c_str());
83 ParserList[iter]->setOstream((std::ostream *)ParserStream[iter]);
84 }
85}
86
87
88/** Adds an MpqcParser to the storage.
89 */
90void FormatParserStorage::addMpqc()
91{
92 if (!ParserPresent[mpqc]) {
93 ParserList[mpqc] = dynamic_cast<FormatParser *>(new MpqcParser);
94 ParserPresent[mpqc] = true;
95 }
96 else
97 DoeLog(1) && (eLog() << Verbose(1) << "Parser mpqc is already present." << endl);
98}
99
100/** Adds an PcpParser to the storage.
101 */
102void FormatParserStorage::addPcp()
103{
104 if (!ParserPresent[pcp]) {
105 ParserList[pcp] = new PcpParser();
106 ParserPresent[pcp] = true;
107 } else
108 DoeLog(1) && (eLog() << Verbose(1) << "Parser pcp is already present." << endl);
109}
110
111
112/** Adds an TremoloParser to the storage.
113 */
114void FormatParserStorage::addTremolo()
115{
116 if (!ParserPresent[tremolo]) {
117 ParserList[tremolo] = new TremoloParser();
118 ParserPresent[tremolo] = true;
119 } else
120 DoeLog(1) && (eLog() << Verbose(1) << "Parser tremolo is already present." << endl);
121}
122
123
124/** Adds an XyzParser to the storage.
125 */
126void FormatParserStorage::addXyz()
127{
128 if (!ParserPresent[xyz]) {
129 ParserList[xyz] = new XyzParser();
130 ParserPresent[xyz] = true;
131 } else
132 DoeLog(1) && (eLog() << Verbose(1) << "Parser xyz is already present." << endl);
133}
134
135/** Returns reference to the output MpqcParser, adds if not present.
136 * \return reference to the output MpqcParser
137 */
138MpqcParser &FormatParserStorage::getMpqc()
139{
140 if (!ParserPresent[mpqc])
141 addMpqc();
142 return dynamic_cast<MpqcParser &>(*ParserList[mpqc]);
143}
144
145/** Returns reference to the output PcpParser, adds if not present.
146 * \return reference to the output PcpParser
147 */
148PcpParser &FormatParserStorage::getPcp()
149{
150 if (!ParserPresent[pcp])
151 addPcp();
152 return dynamic_cast<PcpParser &>(*ParserList[pcp]);
153}
154
155/** Returns reference to the output TremoloParser, adds if not present.
156 * \return reference to the output TremoloParser
157 */
158TremoloParser &FormatParserStorage::getTremolo()
159{
160 if (!ParserPresent[tremolo])
161 addTremolo();
162 return dynamic_cast<TremoloParser &>(*ParserList[tremolo]);
163}
164
165/** Returns reference to the output XyzParser, adds if not present.
166 * \return reference to the output XyzParser
167 */
168XyzParser &FormatParserStorage::getXyz()
169{
170 if (!ParserPresent[xyz])
171 addXyz();
172 return dynamic_cast<XyzParser &>(*ParserList[xyz]);
173}
174
175
176
177CONSTRUCT_SINGLETON(FormatParserStorage)
Note: See TracBrowser for help on using the repository browser.