cobjectfactory.h

00001 //==========================================================================
00002 //  COBJECTFACTORY.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //==========================================================================
00007 
00008 /*--------------------------------------------------------------*
00009   Copyright (C) 1992-2008 Andras Varga
00010   Copyright (C) 2006-2008 OpenSim Ltd.
00011 
00012   This file is distributed WITHOUT ANY WARRANTY. See the file
00013   `license' for details on this and other legal matters.
00014 *--------------------------------------------------------------*/
00015 
00016 #ifndef __COBJECTFACTORY_H
00017 #define __COBJECTFACTORY_H
00018 
00019 #include "simkerneldefs.h"
00020 #include "globals.h"
00021 #include "cownedobject.h"
00022 
00023 NAMESPACE_BEGIN
00024 
00025 
00034 class SIM_API cObjectFactory : public cNoncopyableOwnedObject
00035 {
00036   private:
00037     cObject *(*creatorfunc)();
00038     void *(*castfunc)(cObject *);
00039     std::string descr;
00040 
00041   public:
00047     cObjectFactory(const char *name, cObject *(*creatorfunc)(), void *(*castfunc)(cObject *), const char *description=NULL);
00049 
00056     virtual std::string info() const;
00058 
00065     virtual bool isAbstract() const  {return creatorfunc==NULL;}
00066 
00073     virtual cObject *createOne() const;
00074 
00079     virtual bool isInstance(cObject *obj) const  {return castfunc(obj)!=NULL;}
00080 
00084     const char *getDescription() const  {return descr.c_str();}
00086 
00095     static cObjectFactory *find(const char *classname);
00096 
00100     static cObjectFactory *get(const char *classname);
00101 
00123     static cObject *createOne(const char *classname);
00124 
00132     static cObject *createOneIfClassIsKnown(const char *classname);
00134 };
00135 
00136 
00145 inline cObject *createOne(const char *classname) {
00146     return cObjectFactory::createOne(classname);
00147 }
00148 
00152 inline cObject *createOneIfClassIsKnown(const char *classname) {
00153     return cObjectFactory::createOneIfClassIsKnown(classname);
00154 }
00156 
00157 NAMESPACE_END
00158 
00159 
00160 #endif
00161 
00162 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3