OMNeT++ Simulation Library  5.6.1
cobjectfactory.h
1 //==========================================================================
2 // COBJECTFACTORY.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_COBJECTFACTORY_H
17 #define __OMNETPP_COBJECTFACTORY_H
18 
19 #include "simkerneldefs.h"
20 #include "globals.h"
21 #include "cownedobject.h"
22 
23 namespace omnetpp {
24 
25 
36 {
37  private:
38  cObject *(*creatorFunc)();
39  void *(*castFunc)(cObject *);
40  std::string description;
41 
42  public:
48  cObjectFactory(const char *name, cObject *(*creatorfunc)(), void *(*castfunc)(cObject *), const char *description=nullptr);
50 
57  virtual std::string str() const override;
59 
66  virtual bool isAbstract() const {return creatorFunc==nullptr;}
67 
74  virtual cObject *createOne() const;
75 
80  virtual bool isInstance(cObject *obj) const {return castFunc(obj)!=nullptr;}
81 
85  const char *getDescription() const {return description.c_str();}
87 
95  static cObjectFactory *find(const char *className, const char *contextNamespace=nullptr, bool fallbackToOmnetpp=true);
96 
100  static cObjectFactory *get(const char *className, const char *contextNamespace=nullptr, bool fallbackToOmnetpp=true);
101 
123  static cObject *createOne(const char *classname);
124 
132  static cObject *createOneIfClassIsKnown(const char *classname);
134 };
135 
136 
141 inline cObject *createOne(const char *classname) {
142  return cObjectFactory::createOne(classname);
143 }
144 
149 inline cObject *createOneIfClassIsKnown(const char *classname) {
150  return cObjectFactory::createOneIfClassIsKnown(classname);
151 }
152 
153 } // namespace omnetpp
154 
155 
156 #endif
157 
158 
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual bool isAbstract() const
Definition: cobjectfactory.h:66
const char * getDescription() const
Definition: cobjectfactory.h:85
static cObject * createOneIfClassIsKnown(const char *classname)
The class behind the createOne() function and the Register_Class() macro.
Definition: cobjectfactory.h:35
cObject * createOne(const char *classname)
Shortcut to cObjectFactory::createOne().
Definition: cobjectfactory.h:141
cObject * createOneIfClassIsKnown(const char *classname)
Shortcut to cObjectFactory::createOneIfClassIsKnown().
Definition: cobjectfactory.h:149
Definition: cabstracthistogram.h:21
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248
virtual cObject * createOne() const
virtual bool isInstance(cObject *obj) const
Definition: cobjectfactory.h:80