Enzo
Loading...
Searching...
No Matches
AttributeHandle.h
1#pragma once
2#include <memory>
3#include <stdexcept>
4#include <string>
5#include <optional>
6#include <vector>
7#include "Engine/Operator/Attribute.h"
8#include "Engine/Types.h"
9
10#include <iostream>
11
12
13namespace enzo::ga{
14
15template <typename T>
17{
18public:
19 ga::AttributeType type_;
20
21 AttributeHandle(std::shared_ptr<Attribute> attribute)
22 {
23 type_ = attribute->getType();
24 // get attribute data pointer
25 // TODO: check types match
26 // TODO: add the other types
27
28 // int
29 if constexpr (std::is_same<int, T>::value)
30 {
31 data_=attribute->intStore_;
32 }
33
34 // float
35 else if constexpr (std::is_same<float, T>::value)
36 {
37 data_=attribute->floatStore_;
38 }
39
40 // vector 3
41 else if constexpr (std::is_same<enzo::bt::Vector3, T>::value)
42 {
43 data_=attribute->vector3Store_;
44 }
45 else
46 {
47 throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
48 }
49
50 }
51 void addValue(T value)
52 {
53 // TODO:make this private (primitive friend classes only)
54 data_->push_back(value);
55 }
56
57 std::vector<T> getAllValues() const
58 {
59 return *data_;
60 }
61
62 size_t getSize()
63 {
64 return data_->size();
65 }
66
67 T getValue(size_t pos) const
68 {
69 // TODO:protect against invalid positions
70 // TODO: cast types
71 return data_->at(pos);
72 }
73
74 void setValue(size_t pos, const T& value)
75 {
76 // TODO:protect against invalid positions
77 // TODO: cast types
78 (*data_)[pos] = value;
79 }
80 std::string getName() const
81 {
82 return name_;
83 }
84
85
86
87private:
88 // private attributes are attributes that are hidden from the user
89 // for internal use
90 bool private_=false;
91 // hidden attributes are user accessible attributes that the user may
92 // or may want to use
93 bool hidden_=false;
94 // allows the user to read the attributeHandle but not modify it
95 bool readOnly_=false;
96
97 std::string name_="";
98
99 std::shared_ptr<std::vector<T>> data_;
100
101 // int typeID_;
102
103};
104
108
109}
Definition AttributeHandle.h:17