-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassFactory.cpp
More file actions
43 lines (39 loc) · 2.04 KB
/
ClassFactory.cpp
File metadata and controls
43 lines (39 loc) · 2.04 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClassFactory.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgonor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/05 17:38:15 by dgonor #+# #+# */
/* Updated: 2018/12/05 17:38:17 by dgonor ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClassFactory.hpp"
#include "ClassOperand.hpp"
#include <climits>
IOperand const * Factory::createInt8( std::string const & value ) const {
return (new Operand<char>(static_cast<char>(std::stoi(value))));
}
IOperand const * Factory::createInt16( std::string const & value ) const {
return (new Operand<short>(static_cast<short>(std::stoi(value))));
}
IOperand const * Factory::createInt32( std::string const & value ) const {
return (new Operand<int>(static_cast<int>(std::stoi(value))));
}
IOperand const * Factory::createFloat( std::string const & value ) const {
return (new Operand<float>(static_cast<float>(std::stof(value))));
}
IOperand const * Factory::createDouble( std::string const & value ) const {
return (new Operand<double>(static_cast<double>(std::stod(value))));
}
IOperand const * Factory::createOperand( eOperandType type, std::string const & value ) const {
IOperand const *(Factory::*method[])(std::string const &value) const = {
&Factory::createInt8,
&Factory::createInt16,
&Factory::createInt32,
&Factory::createFloat,
&Factory::createDouble
};
return ((this->*method[type])(value));
}