Skip to content

Commit

Permalink
Merge pull request #261 from ruby-rice/dev
Browse files Browse the repository at this point in the history
Fill in missing to_ruby conversions for arrays of fundamental types.
  • Loading branch information
cfis authored Feb 24, 2025
2 parents 105953f + 3da5f72 commit 89b5aff
Showing 1 changed file with 240 additions and 0 deletions.
240 changes: 240 additions & 0 deletions rice/detail/to_ruby.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<int[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<int>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<int>>::verify();
}

VALUE convert(int buffer[N])
{
PointerView<int> pointerView(buffer, N);
Data_Object<PointerView<int>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== unsigned int ============
template<>
class To_Ruby<unsigned int>
Expand Down Expand Up @@ -205,6 +229,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<unsigned int[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<unsigned int>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<unsigned int>>::verify();
}

VALUE convert(unsigned int buffer[N])
{
PointerView<unsigned int> pointerView(buffer, N);
Data_Object<PointerView<unsigned int>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== char ============
template<>
class To_Ruby<char>
Expand Down Expand Up @@ -482,6 +530,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<signed char[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<signed char>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<signed char>>::verify();
}

VALUE convert(signed char buffer[N])
{
PointerView<signed char> pointerView(buffer, N);
Data_Object<PointerView<signed char>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== double ============
template<>
class To_Ruby<double>
Expand Down Expand Up @@ -546,6 +618,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<double[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<double>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<double>>::verify();
}

VALUE convert(double buffer[N])
{
PointerView<double> pointerView(buffer, N);
Data_Object<PointerView<double>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== float ============
template<>
class To_Ruby<float>
Expand Down Expand Up @@ -610,6 +706,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<float[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<float>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<float>>::verify();
}

VALUE convert(float buffer[N])
{
PointerView<float> pointerView(buffer, N);
Data_Object<PointerView<float>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== long ============
template<>
class To_Ruby<long>
Expand Down Expand Up @@ -674,6 +794,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<long[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<long>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<long>>::verify();
}

VALUE convert(long buffer[N])
{
PointerView<long> pointerView(buffer, N);
Data_Object<PointerView<long>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== unsigned long ============
template<>
class To_Ruby<unsigned long>
Expand Down Expand Up @@ -752,6 +896,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<unsigned long[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<unsigned long>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<unsigned long>>::verify();
}

VALUE convert(unsigned long buffer[N])
{
PointerView<unsigned long> pointerView(buffer, N);
Data_Object<PointerView<unsigned long>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== long long ============
template<>
class To_Ruby<long long>
Expand Down Expand Up @@ -816,6 +984,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<long long[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<long long>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<long long>>::verify();
}

VALUE convert(long long buffer[N])
{
PointerView<long long> pointerView(buffer, N);
Data_Object<PointerView<long long>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== unsigned long long ============
template<>
class To_Ruby<unsigned long long>
Expand Down Expand Up @@ -1001,6 +1193,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<short[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<short>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<short>>::verify();
}

VALUE convert(short buffer[N])
{
PointerView<short> pointerView(buffer, N);
Data_Object<PointerView<short>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== unsigned short ============
template<>
class To_Ruby<unsigned short>
Expand Down Expand Up @@ -1073,6 +1289,30 @@ namespace Rice
Arg* arg_ = nullptr;
};

template<int N>
class To_Ruby<unsigned short[N]>
{
public:
To_Ruby()
{
detail::Type<PointerView<unsigned short>>::verify();
};

explicit To_Ruby(Arg* arg) : arg_(arg)
{
detail::Type<PointerView<unsigned short>>::verify();
}

VALUE convert(unsigned short buffer[N])
{
PointerView<unsigned short> pointerView(buffer, N);
Data_Object<PointerView<unsigned short>> dataObject(pointerView, true);
return dataObject.value();
}
private:
Arg* arg_ = nullptr;
};

// =========== std::nullptr_t ============
template<>
class To_Ruby<std::nullptr_t>
Expand Down

0 comments on commit 89b5aff

Please sign in to comment.