OpenBlox
A game engine which provides a simple and easy to learn Lua API.
OB::ClassFactory Class Reference

#include <ClassFactory.h>

Static Public Member Functions

static std::vector< std::string > getRegisteredClasses ()
 
static void addClass (std::string className, ClassMetadata *newClassMetadata)
 
static bool canCreate (std::string className)
 
static std::string getParentClassName (std::string className)
 
static shared_ptr< Instance::Instancecreate (std::string className, OBEngine *eng)
 
static shared_ptr< Instance::InstancecreateService (std::string className, bool isDataModel, OBEngine *eng)
 
static shared_ptr< Instance::InstancecreateReplicate (std::string className, OBEngine *eng)
 
static bool isA (shared_ptr< Instance::Instance > obj, std::string className)
 
static void initClasses (OBEngine *eng)
 
static void registerCoreClasses ()
 

Detailed Description

The "factory" used to create Instance classes by name.

Author
John M. Harris, Jr.

Member Function Documentation

◆ addClass()

static void OB::ClassFactory::addClass ( std::string  className,
ClassMetadata newClassMetadata 
)
static

Adds an Instance class to the ClassFactory's metatable map. Classes must have unique names, and parent classes are to be added before their children.

Parameters
classNameName of the class to add. Should contain no spaces and should be CamelCase e.g. MyInstanceName
newClassMetadataMetadata describing the class
Author
John M. Harris, Jr.

◆ canCreate()

static bool OB::ClassFactory::canCreate ( std::string  className)
static

Returns whether or not a class of given name can be created.

Parameters
classNameName of the class to check
Returns
True if this class can be created (e.g. by Instance.new in Lua)
Author
John M. Harris, Jr.

◆ create()

static shared_ptr<Instance::Instance> OB::ClassFactory::create ( std::string  className,
OBEngine eng 
)
static

Returns a new instance of the given class name, or NULL if the class is abstract or otherwise cannot be created.

This includes classes that can only be created by services. If you attempt to call this on one of those classes, it will return NULL.

Parameters
classNameName of the class to be created
engThe current OBEngine instance
Returns
New instance or NULL
Author
John M. Harris, Jr.

◆ createReplicate()

static shared_ptr<Instance::Instance> OB::ClassFactory::createReplicate ( std::string  className,
OBEngine eng 
)
static

Returns a new instance of a given class name, or NULL if the class is abstract or otherwise cannot be created.

This is only used to Instance replication.

Parameters
classNameName of the class to be created
engThe current OBEngine instance
Returns
New instance or NULL
Author
John M. Harris, Jr.

◆ createService()

static shared_ptr<Instance::Instance> OB::ClassFactory::createService ( std::string  className,
bool  isDataModel,
OBEngine eng 
)
static

Returns a new instance of the given class name, or NULL if the class is abstract or is not a service.

If the caller is the DataModel, the second parameter, isDataModel, will be true. This allows services to be created only by the DataModel, or only by other ServiceProviders.

Parameters
classNameName of the class to be created
isDataModelTrue if being called from the DataModel, otherwise false.
engThe current OBEngine instance
Returns
New instance or NULL
Author
John M. Harris, Jr.

◆ getParentClassName()

static std::string OB::ClassFactory::getParentClassName ( std::string  className)
static

Returns the name of the parent class of a given class.

Parameters
classNameName of the class to check
Returns
Parent class name, or an empty string in the case of Instance
Author
John M. Harris, Jr.

◆ getRegisteredClasses()

static std::vector<std::string> OB::ClassFactory::getRegisteredClasses ( )
static

Returns a vector containing all registered class names.

Returns
Vector containing all registered class names.
Author
John M. Harris, Jr.

◆ initClasses()

static void OB::ClassFactory::initClasses ( OBEngine eng)
static

Initializes Lua metatables and other Instance related runtime requirements.

Author
John M. Harris, Jr.

◆ isA()

static bool OB::ClassFactory::isA ( shared_ptr< Instance::Instance obj,
std::string  className 
)
static

Returns whether or not a given object is an instance of the given class name.

Parameters
objInstance to test against
classNameName of the class to test against
Returns
true if obj is an instance of className, otherwise false
Author
John M. Harris, Jr.

◆ registerCoreClasses()

static void OB::ClassFactory::registerCoreClasses ( )
static

Registers core classes with the ClassFactory. This is safe to call at any time. It is suggested that, if you want to register your own instance classes, you call this before the creation of OBEngine. However, this is not a requirement, as the constructor for OBEngine calls this function, and you can register a class at any point in the execution of a program.

Author
John M. Harris, Jr.

The documentation for this class was generated from the following file: