]> ruin.nu Git - germs.git/commitdiff
modelFactory method, to help create models
authorMichael Andreen <harv@ruin.nu>
Tue, 14 Aug 2007 10:44:54 +0000 (10:44 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 14 Aug 2007 10:44:54 +0000 (10:44 +0000)
src/model.cpp
src/model.h

index 715d7c2f1a9f5a5ee068d88ca74e95726ad29ebc..efd5c5f4d9ae6fc85d2b1e8cb6ac0177a32c0aa3 100644 (file)
@@ -21,6 +21,8 @@
 #include "model.h"
 #include "models.h"
 
+#include <stdexcept>
+
 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");
+}
index 8bc41d4bcf73da0bf9b4c1d366360ccce00b8f0e..4869793c407fe7bb2800136df715b03733588089 100644 (file)
@@ -22,6 +22,7 @@
 #define __MODEL_H__
 
 #include <tr1/memory>
+#include <string>
 
 class SortAction;
 class GeneOrder;
@@ -53,6 +54,8 @@ class Model{
 
                const char* name() const;
 
+               static Model modelFactory(const std::string& name);
+
        private:
                ModelPointer _impl;