From f7d6bec5a3b79425dab88043a10efad80e26fcb4 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 9 Apr 2025 16:49:51 +0200 Subject: Add an opinionated C++20 adapter --- cpp/nissy.h | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 cpp/nissy.h (limited to 'cpp/nissy.h') diff --git a/cpp/nissy.h b/cpp/nissy.h new file mode 100644 index 0000000..e336c7a --- /dev/null +++ b/cpp/nissy.h @@ -0,0 +1,133 @@ +/* +C++20 header file for nissy. +*/ + +#ifndef NISSY_H +#define NISSY_H + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace nissy { + /* Some constants for size for I/O buffers */ + namespace size { + constexpr size_t B32 = 22; + constexpr size_t H48 = 88; + constexpr size_t CUBE_MAX = H48; + constexpr size_t TRANSFORMATION = 12; + constexpr size_t SOLVE_STATS = 10; + constexpr size_t DATAID = 255; + } + + /* Some structs definitions for better type safety */ + struct nissflag_t { unsigned value; }; + struct error_t { long long value; }; + struct cube_t { std::string value; }; + struct moves_t { std::string value; }; + struct trans_t { std::string value; }; + struct cube_format_t { std::string value; }; + struct solver_t { std::string value; }; + struct solver_data_t { std::vector value; }; + struct solve_result_t { + std::vector solutions; + std::array stats; + }; + + /* Flags for NISS options */ + namespace nissflag { + constexpr nissflag_t NORMAL{1}; + constexpr nissflag_t INVERSE{2}; + constexpr nissflag_t MIXED{4}; + constexpr nissflag_t LINEAR{NORMAL.value | INVERSE.value}; + constexpr nissflag_t ALL{LINEAR.value | MIXED.value}; + } + + /* Error codes */ + namespace error { + constexpr error_t UNSOLVABLE{-1}; + constexpr error_t INVALID_CUBE{-10}; + constexpr error_t UNSOLVABLE_CUBE{-11}; + constexpr error_t INVALID_MOVES{-20}; + constexpr error_t INVALID_TRANS{-30}; + constexpr error_t INVALID_FORMAT{-40}; + constexpr error_t INVALID_SOLVER{-50}; + constexpr error_t NULL_POINTER{-60}; + constexpr error_t BUFFER_SIZE{-61}; + constexpr error_t DATA{-70}; + constexpr error_t OPTIONS{-80}; + constexpr error_t UNKNOWN{-999}; + } + + /* Cube constants */ + namespace cube { + const cube_t SOLVED{"ABCDEFGH=ABCDEFGHIJKL"}; + } + + std::variant inverse( + const cube_t& cube + ); + + std::variant applymoves( + const cube_t& cube, + const moves_t& moves + ); + + std::variant applytrans( + const cube_t& cube, + const trans_t& trans + ); + + std::variant convert( + const cube_format_t& format_in, + const cube_format_t& format_out, + const std::string& cube_string + ); + + std::variant getcube( + long long ep, + long long eo, + long long cp, + long long co, + const std::string& options + ); + + std::variant, error_t> solverinfo( + const solver_t& solver + ); + + std::variant gendata( + const solver_t& solver + ); + + std::optional checkdata( + const solver_data_t& data + ); + + std::variant solve( + const cube_t& cube, + const solver_t& solver, + nissflag_t niss, + unsigned minmoves, + unsigned maxmoves, + unsigned maxsolutions, + int optimal, + int threads, + const solver_data_t& data + ); + + std::variant countmoves( + const moves_t& moves + ); + + void setlogger( + std::function log + ); +} + +#endif -- cgit v1.3