WSF
WsfBMGenericTypeWrapper.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI//REL TO USA ONLY
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// The use, dissemination or disclosure of data in this file is subject to
7// limitation or restriction. See accompanying README and LICENSE for details.
8// ****************************************************************************
9// Classification: UNCLASSIFIED
10
11#ifndef WSF_BM_GENERIC_TYPE_WRAPPER_HPP
12#define WSF_BM_GENERIC_TYPE_WRAPPER_HPP
13
14#include <memory>
15
16#include <WsfBMCommon.hpp>
17#include <WsfObject.hpp>
18
19// This class is a generic data wrapper for bridging between AFSIM and the core data structures.
20// It is not meant to be used alone, see the managed and unmanaged specializations below.
21template <typename tWrappedType, typename tPointerType>
23{
24 public:
25 typedef tPointerType tType;
26
27 WsfBMTypeWrapper(const std::string& script_class_name)
28 : m_script_class_name(script_class_name)
29 {}
30
31 WsfBMTypeWrapper(const std::string& script_class_name, tPointerType data_to_wrap)
32 : m_script_class_name(script_class_name)
33 , m_wrapped_ptr(data_to_wrap)
34 {}
35
36 virtual WsfBMTypeWrapper* Clone() const
37 {
38 return new WsfBMTypeWrapper(*this);
39 }
40
41 virtual const char* GetScriptClassName() const { return m_script_class_name.c_str(); }
42 virtual tType GetRawPtr() const { return m_wrapped_ptr; }
43
44 virtual bool IsValidRef() const { return m_wrapped_ptr ? true : false; }
45
46 protected:
48 tPointerType m_wrapped_ptr;
49};
50
51// Use this type when the data is truly shared and maintained between the core models and AFSIM. This is typically used for things that may be
52// created and passed around (but data copied around) and whose lifecycle isn't well defined ahead of time (messages for instance). The data pointer
53// will be reference counted and attempted to be deleted upon last owner.
54template <typename tWrappedType>
55class WsfBMManagedTypeWrapper : public WsfBMTypeWrapper<tWrappedType, std::shared_ptr<tWrappedType>>
56{
57 public:
58 WsfBMManagedTypeWrapper(const std::string& script_class_name)
59 : WsfBMTypeWrapper<tWrappedType, std::shared_ptr<tWrappedType>>(script_class_name)
60 {
62 }
63
64 WsfBMManagedTypeWrapper(const std::string& script_class_name, const std::shared_ptr<tWrappedType>& data_to_wrap)
65 : WsfBMTypeWrapper<tWrappedType, std::shared_ptr<tWrappedType>>(script_class_name, data_to_wrap)
66 {}
67
68 virtual void SetTable(std::shared_ptr<tWrappedType>& data_to_wrap)
69 {
71 }
72};
73
74// Use this type when the data is really just a thin wrapper but the user won't own the data. This is typically passing internal data structures
75// around (internal BM weapon table for instance) to modules within AFSIM that may need to reference them. The user will never own the data, therefore
76// the data will be wrapped nut not attempted to be referenced counted or deleted.
77template <typename tWrappedType>
78class WsfBMUnmanagedTypeWrapper : public WsfBMTypeWrapper<tWrappedType, tWrappedType*>
79{
80 public:
81 WsfBMUnmanagedTypeWrapper(const std::string& script_class_name)
82 : WsfBMTypeWrapper<tWrappedType, tWrappedType *>(script_class_name)
83 {
85 }
86
87 WsfBMUnmanagedTypeWrapper(const std::string& script_class_name, tWrappedType* data_to_wrap)
88 : WsfBMTypeWrapper<tWrappedType, tWrappedType *>(script_class_name, data_to_wrap)
89 { }
90
91 virtual void SetData(tWrappedType* data_to_wrap)
92 {
94 }
95};
96
97#endif
WsfBMManagedTypeWrapper(const std::string &script_class_name, const std::shared_ptr< tWrappedType > &data_to_wrap)
Definition WsfBMGenericTypeWrapper.hpp:64
WsfBMManagedTypeWrapper(const std::string &script_class_name)
Definition WsfBMGenericTypeWrapper.hpp:58
virtual void SetTable(std::shared_ptr< tWrappedType > &data_to_wrap)
Definition WsfBMGenericTypeWrapper.hpp:68
virtual const char * GetScriptClassName() const
Definition WsfBMGenericTypeWrapper.hpp:41
virtual tType GetRawPtr() const
Definition WsfBMGenericTypeWrapper.hpp:42
std::string m_script_class_name
Definition WsfBMGenericTypeWrapper.hpp:47
tPointerType m_wrapped_ptr
Definition WsfBMGenericTypeWrapper.hpp:48
virtual WsfBMTypeWrapper * Clone() const
Definition WsfBMGenericTypeWrapper.hpp:36
WsfBMTypeWrapper(const std::string &script_class_name)
Definition WsfBMGenericTypeWrapper.hpp:27
tPointerType tType
Definition WsfBMGenericTypeWrapper.hpp:25
virtual bool IsValidRef() const
Definition WsfBMGenericTypeWrapper.hpp:44
WsfBMTypeWrapper(const std::string &script_class_name, tPointerType data_to_wrap)
Definition WsfBMGenericTypeWrapper.hpp:31
virtual void SetData(tWrappedType *data_to_wrap)
Definition WsfBMGenericTypeWrapper.hpp:91
WsfBMUnmanagedTypeWrapper(const std::string &script_class_name)
Definition WsfBMGenericTypeWrapper.hpp:81
WsfBMUnmanagedTypeWrapper(const std::string &script_class_name, tWrappedType *data_to_wrap)
Definition WsfBMGenericTypeWrapper.hpp:87
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
Copyrights Multiple, All Rights Reserved