From: Michael Andreen Date: Tue, 14 Aug 2007 10:44:54 +0000 (+0000) Subject: modelFactory method, to help create models X-Git-Tag: v0.1~26 X-Git-Url: https://ruin.nu/git/?p=germs.git;a=commitdiff_plain;h=6c059509f0e7230c2352963e559b623fadd27810 modelFactory method, to help create models --- diff --git a/src/model.cpp b/src/model.cpp index 715d7c2..efd5c5f 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -21,6 +21,8 @@ #include "model.h" #include "models.h" +#include + Model::Model(Models::ModelImpl* model): _impl(model){ } @@ -35,3 +37,18 @@ const char* Model::name() const{ bool operator<(const Model& lh,const Model& rh){ return &lh < &rh; } + +Model Model::modelFactory(const std::string& name){ + if (name == "X"){ + return Model(new Models::X()); + }else if(name == "Whirl" || name == "Standard"){ + return Model(new Models::ModelImpl()); + }else if(name == "Zipper"){ + return Model(new Models::Zipper()); + }else if(name == "FatX"){ + return Model(new Models::FatX()); + }else if(name == "Cloud"){ + return Model(new Models::Cloud()); + } + throw std::invalid_argument(name + " is not a valid model"); +} diff --git a/src/model.h b/src/model.h index 8bc41d4..4869793 100644 --- a/src/model.h +++ b/src/model.h @@ -22,6 +22,7 @@ #define __MODEL_H__ #include +#include class SortAction; class GeneOrder; @@ -53,6 +54,8 @@ class Model{ const char* name() const; + static Model modelFactory(const std::string& name); + private: ModelPointer _impl;