ADTF
Loading...
Searching...
No Matches
class_factory.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <stdexcept>
10
11namespace adtf
12{
13namespace ucom
14{
15namespace ant
16{
17
24template <typename ...Classes>
25class class_factory : public catwo::object<IClassFactory>
26{
27 private:
28 template<typename ...InnerClasses>
29 struct dispatch
30 {
31 static tResult CreateInstance(const char* /* strCID */,
32 iobject_ptr<IObject>& /* oObject */,
33 const char* /* strNameOfObject */)
34 {
35 RETURN_ERROR(ERR_NO_CLASS);
36 }
37
38 static void AddClassInfo(iobject_enum<const IClassInfo>& /* lstOfClasses */)
39 {
40 }
41 };
42
43 template<typename Class, typename ...InnerClasses>
44 struct dispatch<Class, InnerClasses...>
45 {
46 static tResult CreateInstance(const char* strCID,
47 iobject_ptr<IObject>& oObject,
48 const tChar* strNameOfObject = "")
49 {
50 if (adtf_util::cString(strCID).IsEqual(get_class_id<Class>()))
51 {
52 try
53 {
55 if (!pCreatedObject)
56 {
57 RETURN_ERROR(ERR_MEMORY);
58 }
59 oObject.Reset(pCreatedObject);
60 if (oObject.Get() == nullptr)
61 {
62 RETURN_ERROR(ERR_INVALID_INTERFACE);
63 }
64
66 }
67 catch (...)
68 {
70 }
71 }
72 return dispatch<InnerClasses...>::CreateInstance(strCID, oObject, strNameOfObject);
73 }
74
75 static void AddClassInfo(iobject_enum<const IClassInfo>& lstOfClasses)
76 {
77 //use copy constructor
79 lstOfClasses.PushObject(pInfo);
80 dispatch<InnerClasses...>::AddClassInfo(lstOfClasses);
81 }
82 };
83
84 private:
85 class_factory(const class_factory&) = delete;
86 class_factory(class_factory&&) = delete;
87 class_factory& operator=(const class_factory&) = delete;
88 class_factory& operator=(class_factory&&) = delete;
89
90 public:
95 {
96 }
97
102 {
103 }
104
105
106 public: // implements IClassFactory
116 virtual tResult CreateInstance(const char* strCID,
117 iobject_ptr<IObject>& oObject,
118 const tChar* strNameOfObject = "") const
119 {
121
122 object_ptr<IObject> pCreatedObject = nullptr;
123
124 adtf_util::cString strClassToCreate(strCID);
125
126 if (strClassToCreate.IsEmpty())
127 {
128 RETURN_ERROR_DESC(ERR_INVALID_ARG, "CID is empty");
129 }
130
131 return dispatch<Classes...>::CreateInstance(strCID, oObject, strNameOfObject);
132 }
133
141 {
142 dispatch<Classes...>::AddClassInfo(lstOfClasses);
144 }
145};
146
147}//ns ant
148
150using ant::class_factory;
151
152}//ns ucom
153}//ns adtf
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
Definition result.h:44
#define RETURN_CURRENT_EXCEPTION()
returns the current exception as a tResult, use it in a catch block.
Definition result.h:111
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Definition result.h:42
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
Definition result.h:49
virtual ~class_factory()
Definition class_factory.h:101
class_factory()
Definition class_factory.h:94
virtual tResult CreateInstance(const char *strCID, iobject_ptr< IObject > &oObject, const tChar *strNameOfObject="") const
Definition class_factory.h:116
tResult GetClasses(iobject_enum< const IClassInfo > &lstOfClasses) const
Enumerates all classes supported by the class factory and pushes it to lstOfClasses This method shoul...
Definition class_factory.h:140
Definition object_list.h:22
virtual tResult PushObject(const value_type &oObject)=0
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Reset this object_ptr<> with the content of another iobject_ptr<>
virtual T * Get() const =0
Get raw pointer to shared object.
Base object pointer to realize binary compatible reference counting in interface methods.
Definition object_ptr_intf.h:112
Definition object_ptr.h:384
Definition object.h:397
Namespace for all functionality of the ADTF UCOM SDK provided since v3.0.
Definition test_runtime.h:14
constexpr const char * get_class_id()
Definition class_id.h:110
object_ptr< const adtf::ucom::ant::IClassInfo > get_class_info()
Definition class_info.h:109
object_ptr< Implementation > make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
Definition object_ptr_utilities.h:129
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14