-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_parser.h
123 lines (97 loc) · 2.88 KB
/
product_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef PRODUCT_PARSER_H
#define PRODUCT_PARSER_H
#include <string>
#include <iostream>
#include "product.h"
class ProductParser
{
public:
ProductParser();
virtual ~ProductParser();
/**
* Parses product info from the given input stream
*/
Product* parse(std::string category,
std::istream& is,
bool& error,
std::string& errorMsg,
int& lineno);
/**
* Returns the product category for this parser
*/
virtual std::string categoryID() = 0;
protected:
/**
* Parses the common data members of a product
*/
void parseCommonProduct(std::istream& is,
bool& error,
std::string& errorMsg,
int& lineno);
/**
* Parses the unique data members of a specific product type
* and allocates a specific Product object
*/
virtual Product* parseSpecificProduct(std::string category,
std::istream& is,
bool& error,
std::string& errorMsg,
int& lineno) = 0;
/**
* Dynamically allocates a specific product type from the data
* parsed and stored in the specific product parser
*/
virtual Product* makeProduct() = 0;
std::string prodName_;
double price_;
int qty_;
};
class ProductBookParser : public ProductParser
{
public:
ProductBookParser();
Product* parseSpecificProduct(std::string category,
std::istream& is,
bool& error,
std::string& errorMsg,
int& lineno);
std::string categoryID();
protected:
Product* makeProduct();
private:
std::string isbn_;
std::string author_;
};
class ProductClothingParser : public ProductParser
{
public:
ProductClothingParser();
Product* parseSpecificProduct(std::string category,
std::istream& is,
bool& error,
std::string& errorMsg,
int& lineno);
std::string categoryID();
protected:
Product* makeProduct();
private:
std::string size_;
std::string brand_;
};
class ProductMovieParser : public ProductParser
{
public:
ProductMovieParser();
Product* parseSpecificProduct(std::string category,
std::istream& is,
bool& error,
std::string& errorMsg,
int& lineno);
std::string categoryID();
protected:
Product* makeProduct();
private:
std::string genre_;
std::string rating_;
};
#endif