source: src/Parser/FormatParserStorage.cpp@ bbbad5

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

Added MemDebug.hpp to each and every .cpp file (were it was still missing).

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