| [52baf9] | 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 | /** Constructor of class FormatParserStorage.
 | 
|---|
 | 27 |  */
 | 
|---|
 | 28 | FormatParserStorage::FormatParserStorage()
 | 
|---|
 | 29 | {
 | 
|---|
 | 30 |   ParserList.resize(ParserTypes_end, NULL);
 | 
|---|
 | 31 |   ParserPresent.resize(ParserTypes_end, false);
 | 
|---|
 | 32 |   ParserSuffix.resize(ParserTypes_end, "");
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 |   ParserSuffix[mpqc] = "conf.in";
 | 
|---|
 | 35 |   ParserSuffix[pcp] = "conf";
 | 
|---|
 | 36 |   ParserSuffix[tremolo] = "conf.data";
 | 
|---|
 | 37 |   ParserSuffix[xyz] = "conf.xyz";
 | 
|---|
 | 38 | }
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | /** Destructor of class FormatParserStorage.
 | 
|---|
 | 41 |  * Free all stored FormatParsers. 
 | 
|---|
 | 42 |  * Save on Exit.
 | 
|---|
 | 43 |  */
 | 
|---|
 | 44 | FormatParserStorage::~FormatParserStorage()
 | 
|---|
 | 45 | {
 | 
|---|
 | 46 |   for (ParserTypes iter = ParserTypes_begin; iter < ParserTypes_end; ++iter)
 | 
|---|
 | 47 |     if (ParserPresent[iter])
 | 
|---|
 | 48 |       delete ParserList[iter];
 | 
|---|
 | 49 | }
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | /** Sets the filename of all current parsers in storage to prefix.suffix.
 | 
|---|
 | 52 |  * \param &prefix prefix to use.
 | 
|---|
 | 53 |  */
 | 
|---|
 | 54 | void FormatParserStorage::SetOutputPrefixForAll(std::string &_prefix)
 | 
|---|
 | 55 | {
 | 
|---|
 | 56 |   prefix=_prefix;
 | 
|---|
 | 57 | };
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 | void FormatParserStorage::SaveAll()
 | 
|---|
 | 61 | {
 | 
|---|
 | 62 |   std::string filename;
 | 
|---|
 | 63 |   for (ParserTypes iter = ParserTypes_begin; iter < ParserTypes_end; ++iter)
 | 
|---|
 | 64 |     if (ParserPresent[iter]) {
 | 
|---|
 | 65 |       filename = prefix;
 | 
|---|
 | 66 |       filename += ".";
 | 
|---|
 | 67 |       filename += ParserSuffix[iter];
 | 
|---|
 | 68 |       std::ofstream *file = new std::ofstream(filename.c_str());
 | 
|---|
 | 69 |       ParserList[iter]->setOstream((std::ostream *)file);
 | 
|---|
 | 70 |     }
 | 
|---|
 | 71 | }
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | /** Adds an MpqcParser to the storage.
 | 
|---|
 | 75 |  */
 | 
|---|
 | 76 | void FormatParserStorage::AddMpqc()
 | 
|---|
 | 77 | {
 | 
|---|
 | 78 |   if (!ParserPresent[mpqc])
 | 
|---|
 | 79 |     ParserList[mpqc] = dynamic_cast<FormatParser *>(new MpqcParser);
 | 
|---|
 | 80 |   else
 | 
|---|
 | 81 |     DoeLog(1) && (eLog() << Verbose(1) << "Parser mpqc is already present." << endl);
 | 
|---|
 | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | /** Adds an PcpParser to the storage.
 | 
|---|
 | 85 |  */
 | 
|---|
 | 86 | void FormatParserStorage::AddPcp()
 | 
|---|
 | 87 | {
 | 
|---|
 | 88 |   if (!ParserPresent[pcp])
 | 
|---|
 | 89 |     ParserList[pcp] = new PcpParser();
 | 
|---|
 | 90 |   else
 | 
|---|
 | 91 |     DoeLog(1) && (eLog() << Verbose(1) << "Parser pcp is already present." << endl);
 | 
|---|
 | 92 | }
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | /** Adds an TremoloParser to the storage.
 | 
|---|
 | 96 |  */
 | 
|---|
 | 97 | void FormatParserStorage::AddTremolo()
 | 
|---|
 | 98 | {
 | 
|---|
 | 99 |   if (!ParserPresent[tremolo])
 | 
|---|
 | 100 |     ParserList[tremolo] = new TremoloParser();
 | 
|---|
 | 101 |   else
 | 
|---|
 | 102 |     DoeLog(1) && (eLog() << Verbose(1) << "Parser tremolo is already present." << endl);
 | 
|---|
 | 103 | }
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 | /** Adds an XyzParser to the storage.
 | 
|---|
 | 107 |  */
 | 
|---|
 | 108 | void FormatParserStorage::AddXyz()
 | 
|---|
 | 109 | {
 | 
|---|
 | 110 |   if (!ParserPresent[xyz])
 | 
|---|
 | 111 |     ParserList[xyz] = new XyzParser();
 | 
|---|
 | 112 |   else
 | 
|---|
 | 113 |     DoeLog(1) && (eLog() << Verbose(1) << "Parser xyz is already present." << endl);
 | 
|---|
 | 114 | }
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | 
 | 
|---|
 | 117 | CONSTRUCT_SINGLETON(FormatParserStorage)
 | 
|---|