SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame^] | 1 | #include "parser_factory.hpp" |
| 2 | |
| 3 | #include "ipz_parser.hpp" |
| 4 | #include "keyword_vpd_parser.hpp" |
| 5 | #include "memory_vpd_parser.hpp" |
| 6 | #include "utils.hpp" |
| 7 | |
| 8 | using namespace vpd::keyword::parser; |
| 9 | using namespace openpower::vpd::memory::parser; |
| 10 | using namespace openpower::vpd::parser::interface; |
| 11 | using namespace openpower::vpd::ipz::parser; |
| 12 | |
| 13 | namespace openpower |
| 14 | { |
| 15 | namespace vpd |
| 16 | { |
| 17 | namespace parser |
| 18 | { |
| 19 | namespace factory |
| 20 | { |
| 21 | interface::ParserInterface* ParserFactory::getParser(Binary&& vpdVector) |
| 22 | { |
| 23 | vpdType type = vpdTypeCheck(vpdVector); |
| 24 | |
| 25 | switch (type) |
| 26 | { |
| 27 | case IPZ_VPD: |
| 28 | { |
| 29 | return new IpzVpdParser(std::move(vpdVector)); |
| 30 | } |
| 31 | |
| 32 | case KEYWORD_VPD: |
| 33 | { |
| 34 | return new KeywordVpdParser(std::move(vpdVector)); |
| 35 | } |
| 36 | |
| 37 | case MEMORY_VPD: |
| 38 | { |
| 39 | return new memoryVpdParser(std::move(vpdVector)); |
| 40 | } |
| 41 | |
| 42 | default: |
| 43 | throw std::runtime_error("Invalid VPD format"); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void ParserFactory::freeParser(interface::ParserInterface* parser) |
| 48 | { |
| 49 | if (parser) |
| 50 | { |
| 51 | delete parser; |
| 52 | parser = nullptr; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | } // namespace factory |
| 57 | } // namespace parser |
| 58 | } // namespace vpd |
| 59 | } // namespace openpower |