JayBeams  0.1
Another project to have fun coding.
check_offset.hpp
Go to the documentation of this file.
1 #ifndef jb_itch5_check_offset_hpp
2 #define jb_itch5_check_offset_hpp
3 
4 #include <cstddef>
5 
6 namespace jb {
7 namespace itch5 {
8 
9 /**
10  * Verify that an offset and field length is valid (generic version).
11  *
12  * @tparam validate if true, actually validate the offset and length,
13  * otherwise this is a no-op.
14  *
15  * @param msg a message to include in the exception (if any) raised
16  * when the validation fails.
17  * @param size the size of the message
18  * @param offset the offset into the message where we want to read
19  * data
20  * @param n the size of the data we want to read
21  *
22  * @throws std::runtime_error if the validation fails.
23  */
24 template <bool validate>
26  char const* msg, std::size_t size, std::size_t offset, std::size_t n) {
27 }
28 
29 /// A version of jb::itch5::check_offset<> that actually validates.
30 template <>
32  char const* msg, std::size_t size, std::size_t offset, std::size_t n);
33 
34 /**
35  * Convenience function to raise an exception upon a validation error.
36  *
37  * @throws std::runtime_error
38  *
39  * @param where a string representing what class, function or
40  * component detected the problem.
41  * @param what a string representing what value or expression failed
42  * its validation.
43  */
44 [[noreturn]] void raise_validation_failed(char const* where, char const* what);
45 
46 } // namespace itch5
47 } // namespace jb
48 
49 #endif // jb_itch5_check_offset_hpp
void raise_validation_failed(char const *where, char const *what)
Convenience function to raise an exception upon a validation error.
void check_offset(char const *msg, std::size_t size, std::size_t offset, std::size_t n)
Verify that an offset and field length is valid (generic version).
void check_offset< true >(char const *msg, std::size_t size, std::size_t offset, std::size_t n)
A version of jb::itch5::check_offset<> that actually validates.
Definition: check_offset.cpp:7
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7