Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attributearray.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_ATTRIBUTEARRAY_H_
19 #define ION_GFX_ATTRIBUTEARRAY_H_
20 
21 #include "ion/base/referent.h"
23 #include "ion/gfx/attribute.h"
24 #include "ion/gfx/resourceholder.h"
25 
26 namespace ion {
27 namespace gfx {
28 
30 static const size_t kAttributeSlotCount = 32;
31 
36 class ION_API AttributeArray : public ResourceHolder {
37  public:
39  enum Changes {
40  kAttributeChanged = kNumBaseChanges,
43  kAttributeEnabledChanged = kAttributeChanged + kAttributeSlotCount,
44  kNumChanges = kAttributeEnabledChanged + kAttributeSlotCount
45  };
46 
48 
53  size_t GetAttributeIndexByName(const std::string& name);
54 
60  size_t AddAttribute(const Attribute& attribute);
64  bool ReplaceAttribute(size_t index, const Attribute& attribute);
65 
70  void EnableAttribute(const size_t attribute_index, bool enabled);
73  bool IsAttributeEnabled(const size_t attribute_index) const;
76  void EnableBufferAttribute(const size_t i, bool enabled) {
77  enables_.Set(i, enabled);
78  }
82  bool IsBufferAttributeEnabled(const size_t i) const {
85  const bool& value = enables_.Get(i);
86  return base::IsInvalidReference(value) ? false : value;
87  }
88 
90  size_t GetAttributeCount() const {
91  return attribute_indices_.size();
92  }
94  size_t GetBufferAttributeCount() const {
95  return buffer_attributes_.GetCount();
96  }
98  size_t GetSimpleAttributeCount() const {
99  return simple_attributes_.size();
100  }
101 
106  const Attribute& GetAttribute(const size_t attribute_index) const;
107  const Attribute& GetBufferAttribute(const size_t i) const {
108  return buffer_attributes_.Get(i);
109  }
110  const Attribute& GetSimpleAttribute(const size_t i) const {
111  if (i < simple_attributes_.size()) {
112  return simple_attributes_[i];
113  } else {
114  return base::InvalidReference<Attribute>();
115  }
116  }
117 
123  Attribute* GetMutableAttribute(const size_t attribute_index);
125  return buffer_attributes_.GetMutable(i);
126  }
128  if (i < simple_attributes_.size()) {
129  return &simple_attributes_[i];
130  } else {
131  return NULL;
132  }
133  }
134 
135  protected:
138  ~AttributeArray() override;
139 
140  private:
143  struct Index {
144  enum Type {
145  kBuffer,
146  kSimple
147  };
148  Index(Type type_in, size_t index_in) : type(type_in), index(index_in) {}
149 
151  bool operator==(const Index& other) const {
152  return type == other.type && index == other.index;
153  }
154  Type type;
155  size_t index;
156  };
157 
159  Index* FindIndexOfAttribute(Index::Type type, size_t index);
160 
163  void RemoveAttribute(const Index& attr_index);
164 
166  void OnNotify(const base::Notifier* notifier) override;
167 
170  base::AllocVector<Index> attribute_indices_;
171 
174  VectorField<Attribute> buffer_attributes_;
175 
178  base::AllocVector<Attribute> simple_attributes_;
179 
182  VectorField<bool> enables_;
183 };
184 
187 
188 } // namespace gfx
189 } // namespace ion
190 
191 #endif // ION_GFX_ATTRIBUTEARRAY_H_
bool IsInvalidReference(const T &value)
IsInvalidReference() returns true if a passed const reference of type T has an address of InvalidRefe...
Definition: invalid.h:41
std::string type
Definition: printer.cc:353
Attribute * GetMutableBufferAttribute(const size_t i)
double value
Attribute * GetMutableSimpleAttribute(const size_t i)
const Attribute & GetBufferAttribute(const size_t i) const
size_t GetAttributeCount() const
Gets the total number of Attributes in the AttributeArray.
void EnableBufferAttribute(const size_t i, bool enabled)
Enables or disables the ith buffer Attribute.
std::string name
Definition: printer.cc:324
An AttributeArray represents a collection of Attributes used to describe the vertices of a Shape...
base::ReferentPtr< AttributeArray >::Type AttributeArrayPtr
Convenience typedef for shared pointer to a AttributeArray.
bool IsBufferAttributeEnabled(const size_t i) const
Returns if the ith buffer Attribute is enabled, or false if i is not a valid index.
Changes
Changes that affect the resource.
bool operator==(const StlAllocator< T1 > &lhs, const StlAllocator< T2 > &rhs)
Each StlAllocator holds an Allocator.
Definition: stlallocator.h:237
size_t GetSimpleAttributeCount() const
Gets the number of simple Attributes in the AttributeArray.
size_t GetBufferAttributeCount() const
Gets the number of buffer Attributes in the AttributeArray.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
ResourceHolder is an internal base class for objects that hold resources managed by an outside entity...
const Attribute & GetSimpleAttribute(const size_t i) const