knowL: Knowledge Libraries
Loading...
Searching...
No Matches
ValueToValueImplementation.h
1#include "Interfaces/ValueToValue.h"
2
3#include <rice/rice.hpp>
4
5#include <knowCore/Value.h>
6
7#include "HandleResult.h"
8
9namespace knowRuby
10{
11 template<typename _T_>
13 {
14 static constexpr bool as_pointer = true;
15 };
16 template<typename _T_>
18 {
19 public:
21 bool canConvertToRubyValue(const knowCore::Value& _value) const override
22 {
23 return _value.canConvert<_T_>();
24 }
25 bool canConvertToKnowCoreValue(VALUE _value) const override
26 {
27 return Rice::detail::From_Ruby<_T_>().is_convertible(_value)
28 != Rice::detail::Convertible::None;
29 }
30 VALUE toRubyValue(const knowCore::Value& _value) const override
31 {
32 if constexpr(std::is_trivially_constructible_v<_T_>
34 {
35 return Rice::detail::To_Ruby<_T_>().convert(handle(_value.value<_T_>()));
36 }
37 else
38 {
39 Rice::Return r;
40 r.takeOwnership();
41 return Rice::detail::To_Ruby<_T_*>(&r).convert(new _T_(handle(_value.value<_T_>())));
42 }
43 }
44 knowCore::Value toKnowCoreValue(VALUE _value) const override
45 {
46 return knowCore::Value::fromValue(Rice::detail::From_Ruby<_T_>().convert(_value));
47 }
48 };
49} // namespace knowRuby
Definition Value.h:21
static Value fromValue(const _T_ &_value)
Definition Value.h:241
cres_qresult< _T_ > value(TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
Definition Value.h:353
bool canConvert(TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
Definition Value.h:364
Definition ValueToValue.h:9
Definition ValueToValueImplementation.h:18
Definition ValueToValueImplementation.h:13