JayBeams  0.1
Another project to have fun coding.
check_offset.cpp
Go to the documentation of this file.
2 
3 #include <sstream>
4 #include <stdexcept>
5 
6 template <>
8  char const* msg, std::size_t size, std::size_t offset, std::size_t n) {
9  if (0 < n and offset < size and offset + n <= size) {
10  return;
11  }
12  std::ostringstream os;
13  os << "invalid offset or field length for buffer in " << msg
14  << " size=" << size << ", offset=" << offset << ", n=" << n;
15  throw std::runtime_error(os.str());
16 }
17 
18 void jb::itch5::raise_validation_failed(char const* where, char const* what) {
19  std::ostringstream os;
20  os << "message or field validation failed in " << where << ": " << what;
21  throw std::runtime_error(os.str());
22 }
void raise_validation_failed(char const *where, char const *what)
Convenience function to raise an exception upon a validation error.
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