20#include "dss_capi_ctx.h"
29typedef std::complex<double> complex;
31typedef Eigen::Matrix<int32_t, Eigen::Dynamic, 1> VectorXi;
32typedef std::vector<string> strings;
33typedef std::vector<int32_t> bools;
46 char*** data_PPAnsiChar;
47 double** data_PDouble;
48 int32_t** data_PInteger;
50 int32_t* count_PPAnsiChar;
51 int32_t* count_PDouble;
52 int32_t* count_PInteger;
55 void check_for_error()
57 if (!*error_ptr)
return;
59 int32_t error = *error_ptr;
60 char* error_msg = ctx_Error_Get_Description(ctx);
62 throw std::runtime_error(error_msg);
75 api_util->check_for_error();
89 ctx = ctx_Get_Prime();
91 ctx_DSS_Start(ctx, 0);
92 error_ptr = ctx_Error_Get_NumberPtr(ctx);
93 ctx_DSS_GetGRPointers(
106 APIUtil(
void *context,
bool is_owner=
false)
110 error_ptr = ctx_Error_Get_NumberPtr(ctx);
111 ctx_DSS_GetGRPointers(
136 template <typename T, typename enabled_ = std::enable_if_t<std::is_convertible<T*, dss::obj::DSSObj*>::value>>
137 T create(
const char *name,
bool activate=
true,
bool begin_edit=
true)
139 void *ptr = Obj_New(ctx, T::dss_cls_idx, name, activate, begin_edit);
148 template <typename T, typename enabled_ = std::enable_if_t<std::is_convertible<T*, dss::obj::DSSObj*>::value>>
149 T create(
const string &name,
bool activate=
true,
bool begin_edit=
true)
151 return create<T>(name.c_str(), activate, begin_edit);
159 template <typename T, typename enabled_ = std::enable_if_t<std::is_convertible<T*, dss::obj::DSSBatch*>::value>>
160 T create(
const char *prefix, int32_t count,
bool begin_edit=
true, int32_t start_at=1)
163 std::vector<string> names;
164 std::vector<const char*> names_ptrs;
165 names.reserve(count);
166 names_ptrs.reserve(count);
168 std::string sprefix = prefix;
169 for (int32_t i = 0; i < count; ++i)
171 names.emplace_back(fmt::format(
"{}{}", prefix, start_at + i));
172 names_ptrs.push_back(names.back().c_str());
174 Batch_CreateFromNew(ctx, &batch.pointer, batch.count, T::BatchElementClass::dss_cls_idx, &names_ptrs[0], count, begin_edit);
184 template <
typename T,
typename enabled_ =
186 std::is_convertible<T*, dss::obj::DSSBatch*>::value
189 T create(
const string &prefix, int32_t count,
bool begin_edit=
true, int32_t start_at=1)
191 return create<T>(prefix.c_str(), count, begin_edit, start_at);
194 template <
typename VectorT=Eigen::Matrix<
double, Eigen::Dynamic, 1>,
typename std::enable_if<std::is_same<
typename VectorT::value_type,
double>::value>::type* =
nullptr>
195 VectorT get_float64_gr_array()
197 APIUtil::ErrorChecker error_checker(
this);
199 res.resize(
size_t(*count_PDouble));
200 memcpy(&res[0], *data_PDouble,
sizeof(
typename VectorT::value_type) * (*count_PDouble));
204 template <
typename VectorT=Eigen::Matrix<
int32_t, Eigen::Dynamic, 1>,
typename std::enable_if<std::is_same<
typename VectorT::value_type,
int32_t>::value>::type* =
nullptr>
205 VectorT get_int32_gr_array()
207 APIUtil::ErrorChecker error_checker(
this);
209 res.resize(
size_t(*count_PInteger));
210 memcpy(&res[0], *data_PInteger,
sizeof(
typename VectorT::value_type) * (*count_PInteger));
214 template <
typename VectorT=Eigen::Matrix<
int8_t, Eigen::Dynamic, 1>,
typename std::enable_if<std::is_same<
typename VectorT::value_type,
int8_t>::value>::type* =
nullptr>
215 VectorT get_int8_gr_array()
217 APIUtil::ErrorChecker error_checker(
this);
219 res.resize(
size_t(*count_PByte));
220 memcpy(&res[0], *data_PByte,
sizeof(
typename VectorT::value_type) * (*count_PByte));
224 template<
typename FunctionT,
typename... Args>
225 strings get_string_array(FunctionT func, Args... args)
227 char** ResultPtr =
nullptr;
228 int32_t ResultCount[2] = {0, 0};
229 func(ctx, &ResultPtr, ResultCount, args...);
231 res.reserve(ResultCount[0]);
232 for (int32_t i = 0; i < ResultCount[0]; ++i)
234 res.emplace_back(ResultPtr[i]);
239 template<
typename FunctionT,
typename... Args>
240 void set_string_array(FunctionT func,
const strings &value, Args... args)
242 std::vector<const char*> ptrs(value.size(),
nullptr);
243 for (
size_t i = 0; i < value.size(); ++i)
245 ptrs[i] = value[i].c_str();
248 func(ctx, &ptrs[0], value.size(), args...);
Wraps common DSSContext state data.
Definition: dss_common.hpp:256
void * ctx
Pointer to the DSSContext for easy access.
Definition: dss_common.hpp:261
APIUtil * api_util
API utility functions.
Definition: dss_common.hpp:266
Definition: dss_common.hpp:66
Definition: dss_common.hpp:42