Skip to content

Instantly share code, notes, and snippets.

@lironsade
Created September 10, 2017 20:22
Show Gist options
  • Save lironsade/99a7e7951c2950099a33c404fa23986c to your computer and use it in GitHub Desktop.
Save lironsade/99a7e7951c2950099a33c404fa23986c to your computer and use it in GitHub Desktop.
//
// 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