PeriDyno 1.0.0
Loading...
Searching...
No Matches
List.inl
Go to the documentation of this file.
1#include "Math/SimpleMath.h"
2#include <glm/glm.hpp>
3
4namespace dyno
5{
6 template <typename T>
7 DYN_FUNC List<T>::List()
8 {
9 }
10
11 template <typename T>
12 DYN_FUNC T* List<T>::find(T val)
13 {
14 return nullptr;
15 }
16
17
18 template <typename T>
19 DYN_FUNC T* List<T>::insert(T val)
20 {
21 //return nullptr if the data buffer is full
22 if (m_size >= this->m_maxSize) return nullptr;
23
24 this->m_startLoc[m_size] = val;
25 m_size++;
26
27 return this->m_startLoc + m_size - 1;;
28 }
29
30/*
31 CUDA atomic functions are only available in nvcc compiler.
32 As List.h is included in Framework/Action.cpp
33 (Action.cpp <- Action.h <- Node.h <- Field.h <- ArrayList.h),
34 this "atomicAdd" leads to an error "there are no arguments to
35 'atomicAdd' that depend on a template parameter, so a declaration
36 of 'atomicAdd' must be available".
37 So "defind(__CUDACC__)" is added here to avoid compilation error.
38
39 As class ArrayList uses only the CPU version of dyno::List,
40 adding "defind(__CUDACC__)" here does not affect class ArrayList.
41*/
42#if defined(CUDA_BACKEND) && defined(__CUDACC__)
43
44 template <typename T>
45 GPU_FUNC T* List<T>::atomicInsert(T val)
46 {
47 //return nullptr if the data buffer is full
48 if (m_size >= this->m_maxSize) return nullptr;
49
50 // const uint one = 1;
51 // int index = atomicAdd(&(this->m_size), one);
52 int index = atomicAdd(&(this->m_size), 1);
53 //int index = 0;//Onlinux platform, this is a bug, not yet resolved.
54
55 this->m_startLoc[index] = val;
56
57 return this->m_startLoc + index;
58 }
59
60#endif
61
62 template <typename T>
63 DYN_FUNC void List<T>::clear()
64 {
65 m_size = 0;
66 }
67
68 template <typename T>
70 {
71 return m_size;
72 }
73
74 template <typename T>
75 DYN_FUNC bool List<T>::empty()
76 {
77 return this->m_startLoc == nullptr;
78 }
79
80 template <typename T>
81 DYN_FUNC T List<T>::front()
82 {
83 return this->m_startLoc[0];
84 }
85
86 template <typename T>
87 DYN_FUNC T List<T>::back()
88 {
89 return this->m_startLoc[m_size - 1];
90 }
91}
92
Be aware do not use this structure on GPU if the data size is large.
Definition List.h:21
uint m_size
Definition List.h:67
DYN_FUNC iterator insert(T val)
Definition List.inl:19
DYN_FUNC void clear()
Definition List.inl:63
DYN_FUNC bool empty()
Definition List.inl:75
DYN_FUNC iterator find(T val)
Definition List.inl:12
DYN_FUNC T front()
Definition List.inl:81
DYN_FUNC List()
Definition List.inl:7
DYN_FUNC T back()
Definition List.inl:87
DYN_FUNC uint size()
Definition List.inl:69
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
unsigned int uint
Definition VkProgram.h:14