From 6c059509f0e7230c2352963e559b623fadd27810 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 14 Aug 2007 10:44:54 +0000 Subject: [PATCH] modelFactory method, to help create models --- src/model.cpp | 17 +++++++++++++++++ src/model.h | 3 +++ 2 files changed, 20 insertions(+) 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; -- 2.39.2