1 /*
2  *  cHardwareManager.h
3  *  Avida
4  *
5  *  Created by David on 10/18/05.
6  *  Copyright 1999-2011 Michigan State University. All rights reserved.
7  *
8  *
9  *  This file is part of Avida.
10  *
11  *  Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
12  *  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
13  *
14  *  Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License along with Avida.
18  *  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef cHardwareManager_h
23 #define cHardwareManager_h
24 
25 #include "cTestCPU.h"
26 #include "tDictionary.h"
27 
28 namespace Avida {
29   class Genome;
30 };
31 
32 class cAvidaContext;
33 class cHardwareBase;
34 class cInstSet;
35 class cOrganism;
36 class cStringList;
37 class cUserFeedback;
38 class cWorld;
39 template<typename T> class tList;
40 
41 using namespace Avida;
42 
43 
44 class cHardwareManager
45 {
46 private:
47   cWorld* m_world;
48   tArray<cInstSet*> m_inst_sets;
49   tDictionary<int> m_is_name_map;
50 
51   cHardwareManager(); // @not_implemented
52   cHardwareManager(const cHardwareManager&); // @not_implemented
53   cHardwareManager& operator=(const cHardwareManager&); // @not_implemented
54 
55 
56 public:
57   cHardwareManager(cWorld* world);
58   ~cHardwareManager();
59 
60   bool LoadInstSets(cUserFeedback* feedback = NULL);
61   bool ConvertLegacyInstSetFile(cString filename, cStringList& str_list, cUserFeedback* feedback = NULL);
62 
63   cHardwareBase* Create(cAvidaContext& ctx, cOrganism* org, const Genome& mg);
CreateTestCPU(cAvidaContext & ctx)64   inline cTestCPU* CreateTestCPU(cAvidaContext& ctx) { return new cTestCPU(ctx, m_world); }
65 
IsInstSet(const cString & name)66   inline bool IsInstSet(const cString& name) const { return m_is_name_map.HasEntry(name); }
67 
68   inline const cInstSet& GetInstSet(const cString& name) const;
69   inline cInstSet& GetInstSet(const cString& name);
GetInstSet(int i)70   const cInstSet& GetInstSet(int i) const { return *m_inst_sets[i]; }
71 
GetDefaultInstSet()72   const cInstSet& GetDefaultInstSet() const { return *m_inst_sets[0]; }
73 
GetNumInstSets()74   int GetNumInstSets() const { return m_inst_sets.GetSize(); }
75 
76   bool RegisterInstSet(const cString& name, cInstSet* inst_set);
77 
78 private:
79   bool loadInstSet(int hw_type, const cString& name, cStringList& sl, cUserFeedback* feedback);
80 };
81 
82 
GetInstSet(const cString & name)83 inline const cInstSet& cHardwareManager::GetInstSet(const cString& name) const
84 {
85   return (name == "(default)") ? *m_inst_sets[0] : *m_inst_sets[m_is_name_map.Get(name)];
86 }
87 
GetInstSet(const cString & name)88 inline cInstSet& cHardwareManager::GetInstSet(const cString& name)
89 {
90   return (name == "(default)") ? *m_inst_sets[0] : *m_inst_sets[m_is_name_map.Get(name)];
91 }
92 
93 #endif
94