Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / public-api / actors / custom-actor.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/actors/custom-actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/actors/custom-actor-internal.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 namespace Dali
26 {
27 namespace
28 {
29 using namespace Dali;
30
31 BaseHandle Create()
32 {
33   // not directly creatable
34   return BaseHandle();
35 }
36
37 TypeRegistration mType(typeid(Dali::CustomActor), typeid(Dali::Actor), Create);
38
39 } // namespace
40
41 CustomActor::CustomActor()
42 {
43 }
44
45 CustomActor CustomActor::DownCast(BaseHandle handle)
46 {
47   return CustomActor(dynamic_cast<Dali::Internal::CustomActor*>(handle.GetObjectPtr()));
48 }
49
50 CustomActor::~CustomActor()
51 {
52 }
53
54 CustomActor::CustomActor(const CustomActor& copy) = default;
55
56 CustomActor& CustomActor::operator=(const CustomActor& rhs) = default;
57
58 CustomActor::CustomActor(CustomActor&& rhs) = default;
59
60 CustomActor& CustomActor::operator=(CustomActor&& rhs) = default;
61
62 CustomActorImpl& CustomActor::GetImplementation()
63 {
64   Internal::CustomActor& internal = GetImpl(*this);
65
66   return internal.GetImplementation();
67 }
68
69 const CustomActorImpl& CustomActor::GetImplementation() const
70 {
71   const Internal::CustomActor& internal = GetImpl(*this);
72
73   return internal.GetImplementation();
74 }
75
76 CustomActor::CustomActor(CustomActorImpl& implementation)
77 : Actor(Internal::CustomActor::New(implementation).Get())
78 {
79 }
80
81 CustomActor::CustomActor(Internal::CustomActor* internal)
82 : Actor(internal)
83 {
84   // Check we haven't just constructed a new handle, while in the internal custom actors destructor.
85   // This can happen if the user defined CustomActorImpl destructor calls Self(), to create a new handle
86   // to the CustomActor.
87   //
88   // If it's in the destructor then the ref count is zero, so once we've created a new handle it will be 1
89   // Without this check, the actor will be deleted a second time, when the handle is disposed of
90   // causing a crash.
91
92   if(internal)
93   {
94     DALI_ASSERT_ALWAYS(internal->ReferenceCount() != 1 && "Are you trying to use CustomActorImpl::Self() inside a CustomActorImpl destructor?");
95   }
96 }
97
98 } // namespace Dali