| 1 | /** \file FormatParserStorage.hpp
|
|---|
| 2 | *
|
|---|
| 3 | * date: Jun, 22 2010
|
|---|
| 4 | * author: heber
|
|---|
| 5 | *
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef FORMATPARSERSTORAGE_HPP_
|
|---|
| 9 | #define FORMATPARSERSTORAGE_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #include "Patterns/Singleton.hpp"
|
|---|
| 17 |
|
|---|
| 18 | #include <string>
|
|---|
| 19 | #include <map>
|
|---|
| 20 | #include <vector>
|
|---|
| 21 |
|
|---|
| 22 | class FormatParser;
|
|---|
| 23 | class MpqcParser;
|
|---|
| 24 | class PdbParser;
|
|---|
| 25 | class PcpParser;
|
|---|
| 26 | class TremoloParser;
|
|---|
| 27 | class XyzParser;
|
|---|
| 28 |
|
|---|
| 29 | // enum has to be outside of class for operator++ to be possible
|
|---|
| 30 | enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
|
|---|
| 31 | typedef enum ParserTypes ParserTypes;
|
|---|
| 32 |
|
|---|
| 33 | ParserTypes &operator++(ParserTypes &type);
|
|---|
| 34 |
|
|---|
| 35 | class FormatParserStorage : public Singleton<FormatParserStorage> {
|
|---|
| 36 | friend class Singleton<FormatParserStorage>;
|
|---|
| 37 | public:
|
|---|
| 38 |
|
|---|
| 39 | void addMpqc();
|
|---|
| 40 | void addPcp();
|
|---|
| 41 | void addPdb();
|
|---|
| 42 | void addTremolo();
|
|---|
| 43 | void addXyz();
|
|---|
| 44 | bool add(std::string type);
|
|---|
| 45 | bool add(ParserTypes type);
|
|---|
| 46 |
|
|---|
| 47 | bool get(std::istream &input, std::string suffix);
|
|---|
| 48 | MpqcParser &getMpqc();
|
|---|
| 49 | PcpParser &getPcp();
|
|---|
| 50 | PdbParser &getPdb();
|
|---|
| 51 | TremoloParser &getTremolo();
|
|---|
| 52 | XyzParser &getXyz();
|
|---|
| 53 |
|
|---|
| 54 | ParserTypes getTypeFromName(std::string type);
|
|---|
| 55 | ParserTypes getTypeFromSuffix(std::string type);
|
|---|
| 56 |
|
|---|
| 57 | void SetOutputPrefixForAll(std::string &_prefix);
|
|---|
| 58 | void SaveAll();
|
|---|
| 59 |
|
|---|
| 60 | private:
|
|---|
| 61 | // private constructors as this is a singleton
|
|---|
| 62 | FormatParserStorage();
|
|---|
| 63 | ~FormatParserStorage();
|
|---|
| 64 |
|
|---|
| 65 | // list of allocated parsers
|
|---|
| 66 | std::vector<FormatParser *> ParserList;
|
|---|
| 67 |
|
|---|
| 68 | // list of allocated strams
|
|---|
| 69 | std::vector<std::ofstream *> ParserStream;
|
|---|
| 70 |
|
|---|
| 71 | // which parser is already present
|
|---|
| 72 | std::vector<bool> ParserPresent;
|
|---|
| 73 |
|
|---|
| 74 | // default suffix of each parser type
|
|---|
| 75 | std::map<ParserTypes, std::string> ParserSuffixes;
|
|---|
| 76 | std::map<std::string, ParserTypes> ParserLookupSuffixes;
|
|---|
| 77 |
|
|---|
| 78 | // function pointers to each add...()
|
|---|
| 79 | std::map< ParserTypes, void (FormatParserStorage::*)() > ParserAddFunction;
|
|---|
| 80 |
|
|---|
| 81 | // type name of each parser type and reverse lookup
|
|---|
| 82 | std::map<ParserTypes, std::string> ParserNames;
|
|---|
| 83 | std::map<std::string, ParserTypes> ParserLookupNames;
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | // prefix of the filenames to use on save
|
|---|
| 87 | std::string prefix;
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | #endif // FORMATPARSERSTORAGE_HPP_
|
|---|