From cf18707c086a1b47600c924ae1f33a379d1d3fb2 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Tue, 23 May 2023 18:32:59 +0200 Subject: nix: Fixed dev install and moved folders --- .nix/derivation.nix | 5 +- SConstruct | 66 +++++++++++++++++++++ src/SConscript | 35 ++++++++++++ src/distance/meter.h | 20 +++++++ src/kelunit/distance/meter.h | 20 ------- src/kelunit/time/second.h | 15 ----- src/kelunit/unit.h | 49 ---------------- src/kelunit/unit.tmpl.h | 53 ----------------- src/kelunit/unit_cast.h | 15 ----- src/kelunit/unit_print.h | 55 ------------------ src/kelunit/unit_reduction.h | 133 ------------------------------------------- src/time/second.h | 15 +++++ src/unit.h | 49 ++++++++++++++++ src/unit.tmpl.h | 53 +++++++++++++++++ src/unit_cast.h | 15 +++++ src/unit_print.h | 55 ++++++++++++++++++ src/unit_reduction.h | 133 +++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 442 insertions(+), 344 deletions(-) create mode 100644 SConstruct create mode 100644 src/SConscript create mode 100644 src/distance/meter.h delete mode 100644 src/kelunit/distance/meter.h delete mode 100644 src/kelunit/time/second.h delete mode 100644 src/kelunit/unit.h delete mode 100644 src/kelunit/unit.tmpl.h delete mode 100644 src/kelunit/unit_cast.h delete mode 100644 src/kelunit/unit_print.h delete mode 100644 src/kelunit/unit_reduction.h create mode 100644 src/time/second.h create mode 100644 src/unit.h create mode 100644 src/unit.tmpl.h create mode 100644 src/unit_cast.h create mode 100644 src/unit_print.h create mode 100644 src/unit_reduction.h diff --git a/.nix/derivation.nix b/.nix/derivation.nix index cf887cd..94f5bb7 100644 --- a/.nix/derivation.nix +++ b/.nix/derivation.nix @@ -17,10 +17,7 @@ stdenvNoCC.mkDerivation { buildInputs = [ forstio.core - forstio.async - forstio.io - forstio.codec ]; - outputs = [ "out" ]; + outputs = [ "out" "dev" ]; } diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..ea16f95 --- /dev/null +++ b/SConstruct @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +) + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=['forstio-core']) +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('src/SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/src/SConscript b/src/SConscript new file mode 100644 index 0000000..41f12e1 --- /dev/null +++ b/src/SConscript @@ -0,0 +1,35 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +core_env = env.Clone(); + +core_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +core_env.headers = sorted(glob.glob(dir_path + "/*.h")) +core_env.headers += sorted(glob.glob(dir_path + "/distance/*.h")) +core_env.headers += sorted(glob.glob(dir_path + "/time/*.h")) + +env.sources += core_env.sources; +env.headers += core_env.headers; + +## Shared lib +objects_shared = [] +core_env.add_source_files(objects_shared, core_env.sources, shared=True); +core_env.library_shared = core_env.SharedLibrary('#build/kel-unit', [objects_shared]); + +# Set Alias +env.Alias('library_core', [core_env.library_shared, core_env.library_static]); + +env.targets += ['library_core']; + +# Install +env.Install('$prefix/lib/', [core_env.library_shared, core_env.library_static]); +env.Install('$prefix/include/kel/unit', [core_env.headers]); diff --git a/src/distance/meter.h b/src/distance/meter.h new file mode 100644 index 0000000..0d9fb3b --- /dev/null +++ b/src/distance/meter.h @@ -0,0 +1,20 @@ +#pragma once + +#include "../unit.h" + +#include + +namespace kel { +namespace unit_type { +struct meter{ + static constexpr std::string_view name = "meter"; + static constexpr std::string_view short_name = "m"; +}; +} + +template +using meter = unit>; + +template +using square_meter = unit>; +} diff --git a/src/kelunit/distance/meter.h b/src/kelunit/distance/meter.h deleted file mode 100644 index 0d9fb3b..0000000 --- a/src/kelunit/distance/meter.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "../unit.h" - -#include - -namespace kel { -namespace unit_type { -struct meter{ - static constexpr std::string_view name = "meter"; - static constexpr std::string_view short_name = "m"; -}; -} - -template -using meter = unit>; - -template -using square_meter = unit>; -} diff --git a/src/kelunit/time/second.h b/src/kelunit/time/second.h deleted file mode 100644 index 6dca456..0000000 --- a/src/kelunit/time/second.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "../unit.h" - -namespace kel { -namespace unit_type { -struct second{ - static constexpr std::string_view name = "second"; - static constexpr std::string_view short_name = "s"; -}; -} - -template -using second = unit>; -} diff --git a/src/kelunit/unit.h b/src/kelunit/unit.h deleted file mode 100644 index a8e8320..0000000 --- a/src/kelunit/unit.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "unit_reduction.h" - -namespace kel { -template -struct unit_component {}; - -template -class unit; - -template -class unit...> { -public: - using value_type = StorageT; - - unit() = default; - - unit(const unit...>&) = default; - unit(unit...>&&) = default; - - unit...>& operator=(const unit...>&) = default; - unit...>& operator=(unit...>&&) = default; - - unit(const value_type&); - unit(value_type&&); - - unit...>& operator=(const value_type&); - unit...>& operator=(value_type&&); - - unit...> operator+(const unit...>& rhs); - unit...> operator-(const unit...>& rhs); - - template - typename unit_multiplication...>, unit>::type operator*(const unit& rhs); - - template - typename unit_multiplication...>, typename unit_invert::type>::type operator/(const unit& rhs); - - value_type data() const; -private: - value_type value; -}; - -template -using scalar = unit; -} - -#include "unit.tmpl.h" diff --git a/src/kelunit/unit.tmpl.h b/src/kelunit/unit.tmpl.h deleted file mode 100644 index d89e0c1..0000000 --- a/src/kelunit/unit.tmpl.h +++ /dev/null @@ -1,53 +0,0 @@ -#include - -namespace kelun { - -template -unit...>::unit(const value_type& value_): - value{value_}{} - -template -unit...>::unit(value_type&& value_):value{std::move(value_)}{} - -template -unit...>& unit...>::operator=(const typename unit...>::value_type& value_){ - value = value_; - return *this; -} - -template -unit...>& unit...>::operator=(typename unit...>::value_type&& value_){ - value = std::move(value_); - return *this; -} - -template -unit...> unit...>::operator+(const unit...>& rhs){ - return value + rhs.value; -} - -template -unit...> unit...>::operator-(const unit...>& rhs){ - return value - rhs.value; -} - -template -template -typename unit_multiplication...>, unit>::type -unit...>::operator*(const unit& rhs){ - return value * rhs.data(); -} - -template -template -typename unit_multiplication...>, typename unit_invert::type>::type -unit...>::operator/(const unit& rhs){ - typename unit_invert::type rhs_inverted{static_cast(1)/rhs.data()}; - return value * rhs_inverted.data(); -} - -template -typename unit...>::value_type unit...>::data() const { - return value; -} -} diff --git a/src/kelunit/unit_cast.h b/src/kelunit/unit_cast.h deleted file mode 100644 index 8dc2689..0000000 --- a/src/kelunit/unit_cast.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace kel { -template -class unit_convert { - static_assert(always_false, "Units can't be converted to each other"); -}; - -template -class unit_convert { - static constexpr factor = static_cast(1); -}; -} diff --git a/src/kelunit/unit_print.h b/src/kelunit/unit_print.h deleted file mode 100644 index 0f3cb72..0000000 --- a/src/kelunit/unit_print.h +++ /dev/null @@ -1,55 +0,0 @@ -#include "./unit.h" - -#include - - -namespace std { -template -inline ostream& operator<<(ostream& o, const kelun::unit_base& ele){ - o< -struct unit_print_impl { - static_assert(is_always_false, "Template type not supported"); -}; - -template -struct unit_print_impl,unit_base...> { - static std::ostream& print(std::ostream& o){ - - unit_base element; - - std::ostream& o_ret = o << element; - - if constexpr (sizeof...(UnitTL) > 0){ - std::ostream& o_ret_next = o_ret << ' ' << '*' << ' '; - return unit_print_impl...>::print(o_ret_next); - } - - return o_ret<<']'; - } -}; -} - -namespace std { - -template -inline ostream& operator<<(ostream& o, const kelun::unit& unit); - -template -inline ostream& operator<<(ostream& o, const kelun::unit...>& unit){ - o << unit.data(); - if constexpr (sizeof...(UnitT) > 0) { - auto& o_ret = o << ' '<<'['; - return kelun::unit_print_impl...>::print(o_ret); - } - return o; -} -} diff --git a/src/kelunit/unit_reduction.h b/src/kelunit/unit_reduction.h deleted file mode 100644 index d9060d2..0000000 --- a/src/kelunit/unit_reduction.h +++ /dev/null @@ -1,133 +0,0 @@ -#pragma once - -#include -#include - -namespace kelun { -template -constexpr bool is_always_false = false; - -template -struct unit_component; - -template -class unit; - -namespace impl { - -template -class unit_matching; - -template -class unit_redux_list { - static_assert(sizeof...(T) == 0, "Template type not supported"); - - using reduced_typed = unit_redux_list<>; -}; - -template -struct unit_redux_list, unit_component...> { - using reduced_type = typename unit_matching, unit_component...>, unit_redux_list<>>::type; -}; - -template -class unit_matching_reduce { -public: - static_assert(is_always_false, "Template type not supported"); -}; - -template -class unit_matching_reduce, unit_redux_list,unit_component...>, unit_redux_list...>> { -public: - static constexpr bool is_same = std::is_same_v; - - using match_reduce_type = typename std::conditional, unit_component>::type; - using match_reduce_unit_redux_list = typename std::conditional...>, unit_redux_list..., unit_component>>::type; - - using value_type = typename unit_matching_reduce...>, match_reduce_unit_redux_list>::value_type; - using unit_redux_list_type = typename unit_matching_reduce...>, match_reduce_unit_redux_list>::unit_redux_list_type; - - static constexpr int64_t value_num = unit_matching_reduce...>, match_reduce_unit_redux_list>::value_num; -}; - -template -class unit_matching_reduce, unit_redux_list<>, unit_redux_list...>> { -public: - using value_type = unit_component; - using unit_redux_list_type = unit_redux_list...>; - - static constexpr int64_t value_num = E; -}; - -template -class unit_matching { - static_assert(is_always_false, "Template type not supported"); -}; - -template -class unit_matching,unit_redux_list...>> { -public: - using type = unit_redux_list...>; - -}; - -template -class unit_matching,unit_component...>, unit_redux_list...>> { -public: - using reduced_value_type = typename unit_matching_reduce, unit_redux_list...>, unit_redux_list<>>::value_type; - using reduced_unit_redux_list_type = typename unit_matching_reduce, unit_redux_list...>, unit_redux_list<>>::unit_redux_list_type; - - static constexpr int64_t reduced_value_num = unit_matching_reduce, unit_redux_list...>, unit_redux_list<>>::value_num; - using reduced_result_unit_redux_list = typename std::conditional...>, unit_redux_list...,reduced_value_type>>::type; - - using type = typename unit_matching::type; -}; - -template -class unit_matching_add_storage { -public: - static_assert(is_always_false, "Template type not supported"); -}; - -template -class unit_matching_add_storage...>, StorageT> { -public: - using type = unit...>; -}; - -} - -template -class unit_reduction { - static_assert(is_always_false, "Template type not supported"); -}; - -template -class unit_reduction...> { -public: - using list_type = typename impl::unit_matching...>, impl::unit_redux_list<>>::type; - using type = typename impl::unit_matching_add_storage::type; -}; - -template -class unit_invert { - static_assert(is_always_false, "Template type not supported"); -}; - -template -class unit_invert...> { -public: - using type = unit...>; -}; - -template -class unit_multiplication{ - static_assert(is_always_false, "Template type not supported"); -}; - -template -class unit_multiplication...>, unit...>> { -public: - using type = typename unit_reduction..., unit_component...>::type; -}; -} diff --git a/src/time/second.h b/src/time/second.h new file mode 100644 index 0000000..6dca456 --- /dev/null +++ b/src/time/second.h @@ -0,0 +1,15 @@ +#pragma once + +#include "../unit.h" + +namespace kel { +namespace unit_type { +struct second{ + static constexpr std::string_view name = "second"; + static constexpr std::string_view short_name = "s"; +}; +} + +template +using second = unit>; +} diff --git a/src/unit.h b/src/unit.h new file mode 100644 index 0000000..a8e8320 --- /dev/null +++ b/src/unit.h @@ -0,0 +1,49 @@ +#pragma once + +#include "unit_reduction.h" + +namespace kel { +template +struct unit_component {}; + +template +class unit; + +template +class unit...> { +public: + using value_type = StorageT; + + unit() = default; + + unit(const unit...>&) = default; + unit(unit...>&&) = default; + + unit...>& operator=(const unit...>&) = default; + unit...>& operator=(unit...>&&) = default; + + unit(const value_type&); + unit(value_type&&); + + unit...>& operator=(const value_type&); + unit...>& operator=(value_type&&); + + unit...> operator+(const unit...>& rhs); + unit...> operator-(const unit...>& rhs); + + template + typename unit_multiplication...>, unit>::type operator*(const unit& rhs); + + template + typename unit_multiplication...>, typename unit_invert::type>::type operator/(const unit& rhs); + + value_type data() const; +private: + value_type value; +}; + +template +using scalar = unit; +} + +#include "unit.tmpl.h" diff --git a/src/unit.tmpl.h b/src/unit.tmpl.h new file mode 100644 index 0000000..d89e0c1 --- /dev/null +++ b/src/unit.tmpl.h @@ -0,0 +1,53 @@ +#include + +namespace kelun { + +template +unit...>::unit(const value_type& value_): + value{value_}{} + +template +unit...>::unit(value_type&& value_):value{std::move(value_)}{} + +template +unit...>& unit...>::operator=(const typename unit...>::value_type& value_){ + value = value_; + return *this; +} + +template +unit...>& unit...>::operator=(typename unit...>::value_type&& value_){ + value = std::move(value_); + return *this; +} + +template +unit...> unit...>::operator+(const unit...>& rhs){ + return value + rhs.value; +} + +template +unit...> unit...>::operator-(const unit...>& rhs){ + return value - rhs.value; +} + +template +template +typename unit_multiplication...>, unit>::type +unit...>::operator*(const unit& rhs){ + return value * rhs.data(); +} + +template +template +typename unit_multiplication...>, typename unit_invert::type>::type +unit...>::operator/(const unit& rhs){ + typename unit_invert::type rhs_inverted{static_cast(1)/rhs.data()}; + return value * rhs_inverted.data(); +} + +template +typename unit...>::value_type unit...>::data() const { + return value; +} +} diff --git a/src/unit_cast.h b/src/unit_cast.h new file mode 100644 index 0000000..8dc2689 --- /dev/null +++ b/src/unit_cast.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace kel { +template +class unit_convert { + static_assert(always_false, "Units can't be converted to each other"); +}; + +template +class unit_convert { + static constexpr factor = static_cast(1); +}; +} diff --git a/src/unit_print.h b/src/unit_print.h new file mode 100644 index 0000000..0f3cb72 --- /dev/null +++ b/src/unit_print.h @@ -0,0 +1,55 @@ +#include "./unit.h" + +#include + + +namespace std { +template +inline ostream& operator<<(ostream& o, const kelun::unit_base& ele){ + o< +struct unit_print_impl { + static_assert(is_always_false, "Template type not supported"); +}; + +template +struct unit_print_impl,unit_base...> { + static std::ostream& print(std::ostream& o){ + + unit_base element; + + std::ostream& o_ret = o << element; + + if constexpr (sizeof...(UnitTL) > 0){ + std::ostream& o_ret_next = o_ret << ' ' << '*' << ' '; + return unit_print_impl...>::print(o_ret_next); + } + + return o_ret<<']'; + } +}; +} + +namespace std { + +template +inline ostream& operator<<(ostream& o, const kelun::unit& unit); + +template +inline ostream& operator<<(ostream& o, const kelun::unit...>& unit){ + o << unit.data(); + if constexpr (sizeof...(UnitT) > 0) { + auto& o_ret = o << ' '<<'['; + return kelun::unit_print_impl...>::print(o_ret); + } + return o; +} +} diff --git a/src/unit_reduction.h b/src/unit_reduction.h new file mode 100644 index 0000000..d9060d2 --- /dev/null +++ b/src/unit_reduction.h @@ -0,0 +1,133 @@ +#pragma once + +#include +#include + +namespace kelun { +template +constexpr bool is_always_false = false; + +template +struct unit_component; + +template +class unit; + +namespace impl { + +template +class unit_matching; + +template +class unit_redux_list { + static_assert(sizeof...(T) == 0, "Template type not supported"); + + using reduced_typed = unit_redux_list<>; +}; + +template +struct unit_redux_list, unit_component...> { + using reduced_type = typename unit_matching, unit_component...>, unit_redux_list<>>::type; +}; + +template +class unit_matching_reduce { +public: + static_assert(is_always_false, "Template type not supported"); +}; + +template +class unit_matching_reduce, unit_redux_list,unit_component...>, unit_redux_list...>> { +public: + static constexpr bool is_same = std::is_same_v; + + using match_reduce_type = typename std::conditional, unit_component>::type; + using match_reduce_unit_redux_list = typename std::conditional...>, unit_redux_list..., unit_component>>::type; + + using value_type = typename unit_matching_reduce...>, match_reduce_unit_redux_list>::value_type; + using unit_redux_list_type = typename unit_matching_reduce...>, match_reduce_unit_redux_list>::unit_redux_list_type; + + static constexpr int64_t value_num = unit_matching_reduce...>, match_reduce_unit_redux_list>::value_num; +}; + +template +class unit_matching_reduce, unit_redux_list<>, unit_redux_list...>> { +public: + using value_type = unit_component; + using unit_redux_list_type = unit_redux_list...>; + + static constexpr int64_t value_num = E; +}; + +template +class unit_matching { + static_assert(is_always_false, "Template type not supported"); +}; + +template +class unit_matching,unit_redux_list...>> { +public: + using type = unit_redux_list...>; + +}; + +template +class unit_matching,unit_component...>, unit_redux_list...>> { +public: + using reduced_value_type = typename unit_matching_reduce, unit_redux_list...>, unit_redux_list<>>::value_type; + using reduced_unit_redux_list_type = typename unit_matching_reduce, unit_redux_list...>, unit_redux_list<>>::unit_redux_list_type; + + static constexpr int64_t reduced_value_num = unit_matching_reduce, unit_redux_list...>, unit_redux_list<>>::value_num; + using reduced_result_unit_redux_list = typename std::conditional...>, unit_redux_list...,reduced_value_type>>::type; + + using type = typename unit_matching::type; +}; + +template +class unit_matching_add_storage { +public: + static_assert(is_always_false, "Template type not supported"); +}; + +template +class unit_matching_add_storage...>, StorageT> { +public: + using type = unit...>; +}; + +} + +template +class unit_reduction { + static_assert(is_always_false, "Template type not supported"); +}; + +template +class unit_reduction...> { +public: + using list_type = typename impl::unit_matching...>, impl::unit_redux_list<>>::type; + using type = typename impl::unit_matching_add_storage::type; +}; + +template +class unit_invert { + static_assert(is_always_false, "Template type not supported"); +}; + +template +class unit_invert...> { +public: + using type = unit...>; +}; + +template +class unit_multiplication{ + static_assert(is_always_false, "Template type not supported"); +}; + +template +class unit_multiplication...>, unit...>> { +public: + using type = typename unit_reduction..., unit_component...>::type; +}; +} -- cgit v1.2.3