1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

add checksum literals

This commit is contained in:
bolero-MURAKAMI 2016-08-15 13:43:40 +09:00
parent 0805756259
commit d26dafc3dc
4 changed files with 394 additions and 1 deletions

View file

@ -15,6 +15,8 @@
#include <sprout/workaround/std/cstddef.hpp> #include <sprout/workaround/std/cstddef.hpp>
#include <sprout/array/array.hpp> #include <sprout/array/array.hpp>
#include <sprout/array/make_array.hpp> #include <sprout/array/make_array.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/string/string.hpp>
#include <sprout/container/functions.hpp> #include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp> #include <sprout/iterator/operation.hpp>
#include <sprout/iterator/bytes_iterator.hpp> #include <sprout/iterator/bytes_iterator.hpp>
@ -481,6 +483,74 @@ namespace sprout {
return checksum(); return checksum();
} }
}; };
//
// make_md5
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR sprout::md5::value_type
make_md5(ForwardIterator first, ForwardIterator last) {
return sprout::md5().c_process_block(first, last)();
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::md5::value_type
make_md5(sprout::basic_string<Elem, N, Traits> const& s) {
return sprout::md5().c_process_range(s)();
}
inline SPROUT_CONSTEXPR sprout::md5::value_type
make_md5(char const* s) {
return sprout::md5().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::md5::value_type
make_md5(wchar_t const* s) {
return sprout::md5().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::md5::value_type
make_md5(char16_t const* s) {
return sprout::md5().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::md5::value_type
make_md5(char32_t const* s) {
return sprout::md5().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#endif
} // namespace sprout } // namespace sprout
#if SPROUT_USE_USER_DEFINED_LITERALS
namespace sprout {
namespace literals {
namespace checksum {
//
// _md5
//
inline SPROUT_CONSTEXPR sprout::md5::value_type
operator"" _md5(char const* s, std::size_t size) {
return sprout::md5().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::md5::value_type
operator"" _md5(wchar_t const* s, std::size_t size) {
return sprout::md5().c_process_bytes(s, size)();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::md5::value_type
operator"" _md5(char16_t const* s, std::size_t size) {
return sprout::md5().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::md5::value_type
operator"" _md5(char32_t const* s, std::size_t size) {
return sprout::md5().c_process_bytes(s, size)();
}
#endif
} // namespace checksum
using sprout::literals::checksum::operator"" _md5;
} // namespace literals
using sprout::literals::checksum::operator"" _md5;
} // namespace sprout
#endif // #if SPROUT_USE_USER_DEFINED_LITERALS
#endif // #ifndef SPROUT_CHECKSUM_MD5_HPP #endif // #ifndef SPROUT_CHECKSUM_MD5_HPP

View file

@ -15,6 +15,8 @@
#include <sprout/workaround/std/cstddef.hpp> #include <sprout/workaround/std/cstddef.hpp>
#include <sprout/array/array.hpp> #include <sprout/array/array.hpp>
#include <sprout/array/make_array.hpp> #include <sprout/array/make_array.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/string/string.hpp>
#include <sprout/sub_array/sub_array.hpp> #include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/sub.hpp> #include <sprout/sub_array/sub.hpp>
#include <sprout/container/functions.hpp> #include <sprout/container/functions.hpp>
@ -523,6 +525,74 @@ namespace sprout {
return checksum(); return checksum();
} }
}; };
//
// make_sha1
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR sprout::sha1::value_type
make_sha1(ForwardIterator first, ForwardIterator last) {
return sprout::sha1().c_process_block(first, last)();
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::sha1::value_type
make_sha1(sprout::basic_string<Elem, N, Traits> const& s) {
return sprout::sha1().c_process_range(s)();
}
inline SPROUT_CONSTEXPR sprout::sha1::value_type
make_sha1(char const* s) {
return sprout::sha1().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sha1::value_type
make_sha1(wchar_t const* s) {
return sprout::sha1().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sha1::value_type
make_sha1(char16_t const* s) {
return sprout::sha1().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sha1::value_type
make_sha1(char32_t const* s) {
return sprout::sha1().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#endif
} // namespace sprout } // namespace sprout
#if SPROUT_USE_USER_DEFINED_LITERALS
namespace sprout {
namespace literals {
namespace checksum {
//
// _sha1
//
inline SPROUT_CONSTEXPR sprout::sha1::value_type
operator"" _sha1(char const* s, std::size_t size) {
return sprout::sha1().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sha1::value_type
operator"" _sha1(wchar_t const* s, std::size_t size) {
return sprout::sha1().c_process_bytes(s, size)();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sha1::value_type
operator"" _sha1(char16_t const* s, std::size_t size) {
return sprout::sha1().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sha1::value_type
operator"" _sha1(char32_t const* s, std::size_t size) {
return sprout::sha1().c_process_bytes(s, size)();
}
#endif
} // namespace checksum
using sprout::literals::checksum::operator"" _sha1;
} // namespace literals
using sprout::literals::checksum::operator"" _sha1;
} // namespace sprout
#endif // #if SPROUT_USE_USER_DEFINED_LITERALS
#endif // #ifndef SPROUT_CHECKSUM_SHA1_HPP #endif // #ifndef SPROUT_CHECKSUM_SHA1_HPP

View file

@ -14,6 +14,8 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp> #include <sprout/workaround/std/cstddef.hpp>
#include <sprout/limits.hpp> #include <sprout/limits.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/string/string.hpp>
#include <sprout/container/functions.hpp> #include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp> #include <sprout/iterator/operation.hpp>
#include <sprout/iterator/bytes_iterator.hpp> #include <sprout/iterator/bytes_iterator.hpp>
@ -49,7 +51,9 @@ namespace sprout {
); );
} }
public: public:
SPROUT_CONSTEXPR sum_basic() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL SPROUT_CONSTEXPR sum_basic()
: sum_()
{}
sum_basic(sum_basic const&) = default; sum_basic(sum_basic const&) = default;
explicit SPROUT_CONSTEXPR sum_basic(sum_type sum) explicit SPROUT_CONSTEXPR sum_basic(sum_type sum)
: sum_(sum) : sum_(sum)
@ -121,6 +125,182 @@ namespace sprout {
typedef sprout::sum_basic<8> sum8; typedef sprout::sum_basic<8> sum8;
typedef sprout::sum_basic<16> sum16; typedef sprout::sum_basic<16> sum16;
typedef sprout::sum_basic<32> sum32; typedef sprout::sum_basic<32> sum32;
//
// make_sum8
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR sprout::sum8::value_type
make_sum8(ForwardIterator first, ForwardIterator last) {
return sprout::sum8().c_process_block(first, last)();
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::sum8::value_type
make_sum8(sprout::basic_string<Elem, N, Traits> const& s) {
return sprout::sum8().c_process_range(s)();
}
inline SPROUT_CONSTEXPR sprout::sum8::value_type
make_sum8(char const* s) {
return sprout::sum8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sum8::value_type
make_sum8(wchar_t const* s) {
return sprout::sum8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sum8::value_type
make_sum8(char16_t const* s) {
return sprout::sum8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sum8::value_type
make_sum8(char32_t const* s) {
return sprout::sum8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#endif
//
// make_sum16
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR sprout::sum16::value_type
make_sum16(ForwardIterator first, ForwardIterator last) {
return sprout::sum16().c_process_block(first, last)();
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::sum16::value_type
make_sum16(sprout::basic_string<Elem, N, Traits> const& s) {
return sprout::sum16().c_process_range(s)();
}
inline SPROUT_CONSTEXPR sprout::sum16::value_type
make_sum16(char const* s) {
return sprout::sum16().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sum16::value_type
make_sum16(wchar_t const* s) {
return sprout::sum16().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sum16::value_type
make_sum16(char16_t const* s) {
return sprout::sum16().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sum16::value_type
make_sum16(char32_t const* s) {
return sprout::sum16().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#endif
//
// make_sum32
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR sprout::sum32::value_type
make_sum32(ForwardIterator first, ForwardIterator last) {
return sprout::sum32().c_process_block(first, last)();
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::sum32::value_type
make_sum32(sprout::basic_string<Elem, N, Traits> const& s) {
return sprout::sum32().c_process_range(s)();
}
inline SPROUT_CONSTEXPR sprout::sum32::value_type
make_sum32(char const* s) {
return sprout::sum32().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sum32::value_type
make_sum32(wchar_t const* s) {
return sprout::sum32().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sum32::value_type
make_sum32(char16_t const* s) {
return sprout::sum32().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::sum32::value_type
make_sum32(char32_t const* s) {
return sprout::sum32().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#endif
} // namespace sprout } // namespace sprout
#if SPROUT_USE_USER_DEFINED_LITERALS
namespace sprout {
namespace literals {
namespace checksum {
//
// _sum8
//
inline SPROUT_CONSTEXPR sprout::sum8::value_type
operator"" _sum8(char const* s, std::size_t size) {
return sprout::sum8().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sum8::value_type
operator"" _sum8(wchar_t const* s, std::size_t size) {
return sprout::sum8().c_process_bytes(s, size)();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sum8::value_type
operator"" _sum8(char16_t const* s, std::size_t size) {
return sprout::sum8().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sum8::value_type
operator"" _sum8(char32_t const* s, std::size_t size) {
return sprout::sum8().c_process_bytes(s, size)();
}
#endif
//
// _sum16
//
inline SPROUT_CONSTEXPR sprout::sum16::value_type
operator"" _sum16(char const* s, std::size_t size) {
return sprout::sum16().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sum16::value_type
operator"" _sum16(wchar_t const* s, std::size_t size) {
return sprout::sum16().c_process_bytes(s, size)();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sum16::value_type
operator"" _sum16(char16_t const* s, std::size_t size) {
return sprout::sum16().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sum16::value_type
operator"" _sum16(char32_t const* s, std::size_t size) {
return sprout::sum16().c_process_bytes(s, size)();
}
#endif
//
// _sum32
//
inline SPROUT_CONSTEXPR sprout::sum32::value_type
operator"" _sum32(char const* s, std::size_t size) {
return sprout::sum32().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sum32::value_type
operator"" _sum32(wchar_t const* s, std::size_t size) {
return sprout::sum32().c_process_bytes(s, size)();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::sum32::value_type
operator"" _sum32(char16_t const* s, std::size_t size) {
return sprout::sum32().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::sum32::value_type
operator"" _sum32(char32_t const* s, std::size_t size) {
return sprout::sum32().c_process_bytes(s, size)();
}
#endif
} // namespace checksum
using sprout::literals::checksum::operator"" _sum8;
using sprout::literals::checksum::operator"" _sum16;
using sprout::literals::checksum::operator"" _sum32;
} // namespace literals
using sprout::literals::checksum::operator"" _sum8;
using sprout::literals::checksum::operator"" _sum16;
using sprout::literals::checksum::operator"" _sum32;
} // namespace sprout
#endif // #if SPROUT_USE_USER_DEFINED_LITERALS
#endif // #ifndef SPROUT_CHECKSUM_SUM_HPP #endif // #ifndef SPROUT_CHECKSUM_SUM_HPP

View file

@ -11,6 +11,8 @@
#include <cstdint> #include <cstdint>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp> #include <sprout/workaround/std/cstddef.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/string/string.hpp>
#include <sprout/container/functions.hpp> #include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp> #include <sprout/iterator/operation.hpp>
#include <sprout/iterator/bytes_iterator.hpp> #include <sprout/iterator/bytes_iterator.hpp>
@ -39,6 +41,9 @@ namespace sprout {
); );
} }
public: public:
SPROUT_CONSTEXPR xor8()
: sum_()
{}
xor8(xor8 const&) = default; xor8(xor8 const&) = default;
explicit SPROUT_CONSTEXPR xor8(sum_type sum) explicit SPROUT_CONSTEXPR xor8(sum_type sum)
: sum_(sum) : sum_(sum)
@ -101,6 +106,74 @@ namespace sprout {
return checksum(); return checksum();
} }
}; };
//
// make_xor8
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR sprout::xor8::value_type
make_xor8(ForwardIterator first, ForwardIterator last) {
return sprout::xor8().c_process_block(first, last)();
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::xor8::value_type
make_xor8(sprout::basic_string<Elem, N, Traits> const& s) {
return sprout::xor8().c_process_range(s)();
}
inline SPROUT_CONSTEXPR sprout::xor8::value_type
make_xor8(char const* s) {
return sprout::xor8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::xor8::value_type
make_xor8(wchar_t const* s) {
return sprout::xor8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::xor8::value_type
make_xor8(char16_t const* s) {
return sprout::xor8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
inline SPROUT_CONSTEXPR sprout::xor8::value_type
make_xor8(char32_t const* s) {
return sprout::xor8().c_process_bytes(s, sprout::char_traits<char>::length(s))();
}
#endif
} // namespace sprout } // namespace sprout
#if SPROUT_USE_USER_DEFINED_LITERALS
namespace sprout {
namespace literals {
namespace checksum {
//
// _xor8
//
inline SPROUT_CONSTEXPR sprout::xor8::value_type
operator"" _xor8(char const* s, std::size_t size) {
return sprout::xor8().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::xor8::value_type
operator"" _xor8(wchar_t const* s, std::size_t size) {
return sprout::xor8().c_process_bytes(s, size)();
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::xor8::value_type
operator"" _xor8(char16_t const* s, std::size_t size) {
return sprout::xor8().c_process_bytes(s, size)();
}
inline SPROUT_CONSTEXPR sprout::xor8::value_type
operator"" _xor8(char32_t const* s, std::size_t size) {
return sprout::xor8().c_process_bytes(s, size)();
}
#endif
} // namespace checksum
using sprout::literals::checksum::operator"" _xor8;
} // namespace literals
using sprout::literals::checksum::operator"" _xor8;
} // namespace sprout
#endif // #if SPROUT_USE_USER_DEFINED_LITERALS
#endif // #ifndef SPROUT_CHECKSUM_XOR_HPP #endif // #ifndef SPROUT_CHECKSUM_XOR_HPP