iMSTK
Interactive Medical Simulation Toolkit
imstkAbstractDataArray.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkTypes.h"
10 #include "imstkEventObject.h"
11 
12 namespace imstk
13 {
20 {
21 public:
22  AbstractDataArray() : m_scalarType(IMSTK_VOID), m_size(0), m_capacity(0) { }
23 
24  AbstractDataArray(const int size) : m_scalarType(IMSTK_VOID), m_size(size), m_capacity(size) { }
25 
29  virtual ~AbstractDataArray() { };
30 
31  // *INDENT-OFF*
32  SIGNAL(AbstractDataArray, modified);
33  // *INDENT-ON*
34 
38  virtual void resize(const int size) = 0;
39 
43  virtual void reserve(const int size) = 0;
44 
48  virtual void* getVoidPointer() = 0;
49 
53  void clear() { resize(0); };
54 
58  inline int size() const { return m_size; }
59 
63  inline ScalarTypeId getScalarType() const { return m_scalarType; }
64 
68  inline int getCapacity() const { return m_capacity; }
69 
73  inline virtual int getNumberOfComponents() const { return 1; }
74 
79  virtual std::shared_ptr<AbstractDataArray> cast(ScalarTypeId) = 0;
80 
85  inline void postModified() { this->postEvent(Event(AbstractDataArray::modified())); }
86 
90  std::unique_ptr<AbstractDataArray> clone()
91  {
92  return std::unique_ptr<AbstractDataArray>(cloneImplementation());
93  }
94 
95 protected:
96 
97  void setType(const ScalarTypeId type) { this->m_scalarType = type; }
98 
99  ScalarTypeId m_scalarType;
100  int m_size; // Number of values
101  int m_capacity; // Capacity of the vector
102 
103 private:
104 
105  virtual AbstractDataArray* cloneImplementation() = 0;
106 };
107 } // namespace imstk
int size() const
Get number of values/tuples.
virtual void * getVoidPointer()=0
Returns void pointer to data.
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
virtual std::shared_ptr< AbstractDataArray > cast(ScalarTypeId)=0
cast the content to the given imstk scalar type without having to know the type of the enclosed array...
Compound Geometry.
virtual int getNumberOfComponents() const
Returns the number of components.
virtual void resize(const int size)=0
Resizes the array, may reallocate.
This class serves as the base class of DataArray, for typeless use.
std::unique_ptr< AbstractDataArray > clone()
polymorphic clone() function, utilize this to get a copy of the array without casting to the expected...
int getCapacity() const
Return the capacity of the array.
void postModified()
emits signal to all observers, informing them on the current address in memory and size of array ...
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
void postEvent(const T &e)
Emits the event Direct observers will be immediately called, in sync Queued observers will receive th...
virtual void reserve(const int size)=0
Reserves a size for the array in memory, may reallocate.
virtual ~AbstractDataArray()
Ensure all observers are disconnected.
ScalarTypeId getScalarType() const
Returns the scalar type of this array.