summaryrefslogtreecommitdiff
path: root/modules/codec
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec')
-rw-r--r--modules/codec/c++/args.hpp19
-rw-r--r--modules/codec/c++/data.hpp16
-rw-r--r--modules/codec/c++/data_math.hpp15
-rw-r--r--modules/codec/c++/math.hpp15
-rw-r--r--modules/codec/c++/schema.hpp14
-rw-r--r--modules/codec/c++/schema_meta.hpp18
-rw-r--r--modules/codec/c++/tas.hpp38
-rw-r--r--modules/codec/tests/math.cpp2
8 files changed, 123 insertions, 14 deletions
diff --git a/modules/codec/c++/args.hpp b/modules/codec/c++/args.hpp
index 0253417..66acd97 100644
--- a/modules/codec/c++/args.hpp
+++ b/modules/codec/c++/args.hpp
@@ -199,4 +199,23 @@ public:
return eov;
}
};
+
+/**
+ * Helper function to reduce boilerplate
+ */
+template<typename ArgSch>
+error_or<data<ArgSch>> parse_args(int argc, char** argv){
+ data<ArgSch> dec_dat;
+
+ {
+ data<ArgSch,encode::Args> arg_dat{argc,argv};
+ codec<ArgSch,encode::Args> arg_cod;
+ auto eov = arg_cod.decode(arg_dat,dec_dat);
+ if(eov.is_error()){
+ return std::move(eov.get_error());
+ }
+ }
+
+ return dec_dat;
+}
}
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp
index 6a796f5..79a6ab8 100644
--- a/modules/codec/c++/data.hpp
+++ b/modules/codec/c++/data.hpp
@@ -90,7 +90,7 @@ struct native_data_type<schema::Primitive<schema::FloatingPoint, 8>> {
template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING>
class data {
private:
- static_assert(always_false<T>, "Type not supported.");
+ static_assert(always_false<T,Encoding>, "Type not supported.");
};
template<>
@@ -171,6 +171,10 @@ public:
constexpr data<Schema, encode::Native> operator-(const data<Schema, encode::Native>& rhs)const{
return {get() - rhs.get()};
}
+
+ constexpr data<Schema, encode::Native> operator-() const {
+ return {-get()};
+ }
constexpr data<Schema, encode::Native>& operator++() {
set(get() + static_cast<typename native_data_type<Schema>::type>(1));
@@ -326,6 +330,14 @@ public:
{
}
+ /*
+ template<typename... Args>
+ requires (sizeof...(Args) == ct_multiply<uint64_t, D...>::value) &&
+ (std::constructible_from<data<T, encode::Native>, Args> && ...)
+ constexpr data(Args&&... args):
+ value_{ { std::forward<Args>(args)... } } {}
+ */
+
SAW_DEFAULT_COPY(data);
SAW_DEFAULT_MOVE(data);
@@ -657,9 +669,7 @@ class data<schema::Array<T,Dim>, encode::Native> {
uint64_t s = 1;
for(uint64_t iter = 0; iter < Dim; ++iter){
-
auto& dim_iter = dims_.at(data<schema::UInt64>{iter});
-
s *= dim_iter.get();
}
diff --git a/modules/codec/c++/data_math.hpp b/modules/codec/c++/data_math.hpp
index 1a56bd0..9d07eb3 100644
--- a/modules/codec/c++/data_math.hpp
+++ b/modules/codec/c++/data_math.hpp
@@ -131,8 +131,21 @@ public:
return c;
}
+ data<schema::Tensor<Inner, Dims...>, encode::Native> operator-() const {
+ data<schema::Tensor<Inner, Dims...>, encode::Native> c;
+
+ rank_iterator<Dims...>::in_fixed_bounds([&](const data<schema::FixedArray<schema::UInt64, sizeof...(Dims)>, encode::Native>& index) -> error_or<void>{
+ c.at(index) = -at(index);
+ return make_void();
+ });
+
+ return c;
+ }
+
+
+
template<typename InnerChange>
- data<schema::Tensor<InnerChange, Dims...>, encode::Native> cast_to(){
+ data<schema::Tensor<InnerChange, Dims...>, encode::Native> cast_to() const {
data<schema::Tensor<InnerChange, Dims...>, encode::Native> native_change;
rank_iterator<Dims...>::in_fixed_bounds([&](const data<schema::FixedArray<schema::UInt64, sizeof...(Dims)>, encode::Native>& index) -> error_or<void>{
native_change.at(index) = at(index).template cast_to<InnerChange>();
diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp
index 2ce8333..1d627e6 100644
--- a/modules/codec/c++/math.hpp
+++ b/modules/codec/c++/math.hpp
@@ -141,6 +141,21 @@ data<schema::Scalar<T>,Encoding> cross(
}
template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING>
+data<schema::Vector<T,2u>,Encoding> cross(
+ const data<schema::Scalar<T>, Encoding> lh,
+ const data<schema::Vector<T,2u>, Encoding> rh
+){
+ data<schema::Vector<T,2u>, Encoding> cross_prod;
+
+ cross_prod.at({{0u}}) = lh.at({}) * rh.at({{1u}}) * -1;
+ cross_prod.at({{1u}}) = lh.at({}) * rh.at({{0u}});
+
+ return cross_prod;
+}
+
+
+
+template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING>
data<schema::Scalar<T>,Encoding> cos(
const data<schema::Scalar<T>,Encoding>& val
){
diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp
index 018cb41..b5839f4 100644
--- a/modules/codec/c++/schema.hpp
+++ b/modules/codec/c++/schema.hpp
@@ -114,7 +114,7 @@ class Ref {
* data<Ptr<Float64>> type.
*/
template<typename Schema>
-class Ptr {
+struct Ptr {
static constexpr string_literal name = "Ptr";
using ValueType = Schema;
@@ -178,6 +178,18 @@ struct MixedPrecision {
static_assert(is_primitive<PrimA>::value, "InterfaceSchema needs to be a Primitive");
static_assert(is_primitive<PrimB>::value, "StorageSchema needs to be a Primitive");
};
+/**
+ * Classes enabling IdMap stuff
+ */
+template<typename T>
+struct Id {
+ using Schema = Id;
+};
+
+template<typename T>
+struct IdMap {
+ using Schema = IdMap<T>;
+};
/**
* Classes enabling Rpc calls
diff --git a/modules/codec/c++/schema_meta.hpp b/modules/codec/c++/schema_meta.hpp
index ff66bbb..efa486d 100644
--- a/modules/codec/c++/schema_meta.hpp
+++ b/modules/codec/c++/schema_meta.hpp
@@ -23,8 +23,8 @@ struct meta_schema<schema::Bool> {
template<typename T, uint64_t N>
struct meta_schema<schema::Primitive<T,N>> {
- using MetaSchema = schema::Void;
using Schema = schema::Primitive<T,N>;
+ using MetaSchema = schema::Void;
};
template<typename TA, uint64_t NA, typename TB, uint64_t NB>
@@ -35,38 +35,38 @@ struct meta_schema<schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Prim
template<typename T>
struct meta_schema<schema::Ref<T>> {
- using MetaSchema = schema::Void;
using Schema = schema::Ref<T>;
+ using MetaSchema = schema::Void;
};
template<typename Key, typename Value>
struct meta_schema<schema::Map<Key,Value>> {
- using MetaSchema = schema::Void;
using Schema = schema::Map<Key,Value>;
+ using MetaSchema = schema::Void;
};
template<typename... T, string_literal... Lit>
struct meta_schema<schema::Struct<schema::Member<T,Lit>...>> {
- using MetaSchema = schema::Struct<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
using Schema = schema::Struct<schema::Member<T,Lit>...>;
+ using MetaSchema = schema::Struct<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
};
template<typename... T, string_literal... Lit>
struct meta_schema<schema::Union<schema::Member<T,Lit>...>> {
- using MetaSchema = schema::Union<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
using Schema = schema::Union<schema::Member<T,Lit>...>;
+ using MetaSchema = schema::Union<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
};
template<typename... T>
struct meta_schema<schema::Tuple<T...>> {
- using MetaSchema = schema::Tuple<typename meta_schema<T>::MetaSchema...>;
using Schema = schema::Tuple<T...>;
+ using MetaSchema = schema::Tuple<typename meta_schema<T>::MetaSchema...>;
};
template<>
struct meta_schema<schema::String> {
- using MetaSchema = schema::UInt64;
using Schema = schema::String;
+ using MetaSchema = schema::UInt64;
};
/**
@@ -75,14 +75,14 @@ struct meta_schema<schema::String> {
template<typename T, uint64_t Dim>
struct meta_schema<schema::Array<T,Dim>> {
// TODO Technically this should be a FixedArray of the inner meta schema, except when the inner meta schema is Void
- using MetaSchema = schema::FixedArray<schema::UInt64,Dim>;
using Schema = schema::Array<T,Dim>;
+ using MetaSchema = schema::FixedArray<schema::UInt64,Dim>;
};
template<typename T, uint64_t... Dim>
struct meta_schema<schema::FixedArray<T,Dim...>> {
// TODO Technically this should be a FixedArray of the inner meta schema, except when the inner meta schema is Void
- using MetaSchema = schema::Void;
using Schema = schema::FixedArray<T,Dim...>;
+ using MetaSchema = schema::Void;
};
}
diff --git a/modules/codec/c++/tas.hpp b/modules/codec/c++/tas.hpp
new file mode 100644
index 0000000..f130119
--- /dev/null
+++ b/modules/codec/c++/tas.hpp
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "data.hpp"
+
+namespace saw {
+namespace schema {
+/**
+ * Tuple of Arrays of Structs => TAS
+ *
+ * So the idea is that I have an iterable data structure
+ * with filter what the members contain.
+ *
+ * So lets say I want to iterate over every body with the
+ * attribute "age", but not every object
+ * contains the member age and not every object with age
+ * are identical to each other.
+ *
+ * And if I want to avoid inheritance I need something to
+ * handle it.
+ * Which would be this object.
+ *
+ * I need enforcement over attribute equality.
+ * Only forward checks are needed.
+ *
+ */
+template<typename... T>
+struct Tas {};
+}
+
+template<typename... T, typename Encoding>
+class data<schema::Tas<T...>, Encoding> final {
+public:
+ using Schema = schema::Tas<T...>;
+private:
+ data<schema::Tuple<T...>, Encoding> inner_;
+public:
+};
+}
diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp
index 34dcce8..18b6c41 100644
--- a/modules/codec/tests/math.cpp
+++ b/modules/codec/tests/math.cpp
@@ -76,6 +76,8 @@ SAW_TEST("Math/Tensor"){
SAW_EXPECT(d.at({{1u,0u}}).get() == 1.0, std::string{"Unexpected value at (1,0): "} + std::to_string(d.at({{1u,0u}}).get()));
SAW_EXPECT(d.at({{1u,1u}}).get() == 1.0, std::string{"Unexpected value at (1,1): "} + std::to_string(d.at({{1u,1u}}).get()));
}
+
+ auto e = -a;
}
SAW_TEST("Math/Rotate"){