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 | bool put(std::ostream &output, std::string suffix);
|
---|
49 | MpqcParser &getMpqc();
|
---|
50 | PcpParser &getPcp();
|
---|
51 | PdbParser &getPdb();
|
---|
52 | TremoloParser &getTremolo();
|
---|
53 | XyzParser &getXyz();
|
---|
54 |
|
---|
55 | ParserTypes getTypeFromName(std::string type);
|
---|
56 | ParserTypes getTypeFromSuffix(std::string type);
|
---|
57 |
|
---|
58 | void SetOutputPrefixForAll(std::string &_prefix);
|
---|
59 | void SaveAll();
|
---|
60 |
|
---|
61 | private:
|
---|
62 | // private constructors as this is a singleton
|
---|
63 | FormatParserStorage();
|
---|
64 | ~FormatParserStorage();
|
---|
65 |
|
---|
66 | // list of allocated parsers
|
---|
67 | std::vector<FormatParser *> ParserList;
|
---|
68 |
|
---|
69 | // list of allocated strams
|
---|
70 | std::vector<std::ofstream *> ParserStream;
|
---|
71 |
|
---|
72 | // which parser is already present
|
---|
73 | std::vector<bool> ParserPresent;
|
---|
74 |
|
---|
75 | // default suffix of each parser type
|
---|
76 | std::map<ParserTypes, std::string> ParserSuffixes;
|
---|
77 | std::map<std::string, ParserTypes> ParserLookupSuffixes;
|
---|
78 |
|
---|
79 | // function pointers to each add...()
|
---|
80 | std::map< ParserTypes, void (FormatParserStorage::*)() > ParserAddFunction;
|
---|
81 |
|
---|
82 | // type name of each parser type and reverse lookup
|
---|
83 | std::map<ParserTypes, std::string> ParserNames;
|
---|
84 | std::map<std::string, ParserTypes> ParserLookupNames;
|
---|
85 |
|
---|
86 |
|
---|
87 | // prefix of the filenames to use on save
|
---|
88 | std::string prefix;
|
---|
89 | };
|
---|
90 |
|
---|
91 | #endif // FORMATPARSERSTORAGE_HPP_
|
---|