Containers

Description

The Container type is used when a column source needs to store a list rather than a scalar element. Such a situation arises, for example, when you have a Deephaven group_by operation.

In this situation you will have a ContainerBaseColumnSource representing the column. To get the data out, you will use FillChunk to fill a ContainerBaseChunk. Now you will have a Chunk containing the lists you want to look at. Each of the elements in this Chunk is a std::shared_ptr<ContainerBase>

However, to get at the elements inside these lists, you need to downcast the std::shared_ptr<ContainerBase> to the correct derived type, e.g. std::shared_ptr< Container <int32_t>>.

If you already know the element type you need, you can use a method like AsContainerPtr to downcast it directly. If not, you can use the ContainerVisitor to determine the type at runtime. Another way of determining the type at runtime is to use the ColumnSource’s GetElementType method. The ElementType you get will represent a list type, and you can use its Id method to retrieve its ElementTypeId::Enum.

Declarations

class ContainerBase : public std::enable_shared_from_this<ContainerBase>

Abstract class for the Deephaven Container type.

Subclassed by deephaven::dhcore::container::Container< T >

Public Functions

inline size_t size() const

Returns the number of elements in the container.

Returns:

The number of elements in the Container

template<class T>
inline std::shared_ptr<const Container<T>> AsContainerPtr() const

If this object is a Container<T>, returns a shared_ptr<const Container<T>> pointing to this object. Otherwise, returns a null shared_ptr.

Returns:

A shared_ptr<const Container<T>> if this object is a Container<T>, otherwise a null shared_ptr.

template<class T>
inline const Container<T> &AsContainer() const

If this object is a Container<T>, returns a const Container<T>& referring to this object. Otherwise, throws an exception.

Returns:

A const Container<T>& referring to this object.

virtual void AcceptVisitor(ContainerVisitor *visitor) const = 0

Implements the Visitor pattern.

template<typename T>
class Container : public deephaven::dhcore::container::ContainerBase

Forward declaration

Template Parameters:

T

Public Functions

inline Container(Private, std::shared_ptr<T[]> &&data, std::shared_ptr<bool[]> &&nulls, size_t size)

Constructor. This constructor is effectively private because outside callers cannot create the dummy “Private” argument.

inline virtual void AcceptVisitor(ContainerVisitor *visitor) const final

Implement the Visitor pattern.

inline const T &operator[](size_t index) const

Indexing operator

Parameters:

index – Index of the specified element

Returns:

a const reference to the specified element

inline bool IsNull(size_t index) const

Determines if the element at the specified index is null.

Parameters:

index – Index of the specified element

Returns:

true if the element at the specified index is null; false otherwise

inline const T *data() const

Gets a const pointer to the start of the data

Returns:

A const pointer to the start of the data

inline const T *begin() const

Gets a const pointer to the start of the data.

Returns:

A const pointer to the start of the data

inline const T *end() const

Gets a const pointer to one past the end of the data.

Returns:

A const pointer to one past the end of the data

Public Static Functions

static inline std::shared_ptr<Container<T>> Create(std::shared_ptr<T[]> data, std::shared_ptr<bool[]> nulls, size_t size)

Creates a Container<T> of the specified size from the corresponding data and nulls arrays.

Parameters:
  • data – A shared_ptr to the underlying data

  • nulls – A shared_ptr to the nulls flags

  • size – The size of the container

Returns:

A shared_ptr<Container<T>> representing the specified data.

Utility Declarations

class ContainerVisitor

Implements the visitor pattern for Container.

Public Functions

virtual ~ContainerVisitor() = default

Destructor.

virtual void Visit(const Container<char16_t> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<int8_t> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<int16_t> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<int32_t> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<int64_t> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<float> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<double> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<bool> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<std::string> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<DateTime> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<LocalDate> *container) = 0

Implements the visitor pattern.

virtual void Visit(const Container<LocalTime> *container) = 0

Implements the visitor pattern.