1 /*
2  *  cASCPPParameter.h
3  *  Avida
4  *
5  *  Created by David Bryson on 9/14/08.
6  *  Copyright 2008-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 cASCPPParameter_h
23 #define cASCPPParameter_h
24 
25 #include "avida/Avida.h"
26 #include "AvidaScript.h"
27 
28 #include "cString.h"
29 
30 template<class NativeClass> class tASNativeObject;
31 
32 
33 class cASCPPParameter
34 {
35 private:
36   union {
37     bool m_bool;
38     char m_char;
39     int m_int;
40     double m_float;
41     cString* m_string;
42     cASNativeObject* m_nobj;
43   };
44 
45 public:
cASCPPParameter()46   cASCPPParameter() { ; }
47 
Set(bool val)48   void Set(bool val) { m_bool = val; }
Set(char val)49   void Set(char val) { m_char = val; }
Set(int val)50   void Set(int val) { m_int = val; }
Set(double val)51   void Set(double val) { m_float = val; }
Set(cString * val)52   void Set(cString* val) { m_string = val; }
Set(const cString & val)53   void Set(const cString& val) { m_string = new cString(val); }
Set(cASNativeObject * val)54   void Set(cASNativeObject* val) { m_nobj = val; }
Set(tASNativeObject<NativeClass> * val)55   template<class NativeClass> void Set(tASNativeObject<NativeClass>* val) { m_nobj = val; }
Set(NativeClass * val)56   template<class NativeClass> void Set(NativeClass* val) { m_nobj = new tASNativeObject<NativeClass>(val); }
57 
58   template<typename T> inline T Get() const;
59 
60 };
61 
62 
63 template<> inline bool cASCPPParameter::Get<bool>() const { return m_bool; }
64 template<> inline char cASCPPParameter::Get<char>() const { return m_char; }
65 template<> inline int cASCPPParameter::Get<int>() const { return m_int; }
66 template<> inline double cASCPPParameter::Get<double>() const { return m_float; }
67 template<> inline const cString& cASCPPParameter::Get<const cString&>() const { return *m_string; }
68 template<> inline const cString* cASCPPParameter::Get<const cString*>() const { return m_string; }
69 template<> inline cString* cASCPPParameter::Get<cString*>() const { return m_string; }
70 template<> inline cASNativeObject* cASCPPParameter::Get<cASNativeObject*>() const { return m_nobj; }
71 
72 #endif
73