[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / particle-system / particle.h
1 #ifndef DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_H
2 #define DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_H
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali-toolkit/public-api/particle-system/particle-types.h>
22
23 // EXTERNAL INCLUDES
24 #include <dali/public-api/object/base-handle.h>
25
26 namespace Dali::Toolkit::ParticleSystem
27 {
28 namespace Internal
29 {
30 class Particle;
31 }
32
33 /**
34  * @class Particle
35  *
36  * Particle represents a single instance of a particle in the particle system.
37  *
38  * Particle provides a simple interface that allows R/W access to selected data stream and
39  * allows ignoring a placement of the particle data within the stream (Particle serves as a
40  * view on particular data within a stream).
41  */
42 class DALI_TOOLKIT_API Particle : public BaseHandle
43 {
44 public:
45   /**
46    * @brief Constructor
47    */
48   Particle() = default;
49
50   /**
51    * @brief Downcasts a handle to Particle handle.
52    *
53    * If handle points to an Particle object, the downcast produces valid handle.
54    * If not, the returned handle is left uninitialized.
55    *
56    * @param[in] handle to An object
57    * @return handle to a Particle object or an uninitialized handle
58    */
59   static Particle DownCast(BaseHandle handle);
60
61   /**
62    * @brief Returns writeable reference to the data for specified stream
63    *
64    * The ParticleStreamTypeFlagBit allows accessing only pre-defined streams
65    * defined by the ParticleSystem. For custom streams GetByIndex() should be used.
66    *
67    * @tparam T type of data
68    * @param[in] streamBit Stream to access data from
69    * @return Reference to the data value
70    */
71   template<class T>
72   T& Get(ParticleStreamTypeFlagBit streamBit)
73   {
74     return *reinterpret_cast<T*>(Get(streamBit));
75   }
76
77   /**
78    * @brief Returns writeable reference to the data for a stream specified by stream index.
79    *
80    * This function allows accessing builtin streams as well as custom ones. The index of a custom
81    * stream should be stored upon creation.
82    *
83    * @tparam T type of data
84    * @param[in] streamIndex Index of stream in the emitter
85    * @return Reference to the data value
86    */
87   template<class T>
88   T& GetByIndex(uint32_t streamIndex)
89   {
90     return *reinterpret_cast<T*>(GetByIndex(streamIndex));
91   }
92
93   /**
94    * @brief Returns an index of particle within emitter data streams.
95    *
96    * @return Index of particle
97    */
98   [[nodiscard]] uint32_t GetIndex() const;
99
100 public:
101   /// @cond internal
102   /**
103    * @brief This constructor is used by Particle::New() methods.
104    *
105    * @param [in] impl A pointer to a newly allocated implementation
106    */
107   Particle(Dali::Toolkit::ParticleSystem::Internal::Particle* impl);
108   /// @endcond
109
110 private:
111   /// @cond internal
112   /**
113    * @brief Returns pointer to the value
114    *
115    *
116    * The ParticleStreamTypeFlagBit allows accessing only pre-defined streams
117    * defined by the ParticleSystem. For custom streams GetByIndex() should be used.
118    *
119    * @param[in] streamBit Stream to access data from
120    *
121    * @return void* to the memory within stream that stores the data
122    */
123   void* Get(ParticleStreamTypeFlagBit streamBit);
124   /// @endcond
125
126   /// @cond internal
127   /**
128    * @brief Returns writeable reference to the data for a stream specified by stream index.
129    *
130    * This function allows accessing builtin streams as well as custom ones. The index of a custom
131    * stream should be stored upon creation.
132    *
133    * @param[in] streamIndex Index of stream in the emitter
134    *
135    * @return void* to the memory within stream that stores the data
136    */
137   void* GetByIndex(uint32_t streamIndex);
138   /// @endcond
139 };
140 } // namespace Dali::Toolkit::ParticleSystem
141
142 #endif // DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_H