Adjust to compile with gcc
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
09d0f347e8
commit
857b0b36c0
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sal.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sal.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sal.h"
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
@ -153,7 +154,7 @@ namespace stdex {
|
||||
///
|
||||
/// Helper class for read/write of records to/from memory
|
||||
///
|
||||
template <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
|
||||
template <class T, class T_ID, const T_ID ID, class T_SIZE, unsigned int ALIGN>
|
||||
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<T, T_ID, T_SIZE, ALIGN>& operator =(_In_ const record<T, T_ID, T_SIZE, ALIGN> &r)
|
||||
const record<T, T_ID, ID, T_SIZE, ALIGN>& operator =(_In_ const record<T, T_ID, ID, T_SIZE, ALIGN> &r)
|
||||
{
|
||||
data = r.data;
|
||||
return *this;
|
||||
@ -196,7 +206,7 @@ namespace stdex {
|
||||
///
|
||||
static std::streamoff open(_In_ std::ostream& stream)
|
||||
{
|
||||
return stdex::idrec::open<T_ID, T_SIZE>(stream, id);
|
||||
return stdex::idrec::open<T_ID, T_SIZE>(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<T_ID, T_SIZE, ALIGN>(stream, id, end);
|
||||
return stdex::idrec::find<T_ID, T_SIZE, ALIGN>(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 <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
|
||||
std::ostream& operator <<(_In_ std::ostream& stream, _In_ const stdex::idrec::record<T, T_ID, T_SIZE, ALIGN> r)
|
||||
template <class T, class T_ID, T_ID ID, class T_SIZE, unsigned int ALIGN>
|
||||
std::ostream& operator <<(_In_ std::ostream& stream, _In_ const stdex::idrec::record<T, T_ID, ID, T_SIZE, ALIGN> 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 <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
|
||||
std::istream& operator >>(_In_ std::istream& stream, _In_ stdex::idrec::record<T, T_ID, T_SIZE, ALIGN> r)
|
||||
template <class T, class T_ID, T_ID ID, class T_SIZE, unsigned int ALIGN>
|
||||
std::istream& operator >>(_In_ std::istream& stream, _In_ stdex::idrec::record<T, T_ID, ID, T_SIZE, ALIGN> 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;
|
||||
|
54
include/stdex/sal.h
Normal file
54
include/stdex/sal.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2022 Amebis
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <sal.h>
|
||||
#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
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user