#ifndef CF_DATACUBE_RUNTIME_H
#define CF_DATACUBE_RUNTIME_H

#include <stddef.h>

#include "cf_datacube.h"
#include "cf_step_abi.h"

namespace cf {

inline const CfDataCube* datacube_from_handle(const CfValueHandle* handle) {
  if (!handle || handle->storage_type != CF_STORAGE_DATACUBE) return nullptr;
  return reinterpret_cast<const CfDataCube*>(handle->data);
}

inline double* datacube_data(const CfValueHandle* handle) {
  const CfDataCube* cube = datacube_from_handle(handle);
  return cube ? cube->data : nullptr;
}

inline size_t datacube_length(const CfValueHandle* handle) {
  const CfDataCube* cube = datacube_from_handle(handle);
  return cube ? cube->length : 0;
}

}  // namespace cf

#endif
