81.82% Lines (18/22) 60.00% Functions (3/5)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3   // 3   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 4   // Distributed under the Boost Software License, Version 1.0. (See accompanying
5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 6   //
7   // Official repository: https://github.com/boostorg/json 7   // Official repository: https://github.com/boostorg/json
8   // 8   //
9   9  
10   #ifndef BOOST_JSON_IMPL_STATIC_RESOURCE_IPP 10   #ifndef BOOST_JSON_IMPL_STATIC_RESOURCE_IPP
11   #define BOOST_JSON_IMPL_STATIC_RESOURCE_IPP 11   #define BOOST_JSON_IMPL_STATIC_RESOURCE_IPP
12   12  
13   #include <boost/json/static_resource.hpp> 13   #include <boost/json/static_resource.hpp>
14   #include <boost/throw_exception.hpp> 14   #include <boost/throw_exception.hpp>
15   #include <memory> 15   #include <memory>
16   16  
17   namespace boost { 17   namespace boost {
18   namespace json { 18   namespace json {
19   19  
HITCBC 20   7 static_resource:: 20   7 static_resource::
21   static_resource( 21   static_resource(
22   unsigned char* buffer, 22   unsigned char* buffer,
HITCBC 23   7 std::size_t size) noexcept 23   7 std::size_t size) noexcept
HITCBC 24   7 : p_(buffer) 24   7 : p_(buffer)
HITCBC 25   7 , n_(size) 25   7 , n_(size)
HITCBC 26   7 , size_(size) 26   7 , size_(size)
27   { 27   {
HITCBC 28   7 } 28   7 }
29   29  
30   void 30   void
HITCBC 31   1 static_resource:: 31   1 static_resource::
32   release() noexcept 32   release() noexcept
33   { 33   {
HITCBC 34   1 p_ = reinterpret_cast< 34   1 p_ = reinterpret_cast<
HITCBC 35   1 char*>(p_) - (size_ - n_); 35   1 char*>(p_) - (size_ - n_);
HITCBC 36   1 n_ = size_; 36   1 n_ = size_;
HITCBC 37   1 } 37   1 }
38   38  
39   void* 39   void*
HITCBC 40   10 static_resource:: 40   10 static_resource::
41   do_allocate( 41   do_allocate(
42   std::size_t n, 42   std::size_t n,
43   std::size_t align) 43   std::size_t align)
44   { 44   {
HITCBC 45   10 auto p = std::align(align, n, p_, n_); 45   10 auto p = std::align(align, n, p_, n_);
HITCBC 46   10 if(! p) 46   10 if(! p)
HITCBC 47   4 throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION ); 47   4 throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
HITCBC 48   8 p_ = reinterpret_cast<char*>(p) + n; 48   8 p_ = reinterpret_cast<char*>(p) + n;
HITCBC 49   8 n_ -= n; 49   8 n_ -= n;
HITCBC 50   8 return p; 50   8 return p;
51   } 51   }
52   52  
53   void 53   void
MISUBC 54   static_resource:: 54   static_resource::
55   do_deallocate( 55   do_deallocate(
56   void*, 56   void*,
57   std::size_t, 57   std::size_t,
58   std::size_t) 58   std::size_t)
59   { 59   {
60   // do nothing 60   // do nothing
MISUBC 61   } 61   }
62   62  
63   bool 63   bool
MISUBC 64   static_resource:: 64   static_resource::
65   do_is_equal( 65   do_is_equal(
66   memory_resource const& mr) const noexcept 66   memory_resource const& mr) const noexcept
67   { 67   {
MISUBC 68   return this == &mr; 68   return this == &mr;
69   } 69   }
70   70  
71   } // namespace json 71   } // namespace json
72   } // namespace boost 72   } // namespace boost
73   73  
74   #endif 74   #endif