Langmuir
Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agent.h
Go to the documentation of this file.
1 #ifndef AGENT_H
2 #define AGENT_H
3 
4 #include <QTextStream>
5 #include <QMetaObject>
6 #include <QMetaEnum>
7 #include <QVector>
8 #include <QObject>
9 #include <QString>
10 #include <QDebug>
11 
12 namespace LangmuirCore
13 {
14 
15 class World;
16 
18 
24 class Agent : public QObject
25 {
26 private:
27  Q_OBJECT
28  Q_DISABLE_COPY(Agent)
29  Q_ENUMS(Type)
30 
31 public:
33  enum Type
34  {
36  Empty = 0,
37 
39  Electron = 1,
40 
42  Hole = 2,
43 
45  Defect = 3,
46 
48  Source = 4,
49 
51  Drain = 5,
52 
54  SIZE = 6
55  };
56  static QString toQString(const Agent::Type e);
57 
58 public:
60 
67  Agent(Type type, World &world, int site = 0, QObject *parent = 0);
68 
70  virtual ~Agent();
71 
73  const QVector<int>& getNeighbors() const;
74 
76  void setNeighbors(QVector<int> neighbors);
77 
79  int getCurrentSite() const;
80 
82  int getFutureSite() const;
83 
85  void setCurrentSite(int site);
86 
88  void setFutureSite(int site);
89 
91  Type getType() const;
92 
94  World& getWorld() const;
95 
96 protected:
97 
99  int m_site;
100 
102  int m_fSite;
103 
106 
108  QVector<int> m_neighbors;
109 
112 };
113 
114 inline Agent::Agent(Type type, World &world, int site, QObject *parent) : QObject(parent),
115  m_site(-1), m_fSite(site), m_world(world), m_type(type)
116 {
117 }
118 
120 {
121 }
122 
123 inline void Agent::setNeighbors(QVector<int> neighbors)
124 {
125  m_neighbors = neighbors;
126 }
127 
128 inline const QVector<int>& Agent::getNeighbors() const
129 {
130  return m_neighbors;
131 }
132 
133 inline int Agent::getCurrentSite() const
134 {
135  return m_site;
136 }
137 
138 inline int Agent::getFutureSite() const
139 {
140  return m_fSite;
141 }
142 
143 inline void Agent::setCurrentSite(int site)
144 {
145  m_site = site;
146 }
147 
148 inline void Agent::setFutureSite(int site)
149 {
150  m_fSite = site;
151 }
152 
154 {
155  return m_type;
156 }
157 
158 inline World& Agent::getWorld() const
159 {
160  return m_world;
161 }
162 
164 inline QString Agent::toQString(const Agent::Type e)
165 {
166  const QMetaObject &QMO = Agent::staticMetaObject;
167  QMetaEnum QME = QMO.enumerator(QMO.indexOfEnumerator("Type"));
168  return QString("%1").arg(QME.valueToKey(e));
169 }
170 
172 inline QTextStream &operator<<(QTextStream &stream,const Agent::Type e)
173 {
174  return stream << Agent::toQString(e);
175 }
176 
178 inline QDebug operator<<(QDebug dbg,const Agent::Type e)
179 {
180  return dbg << qPrintable(Agent::toQString(e));
181 }
182 
183 }
184 #endif
void setFutureSite(int site)
Set Agent future site.
Definition: agent.h:148
Agent(Type type, World &world, int site=0, QObject *parent=0)
Create an Agent.
Definition: agent.h:114
int getCurrentSite() const
Get Agent current site.
Definition: agent.h:133
A class that abstractly represents an object that can occupy grid sites.
Definition: agent.h:24
QTextStream & operator<<(QTextStream &stream, const Agent::Type e)
Output Agent type enum to stream.
Definition: agent.h:172
Defective Grid site.
Definition: agent.h:45
Type
An identifier for the type of Agent.
Definition: agent.h:33
SourceAgent.
Definition: agent.h:48
ElectronAgent.
Definition: agent.h:39
static QString toQString(const Agent::Type e)
Convert Agent type enum to QString.
Definition: agent.h:164
virtual ~Agent()
Destroy Agent.
Definition: agent.h:119
A class to hold all objects in a simulation.
Definition: world.h:51
Type m_type
Agent Type enum.
Definition: agent.h:111
int m_fSite
Future site the Agent will occupy.
Definition: agent.h:102
Type getType() const
Get Agent::Type enum.
Definition: agent.h:153
DrainAgent.
Definition: agent.h:51
HoleAgent.
Definition: agent.h:42
World & m_world
Reference to World object.
Definition: agent.h:105
Number of Agent Types.
Definition: agent.h:54
int m_site
Current site the Agent occupies.
Definition: agent.h:99
Definition: agent.h:12
const QVector< int > & getNeighbors() const
Get Agent neighbor list.
Definition: agent.h:128
void setCurrentSite(int site)
Set Agent current site.
Definition: agent.h:143
World & getWorld() const
Get Langmuir::World reference.
Definition: agent.h:158
QVector< int > m_neighbors
List fo neighboring site ids.
Definition: agent.h:108
Empty Grid site.
Definition: agent.h:36
void setNeighbors(QVector< int > neighbors)
Set Agent neighbor list.
Definition: agent.h:123
int getFutureSite() const
Get Agent future site.
Definition: agent.h:138