VR-Engage  2.2
Loading...
Searching...
No Matches
projectileFactory.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6#pragma once
7
8//! \ingroup vreVrfobjcore
9//! \brief Projectile factory class for VREngage
10//!
11//! This file defines the DtProjectileFactory class, which provides a factory for creating
12//! DtProjectile objects in VREngage simulations. By default, the factory contains a single
13//! entry for the base DtProjectile class, but additional projectile types can be registered.
14
15class DtProjectile;
16
18
19#include <vlutil/vlString.h>
20
21#include <string>
22#include <map>
23
24class DtReaderWriterRegistry;
25
26namespace makVre
27{
28class DtProjectile;
29
30//! \brief Function pointer type for projectile creation functions
31//!
32//! Defines the signature for functions that create projectile instances.
33//! Each registered projectile type must provide a creator function with this signature.
34using DtProjectileCreatorFcn = DtProjectile* (*)(const DtString& name, DtReaderWriterRegistry* const parentRegistry);
35
36//! \brief Factory for creating projectile objects
37//!
38//! This class provides a factory for creating DtProjectile objects based on a type string.
39//! By default, the factory contains a single entry for the base DtProjectile class, but
40//! additional projectile types can be registered using the addCreatorFcn method.
42{
43public:
44 //! \brief Default constructor
45 //!
46 //! Creates a new projectile factory with no registered projectile types.
48
49 //! \brief Copy constructor
50 //! \param orig The source factory to copy from
51 //!
52 //! Creates a new projectile factory as a copy of the provided original,
53 //! copying all registered projectile types.
55
56 //! \brief Assignment operator
57 //! \param orig The source factory to copy from
58 //! \return Reference to this factory after assignment
59 //!
60 //! Assigns the contents of the provided factory to this one,
61 //! copying all registered projectile types.
63
64 //! \brief Virtual destructor
65 //!
66 //! Cleans up resources used by the factory.
68
69 //! \brief Registers a projectile creation function with the factory
70 //! \param type The string identifier for this projectile type
71 //! \param fcn Function pointer to the creator function for this type
72 //!
73 //! Adds a creator function to the factory for a specific projectile type.
74 //! When createProjectile is called with this type string, the registered
75 //! function will be used to create the projectile instance.
76 virtual void addCreatorFcn(const std::string& type, DtProjectileCreatorFcn fcn);
77
78 //! \brief Creates a projectile instance of the specified type
79 //! \param type The string identifier for the projectile type to create
80 //! \param name The name to assign to the new projectile
81 //! \param parentRegistry Parent registry for reader/writer functionality (optional)
82 //! \return Pointer to the newly created projectile instance
83 //!
84 //! Creates and returns a new instance of a DtProjectile object of the specified type.
85 //! The type must have been previously registered with addCreatorFcn.
87 const char* type, const DtString& name, DtReaderWriterRegistry* const parentRegistry = NULL);
88
89protected:
90 //! \brief Map of projectile types to their creator functions
91 //!
92 //! Stores the mapping between projectile type strings and their corresponding
93 //! creator functions. When createProjectile is called, the type string is used
94 //! to look up the appropriate creator function in this map.
95 std::map<std::string, DtProjectileCreatorFcn> myProjectileCreatorMap;
96};
97} // namespace makVre
virtual void addCreatorFcn(const std::string &type, DtProjectileCreatorFcn fcn)
Registers a projectile creation function with the factory.
DtProjectileFactory()
Default constructor.
const DtProjectileFactory & operator=(const DtProjectileFactory &orig)
Assignment operator.
DtProjectileFactory(const DtProjectileFactory &orig)
Copy constructor.
virtual DtProjectile * createProjectile(const char *type, const DtString &name, DtReaderWriterRegistry *const parentRegistry=NULL)
Creates a projectile instance of the specified type.
virtual ~DtProjectileFactory()
Virtual destructor.
std::map< std::string, DtProjectileCreatorFcn > myProjectileCreatorMap
Map of projectile types to their creator functions.
Definition projectileFactory.h:95
Class representing ballistic projectiles in simulations.
Definition projectile.h:42
Export macros for the VREngage Object Core library.
#define VREVRFOBJCORE_DLL
Platform-specific DLL export/import declaration.
Definition export.h:27
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtProjectile *(*)(const DtString &name, DtReaderWriterRegistry *const parentRegistry) DtProjectileCreatorFcn
Function pointer type for projectile creation functions.
Definition projectileFactory.h:34