blob: e31d669508fb9a958dddfc5b74506408bf027266 [file] [log] [blame]
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001#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
8using namespace vpd::keyword::parser;
9using namespace openpower::vpd::memory::parser;
10using namespace openpower::vpd::parser::interface;
11using namespace openpower::vpd::ipz::parser;
12
13namespace openpower
14{
15namespace vpd
16{
17namespace parser
18{
19namespace factory
20{
21interface::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
47void 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