Skip to content

Develop #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/cereal/archives/binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ namespace cereal
~BinaryOutputArchive() CEREAL_NOEXCEPT = default;

//! Writes size bytes of data to the output stream
void saveBinary( const void * data, std::size_t size )
void saveBinary( const void * data, std::streamsize size )
{
auto const writtenSize = static_cast<std::size_t>( itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ), size ) );
auto const writtenSize = itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ), size );

if(writtenSize != size)
throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + std::to_string(writtenSize));
Expand Down Expand Up @@ -97,9 +97,9 @@ namespace cereal
~BinaryInputArchive() CEREAL_NOEXCEPT = default;

//! Reads size bytes of data from the input stream
void loadBinary( void * const data, std::size_t size )
void loadBinary( void * const data, std::streamsize size )
{
auto const readSize = static_cast<std::size_t>( itsStream.rdbuf()->sgetn( reinterpret_cast<char*>( data ), size ) );
auto const readSize = itsStream.rdbuf()->sgetn( reinterpret_cast<char*>( data ), size );

if(readSize != size)
throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + std::to_string(readSize));
Expand Down Expand Up @@ -148,14 +148,14 @@ namespace cereal
template <class T> inline
void CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, BinaryData<T> const & bd)
{
ar.saveBinary( bd.data, static_cast<std::size_t>( bd.size ) );
ar.saveBinary( bd.data, static_cast<std::streamsize>( bd.size ) );
}

//! Loading binary data
template <class T> inline
void CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, BinaryData<T> & bd)
{
ar.loadBinary(bd.data, static_cast<std::size_t>(bd.size));
ar.loadBinary(bd.data, static_cast<std::streamsize>( bd.size ) );
}
} // namespace cereal

Expand Down
26 changes: 13 additions & 13 deletions include/cereal/archives/portable_binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ namespace cereal
~PortableBinaryOutputArchive() CEREAL_NOEXCEPT = default;

//! Writes size bytes of data to the output stream
template <std::size_t DataSize> inline
void saveBinary( const void * data, std::size_t size )
template <std::streamsize DataSize> inline
void saveBinary( const void * data, std::streamsize size )
{
std::size_t writtenSize = 0;
std::streamsize writtenSize = 0;

if( itsConvertEndianness )
{
for( std::size_t i = 0; i < size; i += DataSize )
for( std::size_t j = 0; j < DataSize; ++j )
writtenSize += static_cast<std::size_t>( itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ) + DataSize - j - 1 + i, 1 ) );
for( std::streamsize i = 0; i < size; i += DataSize )
for( std::streamsize j = 0; j < DataSize; ++j )
writtenSize += itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ) + DataSize - j - 1 + i, 1 );
}
else
writtenSize = static_cast<std::size_t>( itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ), size ) );
writtenSize = itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ), size );

if(writtenSize != size)
throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + std::to_string(writtenSize));
Expand Down Expand Up @@ -235,11 +235,11 @@ namespace cereal
/*! @param data The data to save
@param size The number of bytes in the data
@tparam DataSize T The size of the actual type of the data elements being loaded */
template <std::size_t DataSize> inline
void loadBinary( void * const data, std::size_t size )
template <std::streamsize DataSize> inline
void loadBinary( void * const data, std::streamsize size )
{
// load data
auto const readSize = static_cast<std::size_t>( itsStream.rdbuf()->sgetn( reinterpret_cast<char*>( data ), size ) );
auto const readSize = itsStream.rdbuf()->sgetn( reinterpret_cast<char*>( data ), size );

if(readSize != size)
throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + std::to_string(readSize));
Expand All @@ -248,7 +248,7 @@ namespace cereal
if( itsConvertEndianness )
{
std::uint8_t * ptr = reinterpret_cast<std::uint8_t*>( data );
for( std::size_t i = 0; i < size; i += DataSize )
for( std::streamsize i = 0; i < size; i += DataSize )
portable_binary_detail::swap_bytes<DataSize>( ptr + i );
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace cereal
(std::is_floating_point<TT>::value && std::numeric_limits<TT>::is_iec559),
"Portable binary only supports IEEE 754 standardized floating point" );

ar.template saveBinary<sizeof(TT)>( bd.data, static_cast<std::size_t>( bd.size ) );
ar.template saveBinary<sizeof(TT)>( bd.data, static_cast<std::streamsize>( bd.size ) );
}

//! Loading binary data from portable binary
Expand All @@ -320,7 +320,7 @@ namespace cereal
(std::is_floating_point<TT>::value && std::numeric_limits<TT>::is_iec559),
"Portable binary only supports IEEE 754 standardized floating point" );

ar.template loadBinary<sizeof(TT)>( bd.data, static_cast<std::size_t>( bd.size ) );
ar.template loadBinary<sizeof(TT)>( bd.data, static_cast<std::streamsize>( bd.size ) );
}
} // namespace cereal

Expand Down
12 changes: 6 additions & 6 deletions include/cereal/archives/xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ namespace cereal
static Options Default(){ return Options(); }

//! Specify specific options for the XMLOutputArchive
/*! @param precision The precision used for floating point numbers
@param indent Whether to indent each line of XML
@param outputType Whether to output the type of each serialized object as an attribute
@param sizeAttributes Whether dynamically sized containers output the size=dynamic attribute */
/*! @param precision_ The precision used for floating point numbers
@param indent_ Whether to indent each line of XML
@param outputType_ Whether to output the type of each serialized object as an attribute
@param sizeAttributes_ Whether dynamically sized containers output the size=dynamic attribute */
explicit Options( int precision_ = std::numeric_limits<double>::max_digits10,
bool indent_ = true,
bool outputType_ = false,
Expand Down Expand Up @@ -210,7 +210,7 @@ namespace cereal
itsNodes.top().node->append_attribute( itsXML.allocate_attribute( "type", "cereal binary data" ) );

finishNode();
};
}

//! @}
/*! @name Internal Functionality
Expand Down Expand Up @@ -467,7 +467,7 @@ namespace cereal
std::memcpy( data, decoded.data(), decoded.size() );

finishNode();
};
}

//! @}
/*! @name Internal Functionality
Expand Down
16 changes: 11 additions & 5 deletions include/cereal/cereal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ namespace cereal
instantiate_polymorphic_binding( T*, Archive*, BindingTag, adl_tag ); \
} } /* end namespaces */

//! Helper macro to omit unused warning
#if defined(__GNUC__)
// GCC / clang don't want the function
#define CEREAL_UNUSED_FUNCTION
#else
#define CEREAL_UNUSED_FUNCTION static void unused() { (void)version; }
#endif

// ######################################################################
//! Defines a class version for some type
/*! Versioning information is optional and adds some small amount of
Expand Down Expand Up @@ -207,7 +215,7 @@ namespace cereal
std::type_index(typeid(TYPE)).hash_code(), VERSION_NUMBER ); \
return VERSION_NUMBER; \
} \
static void unused() { (void)version; } \
CEREAL_UNUSED_FUNCTION \
}; /* end Version */ \
const std::uint32_t Version<TYPE>::version = \
Version<TYPE>::registerVersion(); \
Expand Down Expand Up @@ -483,8 +491,7 @@ namespace cereal
/*! If this is the first time this class has been serialized, we will record its
version number and serialize that.

@tparam T The type of the class being serialized
@param version The version number associated with it */
@tparam T The type of the class being serialized */
template <class T> inline
std::uint32_t registerClassVersion()
{
Expand Down Expand Up @@ -875,8 +882,7 @@ namespace cereal
/*! If this is the first time this class has been serialized, we will record its
version number and serialize that.

@tparam T The type of the class being serialized
@param version The version number associated with it */
@tparam T The type of the class being serialized */
template <class T> inline
std::uint32_t loadClassVersion()
{
Expand Down
2 changes: 1 addition & 1 deletion include/cereal/details/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace cereal
struct adl_tag;

// used during saving pointers
static const int32_t msb_32bit = 0x80000000;
static const uint32_t msb_32bit = 0x80000000;
static const int32_t msb2_32bit = 0x40000000;
}

Expand Down
10 changes: 9 additions & 1 deletion include/cereal/details/polymorphic_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
#include <set>
#include <stack>

//! Helper macro to omit unused warning
#if defined(__GNUC__)
// GCC / clang don't want the function
#define CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION
#else
#define CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION static void unused() { (void)b; }
#endif

//! Binds a polymorhic type to all registered archives
/*! This binds a polymorphic type to all compatible registered archives that
have been registered with CEREAL_REGISTER_ARCHIVE. This must be called
Expand All @@ -67,7 +75,7 @@
template<> \
struct init_binding<__VA_ARGS__> { \
static bind_to_archives<__VA_ARGS__> const & b; \
static void unused() { (void)b; } \
CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION \
}; \
bind_to_archives<__VA_ARGS__> const & init_binding<__VA_ARGS__>::b = \
::cereal::detail::StaticObject< \
Expand Down
1 change: 1 addition & 0 deletions include/cereal/details/static_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace cereal
std::unique_lock<std::mutex> lock;
#else
public:
LockGuard(LockGuard const &) = default; // prevents implicit copy ctor warning
~LockGuard() CEREAL_NOEXCEPT {} // prevents variable not used
#endif
};
Expand Down
9 changes: 8 additions & 1 deletion include/cereal/external/base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#ifndef CEREAL_EXTERNAL_BASE64_HPP_
#define CEREAL_EXTERNAL_BASE64_HPP_

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif

#include <string>

namespace cereal
Expand Down Expand Up @@ -123,5 +128,7 @@ namespace cereal
}
} // namespace base64
} // namespace cereal

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // CEREAL_EXTERNAL_BASE64_HPP_
Loading