From 857b0b36c0381a244055a57df67d6ca371ac1b58 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 13 Sep 2022 13:23:47 +0200 Subject: [PATCH] Adjust to compile with gcc Signed-off-by: Simon Rozman --- include/stdex/base64.h | 9 +++--- include/stdex/hex.h | 9 +++--- include/stdex/idrec.h | 31 +++++++++++++-------- include/stdex/sal.h | 54 ++++++++++++++++++++++++++++++++++++ include/stdex/vector_queue.h | 3 ++ 5 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 include/stdex/sal.h diff --git a/include/stdex/base64.h b/include/stdex/base64.h index 562371785..2f9512f7a 100644 --- a/include/stdex/base64.h +++ b/include/stdex/base64.h @@ -5,6 +5,7 @@ #pragma once +#include "sal.h" #include #include @@ -77,11 +78,11 @@ namespace stdex /// /// Returns maximum encoded size /// - /// \param size Number of bytes to encode + /// \param[in] size Number of bytes to encode /// /// \returns Maximum number of bytes for the encoded data of `size` length /// - size_t enc_size(size_t size) const noexcept + size_t enc_size(_In_ size_t size) const noexcept { return ((num + size + 2)/3)*4; } @@ -219,11 +220,11 @@ namespace stdex /// /// Returns maximum decoded size /// - /// \param size Number of bytes to decode + /// \param[in] size Number of bytes to decode /// /// \returns Maximum number of bytes for the decoded data of `size` length /// - size_t dec_size(size_t size) const noexcept + size_t dec_size(_In_ size_t size) const noexcept { return ((num + size + 3)/4)*3; } diff --git a/include/stdex/hex.h b/include/stdex/hex.h index d0840d342..cbcf00719 100644 --- a/include/stdex/hex.h +++ b/include/stdex/hex.h @@ -5,6 +5,7 @@ #pragma once +#include "sal.h" #include #include @@ -56,11 +57,11 @@ namespace stdex /// /// Returns maximum encoded size /// - /// \param size Number of bytes to encode + /// \param[in] size Number of bytes to encode /// /// \returns Maximum number of bytes for the encoded data of `size` length /// - size_t enc_size(size_t size) const noexcept + size_t enc_size(_In_ size_t size) const noexcept { return size*2; } @@ -142,11 +143,11 @@ namespace stdex /// /// Returns maximum decoded size /// - /// \param size Number of bytes to decode + /// \param[in] size Number of bytes to decode /// /// \returns Maximum number of bytes for the decoded data of `size` length /// - size_t dec_size(size_t size) const noexcept + size_t dec_size(_In_ size_t size) const noexcept { return (size + 1)/2; } diff --git a/include/stdex/idrec.h b/include/stdex/idrec.h index a607bd861..a44629bcc 100644 --- a/include/stdex/idrec.h +++ b/include/stdex/idrec.h @@ -5,6 +5,7 @@ #pragma once +#include "sal.h" #include #include #include @@ -153,7 +154,7 @@ namespace stdex { /// /// Helper class for read/write of records to/from memory /// - template + template class record { public: @@ -173,6 +174,15 @@ namespace stdex { record(_In_ const T &d) : data((T&)d) {} + /// + /// Returns record id + /// + static const T_ID id() + { + return ID; + } + + /// /// Assignment operator /// @@ -180,7 +190,7 @@ namespace stdex { /// /// \returns A const reference to this struct /// - const record& operator =(_In_ const record &r) + const record& operator =(_In_ const record &r) { data = r.data; return *this; @@ -196,7 +206,7 @@ namespace stdex { /// static std::streamoff open(_In_ std::ostream& stream) { - return stdex::idrec::open(stream, id); + return stdex::idrec::open(stream, ID); } @@ -226,11 +236,10 @@ namespace stdex { /// static bool find(_In_ std::istream& stream, _In_opt_ std::streamoff end = (std::streamoff)-1) { - return stdex::idrec::find(stream, id, end); + return stdex::idrec::find(stream, ID, end); } - static const T_ID id; ///< Record id T &data; ///< Record data reference }; }; @@ -245,10 +254,10 @@ namespace stdex { /// /// \returns The stream \p stream /// -template -std::ostream& operator <<(_In_ std::ostream& stream, _In_ const stdex::idrec::record r) +template +std::ostream& operator <<(_In_ std::ostream& stream, _In_ const stdex::idrec::record r) { - // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway. + // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. std::streamoff start = r.open(stream); if (stream.fail()) return stream; @@ -267,10 +276,10 @@ std::ostream& operator <<(_In_ std::ostream& stream, _In_ const stdex::idrec::re /// /// \returns The stream \p stream /// -template -std::istream& operator >>(_In_ std::istream& stream, _In_ stdex::idrec::record r) +template +std::istream& operator >>(_In_ std::istream& stream, _In_ stdex::idrec::record r) { - // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway. + // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. // Read data size. T_SIZE size; diff --git a/include/stdex/sal.h b/include/stdex/sal.h new file mode 100644 index 000000000..bf34c163f --- /dev/null +++ b/include/stdex/sal.h @@ -0,0 +1,54 @@ +/* + SPDX-License-Identifier: MIT + Copyright © 2022 Amebis +*/ + +#pragma once + +#ifdef _WIN32 +#include +#endif + +#ifndef _In_ +#define _In_ +#endif +#ifndef _In_bytecount_ +#define _In_bytecount_(p) +#endif +#ifndef _In_count_ +#define _In_count_(p) +#endif +#ifndef _In_opt_ +#define _In_opt_ +#endif +#ifndef _In_opt_count_ +#define _In_opt_count_(p) +#endif +#ifndef _In_opt_z_count_ +#define _In_opt_z_count_(p) +#endif +#ifndef _In_z_ +#define _In_z_ +#endif +#ifndef _In_z_count_ +#define _In_z_count_(p) +#endif + +#ifndef _Inout_ +#define _Inout_ +#endif + +#ifndef _Use_decl_annotations_ +#define _Use_decl_annotations_ +#endif + +#ifndef _Out_ +#define _Out_ +#endif +#ifndef _Out_opt_ +#define _Out_opt_ +#endif + +#ifndef _Success_ +#define _Success_(p) +#endif diff --git a/include/stdex/vector_queue.h b/include/stdex/vector_queue.h index 28cdd5498..6a0611e31 100644 --- a/include/stdex/vector_queue.h +++ b/include/stdex/vector_queue.h @@ -5,6 +5,8 @@ #pragma once +#include "sal.h" + namespace stdex { /// @@ -399,6 +401,7 @@ namespace stdex /// /// Returns absolute subscript or position number of the given element in the queue. + /// size_type abs(_In_ size_type pos) const { return (m_head + pos) % m_size_max;