Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

kernel.h

00001 /***************************************************************************
00002                         kernel.h  -  description
00003                             -------------------
00004     begin                : nov 29th 2005
00005     copyright            : (C) 2005 by Duong-Khang NGUYEN
00006     email                : neoneurone @ users sourceforge net
00007     author               : Victor STINNER
00008     
00009     $Id: kernel.h 32 2006-08-06 18:59:25Z neoneurone $
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   any later version.                                                    *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 
00022 #ifndef _OPENCITY_KERNEL_H_
00023 #define _OPENCITY_KERNEL_H_ 1
00024 
00025 #include "agent.h"
00026 
00027 #include <map>
00028 #include <list>
00029 
00030 // Forward declaration
00031 class Message;
00032 
00033 
00034    /*=====================================================================*/
00038 class Kernel
00039 {
00040 public:
00041     Kernel();
00042     ~Kernel();
00043 
00044     unsigned long getStep() const;
00045 
00046 //========================================================================
00050     void live();
00051 
00052     AgentID_t getAgentUniqId();
00053 
00054 //========================================================================
00059     static Kernel* getSingleton();
00060 
00061     void registerAgent(Agent* agent);
00062     void registerRole(Agent *agent, Role_t role);
00063     void unregisterAgent(Agent* agent);
00064     void unregisterRole(Agent *agent, Role_t role);
00065 
00066 //========================================================================
00071     void killAgent(Agent* agent);
00072 
00073     void sendMessage(Role_t role, const Message& msg);
00074     void sendMessageToAgent(AgentID_t agent, const Message& msg);
00075 
00076     
00077 private:
00078     static Kernel* m_singleton;             
00079 
00080     unsigned long m_step;
00081     std::map<AgentID_t, Agent*> m_white_pages;
00082     typedef std::map<AgentID_t, Agent*>::iterator m_white_pages_it;
00083     std::map<Role_t, std::list<Agent*> > m_yellow_pages;
00084     typedef std::map<Role_t, std::list<Agent*> >::iterator m_yellow_pages_it;
00085     typedef std::list<Agent*>::iterator m_agent_set_it;
00086     std::list<Agent*> m_agent_dying;
00087     typedef std::list<Agent*>::iterator m_agent_dying_it;
00088     AgentID_t m_agent_uniq_id;
00089 
00090 
00091    /*=====================================================================*/
00092    /*                        PRIVATE     METHODS                          */
00093    /*=====================================================================*/
00094     Agent& getAgentById(AgentID_t agent);
00095 };
00096 
00097 
00098 #endif
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 

Generated on Sat Nov 11 10:21:10 2006 for OpenCity by  doxygen 1.4.2