diff --git a/CMakeLists.txt b/CMakeLists.txt index d96e4af4..15dd0327 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,11 @@ endif() ############################################################################### -RAGEL_TARGET(json-flat json/flat.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/json/flat.cpp) -RAGEL_TARGET(uri uri.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/uri.cpp) +RAGEL_TARGET(json-flat json/flat.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/json/flat.cpp COMPILE_FLAGS -G2) +RAGEL_TARGET(uri uri.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/uri.cpp COMPILE_FLAGS -G2) RAGEL_TARGET(version version.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/version.cpp) RAGEL_TARGET(format.cpp format.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/format.cpp) - +RAGEL_TARGET(parse8601 time/parse8601.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/time/parse8601.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -76,16 +76,6 @@ else () endif () -############################################################################### -# platform libraries -search_libs (SHM_LIBS shm_open rt) -search_libs (DL_LIBS dlopen dl) -search_libs (CLOCK_LIB clock_gettime rt c) -search_libs (MATH_LIB cos m) - -list (APPEND LIBS ${SHM_LIBS} ${DL_LIBS} ${CLOCK_LIB} ${MATH_LIB}) - - ############################################################################### # platform wrappers list ( @@ -93,8 +83,12 @@ list ( posix/dir.cpp posix/dir.hpp posix/dir.ipp + posix/except.cpp + posix/except.hpp posix/fd.cpp posix/fd.hpp + posix/socket.cpp + posix/socket.hpp ) @@ -133,6 +127,8 @@ if (WINDOWS) library_win32.hpp library_win32.cpp time_win32.cpp + win32/except.cpp + win32/except.hpp win32/handle.cpp win32/handle.hpp win32/registry.hpp @@ -194,9 +190,9 @@ list ( coord.hpp coord/init.hpp coord/iostream.hpp - coord/names.hpp coord/ops.hpp coord/store.hpp + coord/traits.hpp crypto/arc4.cpp crypto/arc4.hpp crypto/ice.cpp @@ -212,10 +208,10 @@ list ( debug.cpp debug.hpp debug.ipp + encode/base.cpp + encode/base.hpp endian.cpp endian.hpp - except.cpp - except.hpp exe.hpp extent.cpp extent.hpp @@ -341,7 +337,6 @@ list ( matrix3.cpp matrix4.cpp matrix.hpp - matrix.ipp memory/deleter.cpp memory/deleter.hpp nocopy.hpp @@ -406,7 +401,8 @@ list ( term.hpp time.cpp time.hpp - time.ipp + time/parse.hpp + time/parse8601.cpp tuple.cpp tuple.hpp typeidx.cpp @@ -453,7 +449,20 @@ DEPENDS ############################################################################### add_library(cruft-util ${UTIL_FILES}) -target_link_libraries (cruft-util ${LIBS}) +target_link_libraries (cruft-util PUBLIC ${LIBS}) +target_include_directories(cruft-util PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") + +############################################################################### +# platform libraries +search_libs (SHM_LIBS shm_open rt) +search_libs (DL_LIBS dlopen dl) +search_libs (CLOCK_LIBS clock_gettime rt c) +search_libs (MATH_LIBS cos m) + +target_link_libraries(cruft-util PUBLIC ${SHM_LIBS}) +target_link_libraries(cruft-util PUBLIC ${DL_LIBS}) +target_link_libraries(cruft-util PUBLIC ${CLOCK_LIBS}) +target_link_libraries(cruft-util PUBLIC ${MATH_LIBS}) ############################################################################### @@ -461,6 +470,7 @@ foreach (tool hash json-clean json-schema json-validate scratch) add_executable (util_${tool} tools/${tool}.cpp) set_target_properties (util_${tool} PROPERTIES OUTPUT_NAME ${tool}) target_link_libraries (util_${tool} cruft-util) + target_include_directories(util_${tool} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) endforeach () @@ -494,6 +504,7 @@ if (TESTS) crypto/tea crypto/xtea crypto/xxtea + encode/base endian exe extent @@ -542,8 +553,9 @@ if (TESTS) string stringid strongdef - tuple + time/8601 traits + tuple typeidx uri utf8 @@ -556,6 +568,7 @@ if (TESTS) string(REPLACE "/" "_" name "test/${t}") add_executable(util_${name} test/${t}.cpp) target_link_libraries(util_${name} PRIVATE cruft-util) + target_include_directories(util_${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_test(NAME util_${name} COMMAND util_${name}) endforeach(t) endif () diff --git a/abnf.rl b/abnf.rl new file mode 100644 index 00000000..86903cdc --- /dev/null +++ b/abnf.rl @@ -0,0 +1,67 @@ +void foo (void) { } + +%%{ + +machine rfc5234; + +############################################################################### +# RFC5234 ABNF core rules + +# ; A-Z / a-z +ALPHA = 0x41..0x5A | 0x61..0x7A; +BIT = '0' | '1'; + +# any 7-bit US-ASCII character, excluding NUL +CHAR = 0x01..0x7F; + +# carriage return +CR = 0x0D; + +# linefeed +LF = 0x0A; + +# Internet standard newline +CRLF = CR LF; + +# controls +CTL = 0x00..0x1F | 0x7F; + +# 0-9 +DIGIT = 0x30..0x39; + +# " (Double Quote) +DQUOTE = 0x22; + +HEXDIG = DIGIT | 'A'..'F'; + +# horizontal tab +HTAB = 0x09; + +SP = 0x20; + +# white space +WSP = SP | HTAB; + +# Use of this linear-white-space rule permits lines containing only white space +# that are no longer legal in mail headers and have caused interoperability +# problems in other contexts. +# +# Do not use when defining mail headers and use with caution in other contexts. +LWSP = (WSP | CRLF WSP)*; + +# 8 bits of data +OCTET = any; #0x00..0xFF; + +# visible (printing) characters +VCHAR = 0x21..0x7E; + + write data; + +}%% + +int main () { + + + %%write init; + %%write exec; +} diff --git a/algo/sort.hpp b/algo/sort.hpp index 008a40c1..09c07037 100644 --- a/algo/sort.hpp +++ b/algo/sort.hpp @@ -44,6 +44,6 @@ namespace cruft::util::sort { soa (RandomIt key_first, RandomIt key_last, Comparator comp, Args ...values); } -#include "./sort.ipp" +#include "sort.ipp" #endif diff --git a/alloc/allocator.cpp b/alloc/allocator.cpp index 0747499b..6b898bc5 100644 --- a/alloc/allocator.cpp +++ b/alloc/allocator.cpp @@ -1 +1 @@ -#include "./allocator.hpp" +#include "allocator.hpp" diff --git a/alloc/allocator.hpp b/alloc/allocator.hpp index cca7cfc6..1b4babc0 100644 --- a/alloc/allocator.hpp +++ b/alloc/allocator.hpp @@ -38,6 +38,6 @@ namespace util::alloc { }; } -#include "./allocator.ipp" +#include "allocator.ipp" #endif diff --git a/alloc/arena.cpp b/alloc/arena.cpp index ca065a58..a29f7c79 100644 --- a/alloc/arena.cpp +++ b/alloc/arena.cpp @@ -1 +1 @@ -#include "./arena.hpp" +#include "arena.hpp" diff --git a/alloc/arena.hpp b/alloc/arena.hpp index 16be21dd..f9ca676a 100644 --- a/alloc/arena.hpp +++ b/alloc/arena.hpp @@ -68,6 +68,6 @@ namespace util::alloc { }; } -#include "./arena.ipp" +#include "arena.ipp" #endif diff --git a/alloc/raw/affix.cpp b/alloc/raw/affix.cpp index 7f5f681a..b9159357 100644 --- a/alloc/raw/affix.cpp +++ b/alloc/raw/affix.cpp @@ -14,7 +14,7 @@ * Copyright 2015 Danny Robson */ -#include "./affix.hpp" +#include "affix.hpp" using util::alloc::raw::affix; diff --git a/alloc/raw/linear.cpp b/alloc/raw/linear.cpp index 30501b0d..801aa9fb 100644 --- a/alloc/raw/linear.cpp +++ b/alloc/raw/linear.cpp @@ -14,7 +14,7 @@ * Copyright 2015 Danny Robson */ -#include "./linear.hpp" +#include "linear.hpp" #include "../../pointer.hpp" #include "../../debug.hpp" diff --git a/alloc/raw/malloc.cpp b/alloc/raw/malloc.cpp index 4901c92a..86eb5238 100644 --- a/alloc/raw/malloc.cpp +++ b/alloc/raw/malloc.cpp @@ -14,7 +14,7 @@ * Copyright 2015 Danny Robson */ -#include "./malloc.hpp" +#include "malloc.hpp" #include "../../debug.hpp" diff --git a/alloc/raw/null.cpp b/alloc/raw/null.cpp index c885f6e9..cc3ce234 100644 --- a/alloc/raw/null.cpp +++ b/alloc/raw/null.cpp @@ -15,7 +15,7 @@ */ -#include "./null.hpp" +#include "null.hpp" #include "../../debug.hpp" diff --git a/alloc/raw/stack.cpp b/alloc/raw/stack.cpp index 1f297e2c..d525c906 100644 --- a/alloc/raw/stack.cpp +++ b/alloc/raw/stack.cpp @@ -14,7 +14,7 @@ * Copyright 2015-2016 Danny Robson */ -#include "./stack.hpp" +#include "stack.hpp" #include "../../debug.hpp" #include "../../pointer.hpp" diff --git a/ascii.hpp b/ascii.hpp index 5f13b77f..50b75a57 100644 --- a/ascii.hpp +++ b/ascii.hpp @@ -17,7 +17,7 @@ #ifndef __CRUFT_UTIL_ASCII_HPP #define __CRUFT_UTIL_ASCII_HPP -#include "./annotation.hpp" +#include "annotation.hpp" #include #include @@ -77,7 +77,7 @@ namespace util::ascii { //------------------------------------------------------------------------- constexpr inline - unsigned + uint8_t from_hex (char c) { return c >= '0' && c <= '9' ? (c - '0' ) : diff --git a/backtrace_execinfo.cpp b/backtrace_execinfo.cpp index 40176d78..c7d4b2f8 100644 --- a/backtrace_execinfo.cpp +++ b/backtrace_execinfo.cpp @@ -17,10 +17,10 @@ #include "backtrace.hpp" -#include "./debug.hpp" -#include "./exe.hpp" -#include "./io.hpp" -#include "./cast.hpp" +#include "debug.hpp" +#include "exe.hpp" +#include "io.hpp" +#include "cast.hpp" #include #include diff --git a/backtrace_stackwalk.cpp b/backtrace_stackwalk.cpp index d744877e..a1535d0f 100644 --- a/backtrace_stackwalk.cpp +++ b/backtrace_stackwalk.cpp @@ -14,11 +14,12 @@ * Copyright 2016 Danny Robson */ -#include "./backtrace.hpp" +#include "backtrace.hpp" -#include "./debug.hpp" -#include "./except.hpp" -#include "./types.hpp" +#include "debug.hpp" +#include "except.hpp" +#include "types.hpp" +#include "win32/error.hpp" #include #include @@ -66,7 +67,7 @@ backtrace::backtrace () SymGetModuleBase64, nullptr)) { - util::win32_error::throw_code (); + util::win32::error::throw_code (); } // we've read the bottom of the stack diff --git a/backtrace_win32.cpp b/backtrace_win32.cpp index ae5470a0..5ed8aee8 100644 --- a/backtrace_win32.cpp +++ b/backtrace_win32.cpp @@ -15,11 +15,12 @@ * 2012-2016, Danny Robson */ -#include "./backtrace.hpp" +#include "backtrace.hpp" -#include "./win32/handle.hpp" -#include "./debug.hpp" -#include "./except.hpp" +#include "win32/error.hpp" +#include "win32/handle.hpp" +#include "debug.hpp" +#include "except.hpp" #include #include @@ -33,7 +34,7 @@ debug::backtrace::backtrace (void) auto process = GetCurrentProcess(); if (!SymInitialize (process, NULL, TRUE)) - util::win32_error::throw_code (); + util::win32::error::throw_code (); while (true) { auto res = CaptureStackBackTrace (1, m_frames.size (), m_frames.data (), NULL); diff --git a/bezier.cpp b/bezier.cpp index 0966a416..b02319ea 100644 --- a/bezier.cpp +++ b/bezier.cpp @@ -14,12 +14,12 @@ * Copyright 2015-2016 Danny Robson */ -#include "./bezier.hpp" +#include "bezier.hpp" -#include "./debug.hpp" -#include "./polynomial.hpp" -#include "./stream.hpp" -#include "./coord/iostream.hpp" +#include "debug.hpp" +#include "polynomial.hpp" +#include "stream.hpp" +#include "coord/iostream.hpp" #include #include diff --git a/bezier1.cpp b/bezier1.cpp index b645fbd4..97c280ea 100644 --- a/bezier1.cpp +++ b/bezier1.cpp @@ -14,7 +14,7 @@ * Copyright 2015-2016 Danny Robson */ -#include "./bezier.hpp" +#include "bezier.hpp" #include #include diff --git a/bezier2.cpp b/bezier2.cpp index cb252207..9e6619a2 100644 --- a/bezier2.cpp +++ b/bezier2.cpp @@ -14,10 +14,10 @@ * Copyright 2015-2016 Danny Robson */ -#include "./bezier.hpp" +#include "bezier.hpp" -#include "./polynomial.hpp" -#include "./coord/iostream.hpp" +#include "polynomial.hpp" +#include "coord/iostream.hpp" /////////////////////////////////////////////////////////////////////////////// diff --git a/bezier3.cpp b/bezier3.cpp index f34c7452..d9262b82 100644 --- a/bezier3.cpp +++ b/bezier3.cpp @@ -14,7 +14,7 @@ * Copyright 2015-2016 Danny Robson */ -#include "./bezier.hpp" +#include "bezier.hpp" #include "coord/iostream.hpp" @@ -30,10 +30,10 @@ namespace util { CHECK_GE (t, 0); CHECK_LE (t, 1); - auto v0 = pow (1 - t, 3) * m_points[0]; + auto v0 = pow (1 - t, 3u) * m_points[0]; auto v1 = 3 * pow2 (1 - t) * t * m_points[1]; auto v2 = 3 * pow2 (1 - t) * t * m_points[2]; - auto v3 = pow (t, 3) * m_points[3]; + auto v3 = pow (t, 3u) * m_points[3]; return { v0.x + v1.x + v2.x + v3.x, diff --git a/cast.hpp b/cast.hpp index 6afc863b..f477c936 100644 --- a/cast.hpp +++ b/cast.hpp @@ -17,7 +17,7 @@ #ifndef __UTIL_CAST_HPP #define __UTIL_CAST_HPP -#include "./debug.hpp" +#include "debug.hpp" #include #include diff --git a/cmdopt.cpp b/cmdopt.cpp index 451e5739..402d8baf 100644 --- a/cmdopt.cpp +++ b/cmdopt.cpp @@ -14,10 +14,10 @@ * Copyright 2013-2016 Danny Robson */ -#include "./cmdopt.hpp" +#include "cmdopt.hpp" -#include "./cast.hpp" -#include "./debug.hpp" +#include "cast.hpp" +#include "debug.hpp" #include #include @@ -192,27 +192,27 @@ suffix_to_multiplier (char c) switch (c) { case 'e': case 'E': - return util::pow (1024UL, 6); + return util::pow (1024UL, 6u); case 'p': case 'P': - return util::pow (1024UL, 5); + return util::pow (1024UL, 5u); case 't': case 'T': - return util::pow (1024UL, 4); + return util::pow (1024UL, 4u); case 'g': case 'G': - return util::pow (1024UL, 3); + return util::pow (1024UL, 3u); case 'm': case 'M': - return util::pow (1024UL, 2); + return util::pow (1024UL, 2u); case 'k': case 'K': - return util::pow (1024UL, 1); + return util::pow (1024UL, 1u); default: const char str[2] = { c, '\0' }; diff --git a/cmdopt.ipp b/cmdopt.ipp index 047c397a..4153b850 100644 --- a/cmdopt.ipp +++ b/cmdopt.ipp @@ -23,8 +23,8 @@ #include #include -#include "./introspection.hpp" -#include "./iterator.hpp" +#include "introspection.hpp" +#include "iterator.hpp" namespace util::cmdopt { /////////////////////////////////////////////////////////////////////////// diff --git a/colour.cpp b/colour.cpp index f8a0fd7c..84f31749 100644 --- a/colour.cpp +++ b/colour.cpp @@ -14,454 +14,45 @@ * Copyright 2010-2017 Danny Robson */ -#include "./colour.hpp" +#include "colour.hpp" -#include "./ascii.hpp" -#include "./debug.hpp" -#include "./log.hpp" -#include "./range.hpp" - -#include -#include - -/////////////////////////////////////////////////////////////////////////////// -using util::colour; -using util::colour3f; -using util::colour4f; +#include "ascii.hpp" +#include "parse.hpp" /////////////////////////////////////////////////////////////////////////////// -template -colour -colour::parse_html (const char *fmt) +static util::srgba4f +parse_hex (util::view str) { - // ensure the format is the correct length - auto len = strlen (fmt); + if (str.size () != strlen ("#012345")) + throw std::invalid_argument ("expected length of 7"); - switch (len) { - case 1 + 2 * S: - if (*fmt != '#') - throw std::invalid_argument ("missing leading hash"); - ++fmt; - break; + if (str[0] != '#') + throw std::invalid_argument ("expected leading '#'"); - case 2 * S: - break; - - default: - throw std::invalid_argument ("format is the wrong length"); + if (!util::ascii::is_hex (str[1]) || + !util::ascii::is_hex (str[2]) || + !util::ascii::is_hex (str[3]) || + !util::ascii::is_hex (str[4]) || + !util::ascii::is_hex (str[5]) || + !util::ascii::is_hex (str[6])) + { + throw std::invalid_argument ("expected hex digits"); } - // parse the octets - util::colour res; - for (size_t i = 0; i < res.size (); ++i) { - auto a = util::ascii::from_hex (fmt[i*2+0]); - auto b = util::ascii::from_hex (fmt[i*2+1]); + uint8_t r = util::ascii::from_hex (str[1]) << 4u | util::ascii::from_hex (str[2]); + uint8_t g = util::ascii::from_hex (str[3]) << 4u | util::ascii::from_hex (str[4]); + uint8_t b = util::ascii::from_hex (str[5]) << 4u | util::ascii::from_hex (str[6]); - res[i] = (a << 4u) | b; - } - - return res.template cast (); + return util::srgba<4,uint8_t> { r, g, b, 255 }.template cast (); } + /////////////////////////////////////////////////////////////////////////////// -static const std::map> -HTML_COLOURS { { - { "white", { 0xff, 0xff, 0xff, 0xff } }, - { "silver", { 0xc0, 0xc0, 0xc0, 0xff } }, - { "gray", { 0x80, 0x80, 0x80, 0xff } }, - { "black", { 0x00, 0x00, 0x00, 0xff } }, - { "red", { 0xff, 0x00, 0x00, 0xff } }, - { "maroon", { 0x80, 0x00, 0x00, 0xff } }, - { "yellow", { 0xff, 0xff, 0x00, 0xff } }, - { "olive", { 0x80, 0x80, 0x00, 0xff } }, - { "lime", { 0x00, 0xff, 0x00, 0xff } }, - { "green", { 0x00, 0x80, 0x00, 0xff } }, - { "aqua", { 0x00, 0xff, 0xff, 0xff } }, - { "teal", { 0x00, 0x80, 0x80, 0xff } }, - { "blue", { 0x00, 0x00, 0xff, 0xff } }, - { "navy", { 0x00, 0x00, 0x80, 0xff } }, - { "fuchsia", { 0xff, 0x00, 0xff, 0xff } }, - { "purple", { 0x80, 0x00, 0x80, 0xff } }, -} }; - - -//----------------------------------------------------------------------------- -static const std::map> X11_COLOURS +template <> +util::srgba4f +util::parse (util::view str) { - /* pink */ - { "pink", { 0xff, 0xc0, 0xcb, 0xff } }, - { "lightpink", { 0xff, 0xb6, 0xc1, 0xff } }, - { "hotpink", { 0xff, 0x69, 0xb4, 0xff } }, - { "deeppink", { 0xff, 0x14, 0x93, 0xff } }, - { "palevioletred", { 0xdb, 0x70, 0x93, 0xff } }, - { "mediumvioletred", { 0xc7, 0x15, 0x85, 0xff } }, - - /* red */ - { "lightsalmon", { 0xff, 0xa0, 0x7a, 0xff } }, - { "salmon", { 0xfa, 0x80, 0x72, 0xff } }, - { "darksalmon", { 0xe9, 0x96, 0x7a, 0xff } }, - { "lightcoral", { 0xf0, 0x80, 0x80, 0xff } }, - { "indianred", { 0xcd, 0x5c, 0x5c, 0xff } }, - { "crimson", { 0xdc, 0x14, 0x3c, 0xff } }, - { "firebrick", { 0xb2, 0x22, 0x22, 0xff } }, - { "darkred", { 0x8b, 0x00, 0x00, 0xff } }, - { "red", { 0xff, 0x00, 0x00, 0xff } }, - - /* orange */ - { "orangered", { 0xff, 0x45, 0x00, 0xff } }, - { "tomato", { 0xff, 0x63, 0x47, 0xff } }, - { "coral", { 0xff, 0x7f, 0x50, 0xff } }, - { "darkorange", { 0xff, 0x8c, 0x00, 0xff } }, - { "orange", { 0xff, 0xa5, 0x00, 0xff } }, - - /* yellow */ - { "yellow", { 0xff, 0xff, 0x00, 0xff } }, - { "lightyellow", { 0xff, 0xff, 0xe0, 0xff } }, - { "lemonchiffon", { 0xff, 0xfa, 0xcd, 0xff } }, - { "lightgoldenrodyellow", { 0xfa, 0xfa, 0xd2, 0xff } }, - { "papayawhip", { 0xff, 0xef, 0xd5, 0xff } }, - { "moccasin", { 0xff, 0xe4, 0xb5, 0xff } }, - { "peachpuff", { 0xff, 0xda, 0xb9, 0xff } }, - { "palegoldenrod", { 0xee, 0xe8, 0xaa, 0xff } }, - { "khaki", { 0xf0, 0xe6, 0x8c, 0xff } }, - { "darkkhaki", { 0xbd, 0xb7, 0x6b, 0xff } }, - { "gold", { 0xff, 0xd7, 0x00, 0xff } }, - - /* brown */ - { "cornsilk", { 0xff, 0xf8, 0xdc, 0xff } }, - { "blanchedalmond", { 0xff, 0xeb, 0xcd, 0xff } }, - { "bisque", { 0xff, 0xe4, 0xc4, 0xff } }, - { "navajowhite", { 0xff, 0xde, 0xad, 0xff } }, - { "wheat", { 0xf5, 0xde, 0xb3, 0xff } }, - { "burlywood", { 0xde, 0xb8, 0x87, 0xff } }, - { "tan", { 0xd2, 0xb4, 0x8c, 0xff } }, - { "rosybrown", { 0xbc, 0x8f, 0x8f, 0xff } }, - { "sandybrown", { 0xf4, 0xa4, 0x60, 0xff } }, - { "goldenrod", { 0xda, 0xa5, 0x20, 0xff } }, - { "darkgoldenrod", { 0xb8, 0x86, 0x0b, 0xff } }, - { "peru", { 0xcd, 0x85, 0x3f, 0xff } }, - { "chocolate", { 0xd2, 0x69, 0x1e, 0xff } }, - { "saddlebrown", { 0x8b, 0x45, 0x13, 0xff } }, - { "sienna", { 0xa0, 0x52, 0x2d, 0xff } }, - { "brown", { 0xa5, 0x2a, 0x2a, 0xff } }, - { "maroon", { 0x80, 0x00, 0x00, 0xff } }, - - /* green */ - { "darkolivegreen", { 0x55, 0x6b, 0x2f, 0xff } }, - { "olive", { 0x80, 0x80, 0x00, 0xff } }, - { "olivedrab", { 0x6b, 0x8e, 0x23, 0xff } }, - { "yellowgreen", { 0x9a, 0xcd, 0x32, 0xff } }, - { "limegreen", { 0x32, 0xcd, 0x32, 0xff } }, - { "lime", { 0x00, 0xff, 0x00, 0xff } }, - { "lawngreen", { 0x7c, 0xfc, 0x00, 0xff } }, - { "chartreuse", { 0x7f, 0xff, 0x00, 0xff } }, - { "greenyellow", { 0xad, 0xff, 0x2f, 0xff } }, - { "springgreen", { 0x00, 0xff, 0x7f, 0xff } }, - { "mediumspringgreen", { 0x00, 0xfa, 0x9a, 0xff } }, - { "lightgreen", { 0x90, 0xee, 0x90, 0xff } }, - { "palegreen", { 0x98, 0xfb, 0x98, 0xff } }, - { "darkseagreen", { 0x8f, 0xbc, 0x8f, 0xff } }, - { "mediumseagreen", { 0x3c, 0xb3, 0x71, 0xff } }, - { "seagreen", { 0x2e, 0x8b, 0x57, 0xff } }, - { "forestgreen", { 0x22, 0x8b, 0x22, 0xff } }, - { "green", { 0x00, 0x80, 0x00, 0xff } }, - { "darkgreen", { 0x00, 0x64, 0x00, 0xff } }, - - /* cyan */ - { "mediumaquamarine", { 0x66, 0xcd, 0xaa, 0xff } }, - { "aqua", { 0x00, 0xff, 0xff, 0xff } }, - { "cyan", { 0x00, 0xff, 0xff, 0xff } }, - { "lightcyan", { 0xe0, 0xff, 0xff, 0xff } }, - { "paleturquoise", { 0xaf, 0xee, 0xee, 0xff } }, - { "aquamarine", { 0x7f, 0xff, 0xd4, 0xff } }, - { "turquoise", { 0x40, 0xe0, 0xd0, 0xff } }, - { "mediumturquoise", { 0x48, 0xd1, 0xcc, 0xff } }, - { "darkturquoise", { 0x00, 0xce, 0xd1, 0xff } }, - { "lightseagreen", { 0x20, 0xb2, 0xaa, 0xff } }, - { "cadetblue", { 0x5f, 0x9e, 0xa0, 0xff } }, - { "darkcyan", { 0x00, 0x8b, 0x8b, 0xff } }, - { "teal", { 0x00, 0x80, 0x80, 0xff } }, - - /* blue */ - { "lightsteelblue", { 0xb0, 0xc4, 0xde, 0xff } }, - { "powderblue", { 0xb0, 0xe0, 0xe6, 0xff } }, - { "lightblue", { 0xad, 0xd8, 0xe6, 0xff } }, - { "skyblue", { 0x87, 0xce, 0xeb, 0xff } }, - { "lightskyblue", { 0x87, 0xce, 0xfa, 0xff } }, - { "deepskyblue", { 0x00, 0xbf, 0xff, 0xff } }, - { "dodgerblue", { 0x1e, 0x90, 0xff, 0xff } }, - { "cornflowerblue", { 0x64, 0x95, 0xed, 0xff } }, - { "steelblue", { 0x46, 0x82, 0xb4, 0xff } }, - { "royalblue", { 0x41, 0x69, 0xe1, 0xff } }, - { "blue", { 0x00, 0x00, 0xff, 0xff } }, - { "mediumblue", { 0x00, 0x00, 0xcd, 0xff } }, - { "darkblue", { 0x00, 0x00, 0x8b, 0xff } }, - { "navy", { 0x00, 0x00, 0x80, 0xff } }, - { "midnightblue", { 0x19, 0x19, 0x70, 0xff } }, - - /* purple */ - { "lavender", { 0xe6, 0xe6, 0xfa, 0xff } }, - { "thistle", { 0xd8, 0xbf, 0xd8, 0xff } }, - { "plum", { 0xdd, 0xa0, 0xdd, 0xff } }, - { "violet", { 0xee, 0x82, 0xee, 0xff } }, - { "orchid", { 0xda, 0x70, 0xd6, 0xff } }, - { "fuchsia", { 0xff, 0x00, 0xff, 0xff } }, - { "magenta", { 0xff, 0x00, 0xff, 0xff } }, - { "mediumorchid", { 0xba, 0x55, 0xd3, 0xff } }, - { "mediumpurple", { 0x93, 0x70, 0xdb, 0xff } }, - { "blueviolet", { 0x8a, 0x2b, 0xe2, 0xff } }, - { "darkviolet", { 0x94, 0x00, 0xd3, 0xff } }, - { "darkorchid", { 0x99, 0x32, 0xcc, 0xff } }, - { "darkmagenta", { 0x8b, 0x00, 0x8b, 0xff } }, - { "purple", { 0x80, 0x00, 0x80, 0xff } }, - { "indigo", { 0x4b, 0x00, 0x82, 0xff } }, - { "darkslateblue", { 0x48, 0x3d, 0x8b, 0xff } }, - { "rebeccapurple", { 0x66, 0x33, 0x99, 0xff } }, - { "slateblue", { 0x6a, 0x5a, 0xcd, 0xff } }, - { "mediumslateblue", { 0x7b, 0x68, 0xee, 0xff } }, - - /* white */ - { "white", { 0xff, 0xff, 0xff, 0xff } }, - { "snow", { 0xff, 0xfa, 0xfa, 0xff } }, - { "honeydew", { 0xf0, 0xff, 0xf0, 0xff } }, - { "mintcream", { 0xf5, 0xff, 0xfa, 0xff } }, - { "azure", { 0xf0, 0xff, 0xff, 0xff } }, - { "aliceblue", { 0xf0, 0xf8, 0xff, 0xff } }, - { "ghostwhite", { 0xf8, 0xf8, 0xff, 0xff } }, - { "whitesmoke", { 0xf5, 0xf5, 0xf5, 0xff } }, - { "seashell", { 0xff, 0xf5, 0xee, 0xff } }, - { "beige", { 0xf5, 0xf5, 0xdc, 0xff } }, - { "oldlace", { 0xfd, 0xf5, 0xe6, 0xff } }, - { "floralwhite", { 0xff, 0xfa, 0xf0, 0xff } }, - { "ivory", { 0xff, 0xff, 0xf0, 0xff } }, - { "antiquewhite", { 0xfa, 0xeb, 0xd7, 0xff } }, - { "linen", { 0xfa, 0xf0, 0xe6, 0xff } }, - { "lavenderblush", { 0xff, 0xf0, 0xf5, 0xff } }, - { "mistyrose", { 0xff, 0xe4, 0xe1, 0xff } }, - - /* grey/black */ - { "gainsboro", { 0xdc, 0xdc, 0xdc, 0xff } }, - { "lightgrey", { 0xd3, 0xd3, 0xd3, 0xff } }, - { "silver", { 0xc0, 0xc0, 0xc0, 0xff } }, - { "darkgray", { 0xa9, 0xa9, 0xa9, 0xff } }, - { "gray", { 0x80, 0x80, 0x80, 0xff } }, - { "dimgray", { 0x69, 0x69, 0x69, 0xff } }, - { "lightslategray", { 0x77, 0x88, 0x99, 0xff } }, - { "slategray", { 0x70, 0x80, 0x90, 0xff } }, - { "darkslategray", { 0x2f, 0x4f, 0x4f, 0xff } }, - { "black", { 0x00, 0x00, 0x00, 0xff } }, -}; - - -//----------------------------------------------------------------------------- -template -static colour -lookup_colour (const std::string &name, - const std::map> &map) -{ - std::string lower (name); - std::transform (lower.begin (), lower.end (), lower.begin (), tolower); - - auto pos = map.find (lower); - if (pos == map.end ()) - throw std::out_of_range (name); - - static_assert (S <= 4, "cannot invent additional data"); - return pos->second.template redim ().template cast (); -} - - -//----------------------------------------------------------------------------- -template -colour -colour::from_html (const std::string &name) -{ - return lookup_colour (name, HTML_COLOURS); -} - - -//----------------------------------------------------------------------------- -template -colour -colour::from_x11 (const std::string &name) -{ - return lookup_colour (name, X11_COLOURS); -} - - -/////////////////////////////////////////////////////////////////////////////// -colour3f -util::rgb_to_hsv (colour3f rgb) -{ - // Calculate chroma - auto M = max (rgb); - auto m = min (rgb); - auto C = M - m; - - // Undefined for zero chroma - if (almost_zero (C)) - return { -1.f, 0.f, M }; - - // Calculate hue - float H = exactly_equal (rgb.r, M) ? (rgb.g - rgb.b) : - exactly_equal (rgb.g, M) ? 2 + (rgb.b - rgb.r) : - exactly_equal (rgb.b, M) ? 4 + (rgb.r - rgb.g) : - 0 ; - - H /= C; - H *= 60; - - if (H < 0) - H += 360; - - // Calculate value - auto V = M; - - // Calculate saturation - auto S = almost_zero (V) ? 0.f : C / V; - - return { H, S, V }; -} - - -//----------------------------------------------------------------------------- -colour3f -util::hsv_to_rgb (colour3f hsv) -{ - CHECK_GE (hsv.h, 0); - CHECK_LT (hsv.h, 360); - CHECK_GE (hsv.s, 0); - CHECK_LE (hsv.s, 1); - CHECK_GE (hsv.v, 0); - CHECK_LE (hsv.v, 1); - - float C = hsv.v * hsv.s; - float H = hsv.h / 60; - float X = C * (1 - std::abs (std::fmod (H, 2.f) - 1)); - - // monochromatic'ish - if (almost_zero (hsv.s)) - return colour3f { hsv.v }; - - colour3f rgb; - - unsigned hex = (unsigned)H; - switch (hex) { - case 0: rgb = { C, X, 0 }; break; - case 1: rgb = { X, C, 0 }; break; - case 2: rgb = { 0, C, X }; break; - case 3: rgb = { 0, X, C }; break; - case 4: rgb = { X, 0, C }; break; - case 5: rgb = { C, 0, X }; break; - } - - auto m = hsv.v - C; - - return rgb + m; -} - - -///---------------------------------------------------------------------------- -/// Extract a colour object from a JSON node. -#include "json/tree.hpp" - -namespace json::tree { - template <> - util::colour4f - io::deserialise (const node &root) { - return { - root[0].as (), - root[1].as (), - root[2].as (), - root[3].as (), - }; - } -} - - -/////////////////////////////////////////////////////////////////////////////// -template -std::ostream& -util::operator<< (std::ostream &os, util::colour c) -{ - return os << "[ " << util::make_infix (util::numeric_view (c), ", ") << ']'; -} - - -//----------------------------------------------------------------------------- -template -std::istream& -util::operator>> (std::istream &is, util::colour &c) -{ - std::array< - std::conditional_t< - sizeof(T) == 1, - uint16_t, - T - >,S - > v; - - static_assert (S > 0, "current implementation requires strictly positive components"); - char comma; - - for (size_t i = 0; i < S - 1; ++i) { - is >> v[i] >> comma; - - if (comma != ',' || is.eof ()) { - is.setstate (std::ios_base::failbit); - return is; - } - } - - is >> v[S-1]; - - if (!std::is_same::value) { - if (std::any_of (std::cbegin (v), - std::cend (v), - [] (auto i) { - return i > std::numeric_limits::max (); - })) { - is.setstate (std::ios_base::failbit); - return is; - } - } - - std::copy (std::cbegin (v), - std::cend (v), - std::begin (c)); - - return is; -} - -//----------------------------------------------------------------------------- -template std::istream& util::operator>> (std::istream&, util::colour<3,uint8_t>&); - - -/////////////////////////////////////////////////////////////////////////////// -#define INSTANTIATE_S_T(S,T) \ -template \ -struct util::colour; \ - \ -template \ -std::ostream& \ -util::operator<< (std::ostream&, util::colour); \ - \ -template \ -const char* \ -util::to_string> (void); - - -//----------------------------------------------------------------------------- -#define INSTANTIATE_S(S) \ -INSTANTIATE_S_T(S,uint8_t) \ -INSTANTIATE_S_T(S,uint16_t) \ -INSTANTIATE_S_T(S,float) \ -INSTANTIATE_S_T(S,double) - - -//----------------------------------------------------------------------------- -INSTANTIATE_S(1) -INSTANTIATE_S(3) -INSTANTIATE_S(4) + return parse_hex (str); +} \ No newline at end of file diff --git a/colour.hpp b/colour.hpp index 7bed5b15..3c7273eb 100644 --- a/colour.hpp +++ b/colour.hpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2010-2015 Danny Robson + * Copyright 2010-2017 Danny Robson */ #ifndef __UTIL_COLOUR_HPP @@ -21,68 +21,98 @@ #include "introspection.hpp" #include +#include + namespace util { - /// An RGBA colour POD type. - template - struct colour : public coord::base { - using coord::base::base; - using base_t = coord::base; + /// An abstract colour POD type componsed of S components of type T. + /// + /// Not to be used directly, instead the use of derived types is required. + /// This exists purely to simplify generic colour code. + template < + size_t S, + typename T, + typename SelfT + > + struct colour : coord::base { + using coord::base::base; - // overloaded cast operator which assumes values are unit normalised template - colour - cast (void) const; - - /// parse colours specified as "#AABBCCDD". - /// - /// * the leading hash is optional. - /// * all components must be 2 hex digits. - static colour parse_html (const char*); - static colour parse_html (const std::string&); - - /// look up the name of a colour from those specified in - /// html/x11/etc specifications. - static colour from_html (const std::string &name); - static colour from_x11 (const std::string &name); - - /// look up all the specifications and returns the colour from one - /// that matches. the search order is unspecified, so if you want a - /// known colour then try them first yourself. - static colour from_string (const std::string &name); + auto + cast (void) const + { + ::util::revalue_t ret; + std::transform (std::begin (*this), + std::end (*this), + std::begin (ret), + renormalise); + return ret; + } }; - // Convenience types - template using colour1 = colour<1,T>; - template using colour3 = colour<3,T>; - template using colour4 = colour<4,T>; - - typedef colour1 colour1u; - typedef colour3 colour3u; - typedef colour4 colour4u; - - typedef colour1 colour1f; - typedef colour3 colour3f; - typedef colour4 colour4f; - - // RGB/HSV conversions - colour3f rgb_to_hsv (colour3f); - colour3f hsv_to_rgb (colour3f); - - // ostream/istream operators - template - std::ostream& - operator<< (std::ostream&, util::colour); - - template - std::istream& - operator>> (std::istream&, util::colour&); - - // type name introspection specialisation - template - struct type_name> { - static constexpr const char value[] = "colour"; + template + struct util::coord::store<1,T,srgba<1,T>> { + union { struct { T r; }; T data[1]; }; }; + template + struct util::coord::store<2,T,srgba<2,T>> { + union { struct { T r, g; }; T data[2]; }; + }; + template + struct util::coord::store<3,T,srgba<3,T>> { + union { struct { T r, g, b; }; T data[3]; }; + }; + + template + struct util::coord::store<4,T,srgba<4,T>> { + union { struct { T r, g, b, a; }; T data[4]; }; + }; + + template struct srgba : colour> { + using colour>::colour; + }; + + using srgba3f = srgba<3,float>; + using srgba4f = srgba<4,float>; + + using srgba3u = srgba<3,uint8_t>; + using srgba4u = srgba<4,uint8_t>; + + template struct hsva : colour> {}; + + template + struct redim_type< + srgba + > { template using type = srgba<_S,T>; }; + + template + struct revalue_type> { + template + using type = srgba; + }; + + + template struct is_colour : public std::false_type {}; + template < + size_t S, + typename T, + template < + size_t, + typename + > typename ColourT + > struct is_colour> + :std::conditional_t< + std::is_base_of_v< + colour>, + ColourT + >, + std::true_type, + std::false_type + > {}; + + + template + constexpr auto is_colour_v = is_colour::value; } #include "colour.ipp" diff --git a/colour.ipp b/colour.ipp index 37b8f2eb..0f334864 100644 --- a/colour.ipp +++ b/colour.ipp @@ -19,15 +19,3 @@ #endif #define __UTIL_COLOUR_IPP -template -template -util::colour -util::colour::cast (void) const -{ - colour ret; - std::transform (this->begin (), - this->end (), - ret.begin (), - renormalise); - return ret; -} diff --git a/coord/base.hpp b/coord/base.hpp index 2afb74bd..41c370d6 100644 --- a/coord/base.hpp +++ b/coord/base.hpp @@ -17,36 +17,46 @@ #ifndef CRUFT_UTIL_COORD_BASE_HPP #define CRUFT_UTIL_COORD_BASE_HPP -#include "init.hpp" +#include "fwd.hpp" -#include "./ops.hpp" +#include "ops.hpp" +#include "init.hpp" +#include "traits.hpp" #include "../maths.hpp" #include #include #include + namespace util::coord { ///////////////////////////////////////////////////////////////////////// + // the base class for all coordinate-like types. + // + // SelfT should not be exposed as a template template directly because + // some types (eg, XYZ colours) do not conform to the same template + // parameters are others (eg, vector2f). ie, it does not make sense to + // allow redim, or type changing on some types so they just aren't exposed. template < std::size_t S, typename T, - template class KLASS, - typename ...tags + typename SelfT > - struct base : public init { + struct base : public init { static_assert (S > 0); static_assert (std::is_arithmetic::value); + static_assert (sizeof (init) == S * sizeof (T)); + using self_t = SelfT; using value_type = T; static constexpr std::size_t dimension = S; static constexpr std::size_t elements = S; /// returns the number of elements we contain - static constexpr std::size_t size (void) { return S; } + static constexpr auto size (void) { return S; } - // inherit the fancy elementwise constructors from `init'. - using init::init; + // constructors + using init::init; /// constructs, but does not initialise, the data. /// @@ -63,12 +73,21 @@ namespace util::coord { this->data[i] = fill; } - constexpr base (const base &rhs) = default; - base& operator= (const base &rhs) = default; + constexpr base (const base &rhs) = default; + base& operator= (const base &rhs)& = default; + base& operator= (const T t)& + { + for (auto v: *this) + v = t; + return *this; + } // element accessors - T& operator[] (std::size_t i) { return this->data[i]; } - constexpr const T& operator[] (std::size_t i) const { return this->data[i]; } + constexpr T& operator[] (size_t i)& noexcept { return this->data[i]; } + constexpr T& operator[] (int i)& noexcept { return this->data[i]; } + + constexpr const T& operator[] (size_t i) const& noexcept { return this->data[i]; } + constexpr const T& operator[] (int i) const& noexcept { return this->data[i]; } auto cbegin (void) const { return std::cbegin (this->data); } auto cend (void) const { return std::cend (this->data); } @@ -95,12 +114,28 @@ namespace util::coord { return k; } + + //--------------------------------------------------------------------- + template < + typename K, + typename = std::enable_if_t,void> + > + K as (void) const + { + static_assert (K::elements == elements); + K k; + std::copy (begin (), end (), k.begin ()); + return k; + } + + //--------------------------------- template - KLASS + auto cast (void) const { - KLASS out; + typename revalue_type::template type out; + std::copy (std::cbegin (this->data), std::cend (this->data), std::begin (out.data)); @@ -113,14 +148,21 @@ namespace util::coord { /// /// explicitly does not allow a fill parameter given it can't be used /// when reducing dimensions. - template + template < + size_t D, + typename _sfinae = SelfT + > std::enable_if_t< - D <= S, KLASS + has_redim_v<_sfinae>, + redim_t<_sfinae,D> > redim (void) const { - KLASS out; - std::copy_n (cbegin (), D, std::begin (out.data)); + redim_t out; + + std::copy_n (std::cbegin (this->data), + min (S, D), + std::begin (out.data)); return out; } @@ -132,13 +174,14 @@ namespace util::coord { /// /// explicitly requires a fill parameter so that we avoid undefined /// values. - template + template std::enable_if_t< - (D > S), KLASS + has_redim_v<_sfinae>, + redim_t<_sfinae,D> > - redim (const KLASS fill) const + redim (const redim_t<_sfinae,D> fill) const { - KLASS out; + redim_t out; auto next = std::copy (cbegin (), cend (), std::begin (out)); std::copy (std::cbegin (fill) + S, std::cend (fill), next); @@ -151,13 +194,17 @@ namespace util::coord { /// /// explicitly requires a fill parameter so that we avoid undefined /// values. - template + template < + size_t D, + typename _sfinae = SelfT + > std::enable_if_t< - (D > S), KLASS + has_redim_v<_sfinae>, + redim_t<_sfinae,D> > redim (T fill) const { - KLASS out; + redim_t out; auto next = std::copy (cbegin (), cend (), std::begin (out)); std::fill (next, std::end (out), fill); @@ -172,7 +219,7 @@ namespace util::coord { /// it's ugly as sin, but simplifies some situations where we don't /// want a temporary. template - KLASS + constexpr auto indices (void) const { static_assert ( @@ -180,11 +227,11 @@ namespace util::coord { "indices must fall within the defined range for the type" ); - return KLASS { this->data[Indices]... }; + return redim_t { + this->data[Indices]... + }; } }; } -#include "../vector.hpp" - #endif diff --git a/coord/fwd.hpp b/coord/fwd.hpp index 3aecbc39..af80ae0f 100644 --- a/coord/fwd.hpp +++ b/coord/fwd.hpp @@ -20,10 +20,17 @@ #include namespace util { - template struct colour; - template struct extent; - template struct point; - template struct vector; + namespace coord { + template struct store; + template struct init; + template struct base; + } + + template struct srgba; + template struct hsva; + template struct extent; + template struct point; + template struct vector; } #endif diff --git a/coord/init.hpp b/coord/init.hpp index 68d5555f..04aa12a6 100644 --- a/coord/init.hpp +++ b/coord/init.hpp @@ -22,53 +22,53 @@ #include namespace util::coord { - template + template struct init; //------------------------------------------------------------------------- - template - struct init<1,T,tags...> : public store<1,T,tags...> + template + struct init<1,T,SelfT> : public store<1,T,SelfT> { - using store<1,T,tags...>::store; + using store<1,T,SelfT>::store; constexpr init () = default; - constexpr explicit init (T v0): - store<1,T,tags...> ({v0}) + constexpr init (T v0): + store<1,T,SelfT> ({v0}) { ; } }; //------------------------------------------------------------------------- - template - struct init<2,T,tags...> : public store<2,T,tags...> + template + struct init<2,T,SelfT> : public store<2,T,SelfT> { - using store<2,T,tags...>::store; + using store<2,T,SelfT>::store; constexpr init () = default; constexpr init (T v0, T v1): - store<2,T,tags...> ({ v0, v1 }) + store<2,T,SelfT> ({ v0, v1 }) { ; } }; //------------------------------------------------------------------------- - template - struct init<3,T,tags...> : public store<3,T,tags...> + template + struct init<3,T,SelfT> : public store<3,T,SelfT> { - using store<3,T,tags...>::store; + using store<3,T,SelfT>::store; constexpr init () = default; constexpr init (T v0, T v1, T v2): - store<3,T,tags...> ({v0, v1, v2}) + store<3,T,SelfT> ({v0, v1, v2}) { ; } }; //------------------------------------------------------------------------- - template - struct init<4,T,tags...> : public store<4,T,tags...> + template + struct init<4,T,SelfT> : public store<4,T,SelfT> { - using store<4,T,tags...>::store; + using store<4,T,SelfT>::store; constexpr init () = default; constexpr init (T v0, T v1, T v2, T v3): - store<4,T,tags...> ({ v0, v1, v2, v3 }) + store<4,T,SelfT> ({ v0, v1, v2, v3 }) { ; } }; } diff --git a/coord/iostream.hpp b/coord/iostream.hpp index 52709f32..d31fa9d4 100644 --- a/coord/iostream.hpp +++ b/coord/iostream.hpp @@ -17,6 +17,7 @@ #ifndef CRUFT_UTIL_IOSTREAM #define CRUFT_UTIL_IOSTREAM +#include "./traits.hpp" #include "../iterator.hpp" #include @@ -25,17 +26,16 @@ namespace util { template < - template class K, - std::size_t S, - typename T + typename K, + typename = std::enable_if_t,void> > std::ostream& - operator<< (std::ostream &os, const K &k) + operator<< (std::ostream &os, const K &k) { os << "["; std::transform (std::cbegin (k), std::cend (k), - infix_iterator (os, ", "), + infix_iterator (os, ", "), [] (auto i) { return +i; }); os << "]"; diff --git a/coord/names.hpp b/coord/names.hpp deleted file mode 100644 index d8c9c294..00000000 --- a/coord/names.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifndef CRUFT_UTIL_COORD_NAMES_HPP -#define CRUFT_UTIL_COORD_NAMES_HPP - -namespace util::coord { - /////////////////////////////////////////////////////////////////////// - // tags for accessor names - // - // colours - struct rgba { }; - struct hsv { }; - - // physical positions - struct xyzw { }; - - // texture coords - struct stpq { }; - - // physical dimensions - struct whd { }; - - // quaternions - struct wxyz { }; - struct abcd { }; -} - -#endif diff --git a/coord/ops.hpp b/coord/ops.hpp index 3b3c6f1b..1fc301d9 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -14,16 +14,19 @@ * Copyright 2012-2017 Danny Robson */ -#ifndef CRUFT_UTIL_COORDS_OPS -#define CRUFT_UTIL_COORDS_OPS +#ifndef __UTIL_COORDS_OPS +#define __UTIL_COORDS_OPS -#include "./fwd.hpp" +#include "fwd.hpp" +#include "traits.hpp" + +// we specifically rely on vector to compute a few logical operations +#include "../vector.hpp" #include "../debug.hpp" #include "../maths.hpp" -#include "../types/bits.hpp" - #include "../preprocessor.hpp" +#include "../types/bits.hpp" #include #include @@ -32,84 +35,46 @@ #include namespace util { - /////////////////////////////////////////////////////////////////////// - // operation traits - namespace coord { - template < - template class A, - template class B - > - struct result { }; - - //------------------------------------------------------------------------- - template <> struct result { template using type = colour; }; - template <> struct result { template using type = extent; }; - template <> struct result { template using type = extent; }; - template <> struct result { template using type = point ; }; - template <> struct result { template using type = point ; }; - template <> struct result { template using type = point ; }; - template <> struct result { template using type = vector; }; - - template < - template class A, - template class B - > - using result_t = typename result::type; - - - //--------------------------------------------------------------------- - template