summaryrefslogtreecommitdiff
path: root/modules/codec/c++
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/c++')
-rw-r--r--modules/codec/c++/data.hpp30
-rw-r--r--modules/codec/c++/simple.hpp24
2 files changed, 35 insertions, 19 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp
index 9f65d08..ce57967 100644
--- a/modules/codec/c++/data.hpp
+++ b/modules/codec/c++/data.hpp
@@ -319,14 +319,6 @@ public:
value_{value__}
{}
- constexpr data<T, encode::Native>& at(const std::array<uint64_t, sizeof...(D)>& ind){
- return value_.at(this->get_flat_index(ind));
- }
-
- constexpr const data<T, encode::Native>& at(const std::array<uint64_t, sizeof...(D)>& ind) const {
- return value_.at(this->get_flat_index(ind));
- }
-
constexpr data<T, encode::Native>& at(data<schema::UInt64, encode::Native> i) {
return value_.at(this->get_flat_index({i.get()}));
}
@@ -861,5 +853,27 @@ public:
}
};
+/**
+ * I need some basic support to be able to have some STL guarantees for now.
+ * I probably should to a trait check on the encoding to have some guarantees regarding the layout instead.
+ */
+template<typename Schema, typename Encode>
+struct convert_to_stl {
+ static_assert(always_false<Schema,Encode>, "Encode or Schema not supported for stl conversion");
+};
+
+template<typename T, uint64_t Dim>
+struct convert_to_stl<schema::FixedArray<T,Dim>, encode::Native> {
+ using Schema = schema::FixedArray<T,Dim>;
+ static_assert(is_primitive<T>::value, "Only supports primitives");
+
+ std::array<typename native_data_type<T>::type, Dim> operator()(const data<Schema,encode::Native>& inp){
+ std::array<typename native_data_type<T>::type,Dim> conv;
+ for(uint64_t i = 0u; i < Dim; ++i){
+ conv[i] = inp.at({i}).get();
+ }
+ return conv;
+ }
+};
}
diff --git a/modules/codec/c++/simple.hpp b/modules/codec/c++/simple.hpp
index de35c3e..0e5ef6d 100644
--- a/modules/codec/c++/simple.hpp
+++ b/modules/codec/c++/simple.hpp
@@ -48,12 +48,12 @@ struct kelsimple_encode<schema::Primitive<T,N>, FromEnc> {
template<typename T, size_t Dim, typename FromEnc>
struct kelsimple_encode<schema::Array<T,Dim>, FromEnc> {
template<std::size_t Level>
- static error_or<void> encode_level(const data<schema::Array<T,Dim>, FromEnc>& from, buffer& to, std::array<std::size_t, Dim>& index){
+ static error_or<void> encode_level(const data<schema::Array<T,Dim>, FromEnc>& from, buffer& to, data<schema::FixedArray<schema::UInt64, Dim>, FromEnc>& index){
if constexpr (Dim == Level){
return kelsimple_encode<T,FromEnc>::encode(from.at(index), to);
} else {
const std::size_t dim_size = from.get_dim_size(Level);
- for(index[Level] = 0; (index.at(Level) < dim_size); ++index[Level]){
+ for(index.at(Level) = 0; (index.at(Level).get() < dim_size); ++index.at(Level)){
auto eov = encode_level<Level+1>(from, to, index);
if(eov.is_error()){
return eov;
@@ -73,8 +73,10 @@ struct kelsimple_encode<schema::Array<T,Dim>, FromEnc> {
}
}
{
- std::array<std::size_t, Dim> index;
- std::fill(index.begin(), index.end(), 0);
+ data<schema::FixedArray<schema::UInt64, Dim>,FromEnc> index;
+ for(data<schema::UInt64,FromEnc> i{0u}; i.get() < Dim; ++i){
+ index.at(i) = 0u;
+ }
return encode_level<0>(from, to, index);
}
@@ -210,12 +212,12 @@ struct kelsimple_decode<schema::Primitive<T,N>, FromEnc> {
template<typename T, size_t Dim, typename FromEnc>
struct kelsimple_decode<schema::Array<T,Dim>, FromEnc> {
template<std::size_t Level>
- static error_or<void> decode_level(buffer& from, data<schema::Array<T,Dim>, FromEnc>& to, std::array<std::size_t, Dim>& index){
+ static error_or<void> decode_level(buffer& from, data<schema::Array<T,Dim>, FromEnc>& to, data<schema::FixedArray<schema::UInt64,Dim>, FromEnc>& index){
if constexpr (Level == Dim){
- return kelsimple_decode<T, FromEnc>::decode(from, {to.at(index)});
+ return kelsimple_decode<T, FromEnc>::decode(from, to.at(index));
}else{
- const std::size_t dim_size = to.get_dim_size(Level);
- for(index[Level] = 0; index[Level] < dim_size; ++index[Level]){
+ const auto dim_size = to.get_dim_size(Level);
+ for(index.at(Level) = 0; index.at(Level).get() < dim_size; ++index.at(Level)){
auto eov = decode_level<Level+1>(from, to, index);
if(eov.is_error()){
return eov;
@@ -227,19 +229,19 @@ struct kelsimple_decode<schema::Array<T,Dim>, FromEnc> {
static error_or<void> decode(buffer& from, data<schema::Array<T,Dim>, FromEnc>& to){
{
- std::array<std::size_t, Dim> dims{};
+ data<schema::FixedArray<schema::UInt64, Dim>, FromEnc> dims{};
for(std::size_t i = 0; i < Dim; ++i){
uint64_t val{};
auto eov = stream_value<schema::UInt64>::decode(val, from);
if(eov.is_error()){
return eov;
}
- dims.at(i) = static_cast<std::size_t>(val);
+ dims.at({i}) = {static_cast<std::size_t>(val)};
}
to = data<schema::Array<T,Dim>,FromEnc>{dims};
}
{
- std::array<std::size_t, Dim> index{};
+ data<schema::FixedArray<schema::UInt64, Dim>, FromEnc> index{};
return decode_level<0>(from, to, index);
}
return void_t{};