Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

class.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: class.h,v 1.12 2004/04/10 08:55:46 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 
00022    Class
00023 
00024    HISTORY:
00025                 04.06.2002 MK
00026                         - initial version
00027 
00028 */
00029 #ifndef ZEITGEIST_CLASS_H
00030 #define ZEITGEIST_CLASS_H
00031 
00032 #include <zeitgeist/scriptserver/gcvalue.h>
00033 
00034 #ifdef HAVE_CONFIG_H
00035 #include <config.h>
00036 #endif
00037 
00038 #ifdef HAVE_HASH_MAP
00039 #include <hash_map>
00040 #else
00041 #include <map>
00042 #endif
00043 
00044 #include <string>
00045 #include <vector>
00046 #include <list>
00047 #include <salt/defines.h>
00048 #include <salt/sharedlibrary.h>
00049 #include "leaf.h"
00050 #include "parameterlist.h"
00051 
00052 namespace zeitgeist
00053 {
00054 
00055 #define CLASS(className)        Class_##className
00056 
00057 #define DECLARE_CLASS(className)\
00058     class CLASS(className) : public zeitgeist::Class\
00059     {\
00060     public:\
00061         CLASS(className)() : zeitgeist::Class(#className) { DefineClass(); }\
00062         zeitgeist::Object* CreateInstance() const\
00063         {\
00064             zeitgeist::Object *instance = new className();\
00065             return instance;\
00066         }\
00067     private:\
00068         void DefineClass();\
00069     };
00070 
00071 #define DECLARE_ABSTRACTCLASS(className)\
00072     class CLASS(className) : public zeitgeist::Class\
00073     {\
00074     public:\
00075         CLASS(className)() : zeitgeist::Class(#className) { DefineClass();  }\
00076     private:\
00077         void DefineClass();\
00078     };
00079 
00080 
00081 // note the 'unused' attribute suppresses compiler warnings if the
00082 // 'in' parameter is not accessed in the function implementation
00083 #define FUNCTION(className,functionName)\
00084     static zeitgeist::GCValue functionName(className *obj, \
00085          __attribute__((unused)) const zeitgeist::ParameterList &in)
00086 
00087 #define DEFINE_FUNCTION(functionName)\
00088     mFunctions[#functionName] = (TCmdProc) &functionName;
00089 
00090 #define DEFINE_BASECLASS(baseClass)\
00091     mBaseClasses.push_back(#baseClass);
00092 
00093 //
00094 // Export stuff
00095 //
00096 #define ZEITGEIST_EXPORT_BEGIN()\
00097     using namespace boost;\
00098     using namespace salt;\
00099     using namespace zeitgeist;\
00100     extern "C"{\
00101     SHARED_LIB_EXPORT void Zeitgeist_RegisterBundle(std::list <shared_ptr<Class> > &classes){
00102 
00103 #define ZEITGEIST_EXPORT_EX(className, path)\
00104     classes.push_back(shared_ptr<Class>(new CLASS(className)));
00105 
00106 #define ZEITGEIST_EXPORT(className) ZEITGEIST_EXPORT_EX(className, "")
00107 
00108 #define ZEITGEIST_EXPORT_END()\
00109         }}
00110 
00111 // forward declarations
00112 class Core;
00113 
00135 class Class : public Leaf
00136 {
00137     // friends
00138     friend class Object;
00139     friend class Core;
00140 
00141     //
00142     // types
00143     //
00144 public:
00151     typedef GCValue (*TCmdProc)(Object* , const zeitgeist::ParameterList &in);
00152     typedef std::list<std::string> TStringList;
00153 
00154 private:
00156     typedef std::list< boost::weak_ptr<Object> > TObjectList;
00157 
00159 #ifdef HAVE_HASH_MAP
00160     typedef std::hash_map<std::string, TCmdProc> TCommandMap;
00161 #else
00162     typedef std::map<std::string, TCmdProc> TCommandMap;
00163 #endif
00164 
00165     //
00166     // functions
00167     //
00168 public:
00170     Class(const std::string &name);
00171     virtual ~Class();
00172 
00174     boost::shared_ptr<Object> Create();
00175 
00177     boost::shared_ptr<Core> GetCore() const;
00178 
00180     void SetBundle(const boost::shared_ptr<salt::SharedLibrary> &bundle);
00181 
00183     TCmdProc GetCmdProc(const std::string &functionName) const;
00184 
00186     const TStringList& GetBaseClasses() const;
00187 
00191     bool SupportsClass(const std::string &name) const;
00192 
00197     bool SupportsCommand(const std::string &name) const;
00198 
00199 protected:
00201     void AttachInstance(const boost::weak_ptr<Object> &instance);
00202 
00204     void DetachInstance(const boost::weak_ptr<Object> &instance);
00205 
00206 private:
00207     Class(const Class &obj);
00208     Class& operator=(const Class &obj);
00209 
00211     virtual Object* CreateInstance() const;
00212 
00214     virtual void DefineClass() = 0;
00215 
00217     void AttachTo(const boost::weak_ptr<Core>& core);
00218 
00219     //
00220     // members
00221     //
00222 protected:
00223     TCommandMap mFunctions;
00224     TStringList mBaseClasses;
00225 private:
00226     boost::weak_ptr<Core> mCore;
00227 
00232     boost::shared_ptr<salt::SharedLibrary>  mBundle;
00233 
00235     TObjectList mInstances;
00236 };
00237 
00238 
00241 class CLASS(Class) : public Class
00242 {
00243 public:
00244     CLASS(Class)() : Class("ClassClass")    { DefineClass();  }
00245 private:
00246     void DefineClass();
00247 };
00248 
00253 DECLARE_CLASS(Leaf);
00254 
00255 } // namespace zeitgeist
00256 
00257 #endif //ZEITGEIST_CLASS_H

Generated on Thu Apr 6 15:25:37 2006 for rcssserver3d by  doxygen 1.4.4