PeriDyno 1.0.0
Loading...
Searching...
No Matches
ArrayMap.h
Go to the documentation of this file.
1
16#pragma once
17#include <map>
18#include <vector>
19#include <iostream>
20
21#include "STL/Map.h"
22#include "Array/Array.h"
23
24namespace dyno {
25 template<class ElementType, DeviceType deviceType> class ArrayMap;
26
27 template<class ElementType>
28 class ArrayMap<ElementType, DeviceType::CPU>
29 {
30 public:
33
34 void clear();
35
36 bool resize(uint num);
37
38 void reset();
39
40 inline uint size() const { return m_maps.size(); }
41 inline uint elementSize() const { return m_elements.size(); }
42
43 inline Map<int, ElementType>& operator [] (unsigned int id)
44 {
45 return m_maps[id];
46 }
47
48 inline const Map<int, ElementType>& operator [] (unsigned int id) const
49 {
50 return m_maps[id];
51 }
52
53 inline bool isCPU() const { return true; }
54 inline bool isGPU() const { return false; }
55 inline bool isEmpty() const { return m_maps.empty(); }
56
57 void assign(const ArrayMap<ElementType, DeviceType::CPU>& src);
58 void assign(const ArrayMap<ElementType, DeviceType::GPU>& src);
59
60 friend std::ostream& operator<<(std::ostream& out, const ArrayMap<ElementType, DeviceType::CPU>& aMap)
61 {
62 out << std::endl;
63 for (int i = 0; i < aMap.size(); i++)
64 {
65 Map<int, ElementType> mmap = aMap[i];
66
67 out << "Map " << i << " (" << mmap.size() << "):";
68 for (auto it = mmap.begin(); it != mmap.end(); it++)
69 {
70 std::cout << " key:" << it->first << " value:" << it->second;
71 }
72 out << std::endl;
73 }
74 return out;
75 }
76
77 const CArray<uint>& index() const { return m_index; }
79 const CArray<Map<int, ElementType>>& maps() const { return m_maps; }
80
85
86 private:
89
91 };
92
93 template<typename T>
95}
96
97#ifdef CUDA_BACKEND
99#endif
100
101#ifdef VK_BACKEND
102//TODO: implement the vulkan version
103//#include "Backend/Vulkan/Array/ArrayList.inl"
104#endif
const CArray< Map< int, ElementType > > & maps() const
Definition ArrayMap.h:79
CArray< Pair< int, ElementType > > m_elements
Definition ArrayMap.h:88
const CArray< Pair< int, ElementType > > & elements() const
Definition ArrayMap.h:78
const CArray< uint > & index() const
Definition ArrayMap.h:77
CArray< Map< int, ElementType > > m_maps
Definition ArrayMap.h:90
friend std::ostream & operator<<(std::ostream &out, const ArrayMap< ElementType, DeviceType::CPU > &aMap)
Definition ArrayMap.h:60
ArrayMap< ElementType, DeviceType::CPU > & operator=(const ArrayMap< ElementType, DeviceType::CPU > &)=delete
To avoid erroneous shallow copy.
Be aware do not use this structure on GPU if the data size is large.
Definition Map.h:16
DYN_FUNC iterator end()
Definition Map.h:32
DYN_FUNC uint size()
Definition Map.inl:52
DYN_FUNC iterator begin()
Definition Map.h:30
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
ArrayMap< T, DeviceType::CPU > CArrayMap
Definition ArrayMap.h:94
Array< T, DeviceType::CPU > CArray
Definition Array.h:151
unsigned int uint
Definition VkProgram.h:14