Enzo
Loading...
Searching...
No Matches
Attribute.h
1#pragma once
2#include "Engine/Core/Types.h"
3#include <memory>
4#include <optional>
5#include <string>
6#include <string_view>
7#include <variant>
8#include <vector>
9
10namespace enzo {
11namespace attr {
12template <typename T> using StoreContainer = std::vector<T>;
13
14template <typename T> class AttributeHandle;
15
35class Attribute
36{
37 public:
47 std::string name,
48 attr::AttributeType type,
49 bool intrinsic = false,
50 bool isPrivate = false
51 );
52 Attribute(const Attribute& other);
56 AttributeType getType() const;
60 std::string getName() const;
61
62 Vector3 getVector3(Offset offset) const;
63 Matrix4 getMatrix4(Offset offset) const;
64 size_t getSize() const;
68 unsigned int getTypeSize() const;
69
76 bool isIntrinsic() const;
77
84 bool isPrivate() const;
85
89 void resize(size_t size);
90
95 void compact(const std::vector<bool>& keep);
96
97 template <typename T> friend class AttributeHandle;
98 template <typename T> friend class AttributeHandleRO;
99
100 private:
101 // private attributes are attributes that are hidden from the user
102 // for internal use
103 bool private_ = false;
104 // hidden attributes are user accessible attributes that the user may
105 // or may want to use
106 // bool hidden_=false;
107 // allows the user to read the attribute but not modify it
108 // bool readOnly_=false;
109 bool intrinsic_ = false;
110
112 unsigned int typeSize_ = 1;
113
114 std::string name_;
115
116 using StoreVariant = std::variant<
117 std::shared_ptr<StoreContainer<intT>>,
118 std::shared_ptr<StoreContainer<floatT>>,
119 std::shared_ptr<StoreContainer<enzo::Vector3>>,
120 std::shared_ptr<StoreContainer<enzo::boolT>>,
121 std::shared_ptr<StoreContainer<enzo::Matrix4>>>;
122 StoreVariant store_;
123};
124
125using attribVector = std::vector<std::shared_ptr<attr::Attribute>>;
126} // namespace attr
127} // namespace enzo
Basic attribute, parameter, and node types for Enzo.
AttributeType
Data types available to store attribute values in.
Definition Types.h:32
Read only accessor for enzo::attr::Attribute.
Definition AttributeHandle.h:197
Read write accessor for enzo::attr::Attribute.
AttributeType getType() const
Returns the attribute type this attribute stores.
Definition Attribute.cpp:116
bool isIntrinsic() const
Returns whether the attribute is intrinsic.
Definition Attribute.cpp:77
std::string getName() const
Returns the name of this attribute.
Definition Attribute.cpp:118
Attribute(std::string name, attr::AttributeType type, bool intrinsic=false, bool isPrivate=false)
Construct a new attribute and initialize its typed storage.
Definition Attribute.cpp:9
bool isPrivate() const
Returns whether the attribute is private.
Definition Attribute.cpp:79
void resize(size_t size)
Changes the number of elements stored.
Definition Attribute.cpp:49
unsigned int getTypeSize() const
Returns the number of components in the type (eg. StringT is 1, vectorT is 3).
void compact(const std::vector< bool > &keep)
Removes entries marked as deleted, defragmenting the storage so offsets are contiguous again.
Definition Attribute.cpp:54