Created
September 10, 2017 20:22
-
-
Save lironsade/99a7e7951c2950099a33c404fa23986c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by liron on 9/7/17. | |
// | |
#include <memory> | |
#include "ShapeFactory.h" | |
/** | |
* Creates a shape of the given type and points. | |
* @param shapeType type of shape | |
* @param points points vector | |
* @return a shape if it is valid, nullptr otherwise. | |
*/ | |
Shape *ShapeFactory::createShape(char shapeType, std::vector<Point> points) | |
{ | |
Shape *s; | |
//TODO: shared_ptr | |
switch (shapeType) | |
{ | |
case TRIANGLE: | |
s = new Triangle{points}; | |
break; | |
case TRAPEZOID: | |
s = new Trapezoid{points}; | |
break; | |
default: | |
return nullptr; | |
} | |
if (s->isValid()) | |
{ | |
return s; | |
} | |
delete s; | |
return nullptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment