1 // Copyright (C) 2003 Davis E. King (davis@dlib.net) 2 // License: Boost Software License See LICENSE.txt for the full license. 3 #ifndef DLIB_ENTROPY_DECODER_KERNEl_C_ 4 #define DLIB_ENTROPY_DECODER_KERNEl_C_ 5 6 #include "entropy_decoder_kernel_abstract.h" 7 #include "../algs.h" 8 #include "../assert.h" 9 #include <iostream> 10 11 namespace dlib 12 { 13 14 template < 15 typename decoder 16 > 17 class entropy_decoder_kernel_c : public decoder 18 { 19 20 public: 21 std::istream& get_stream ( 22 ) const; 23 24 void decode ( 25 uint32 low_count, 26 uint32 high_count 27 ); 28 29 uint32 get_target ( 30 uint32 total 31 ); 32 33 private: 34 uint32 _get_target; 35 uint32 TOTAL; 36 }; 37 38 // ---------------------------------------------------------------------------------------- 39 // ---------------------------------------------------------------------------------------- 40 // member function definitions 41 // ---------------------------------------------------------------------------------------- 42 // ---------------------------------------------------------------------------------------- 43 44 template < 45 typename decoder 46 > 47 std::istream& entropy_decoder_kernel_c<decoder>:: get_stream()48 get_stream ( 49 ) const 50 { 51 // make sure requires clause is not broken 52 DLIB_CASSERT( this->stream_is_set() == true, 53 "\tstd::istream& entropy_decoder::get_stream()" 54 << "\n\tyou must set a stream for this object before you can get it" 55 << "\n\tthis: " << this 56 ); 57 58 // call the real function 59 return decoder::get_stream(); 60 } 61 62 // ---------------------------------------------------------------------------------------- 63 64 template < 65 typename decoder 66 > 67 void entropy_decoder_kernel_c<decoder>:: decode(uint32 low_count,uint32 high_count)68 decode ( 69 uint32 low_count, 70 uint32 high_count 71 ) 72 { 73 // make sure requires clause is not broken 74 DLIB_CASSERT( (low_count <= _get_target) && (_get_target < high_count) && 75 (high_count <= TOTAL) && 76 (this->stream_is_set() == true) && (this->get_target_called() == true), 77 "\tvoid entropy_decoder::decode()" 78 << "\n\tRefer to the ensures clause for this function for further information." 79 << "\n\tNote that _get_target refers to get_target(TOTAL)" 80 << "\n\tthis: " << this 81 << "\n\tlow_count: " << low_count 82 << "\n\thigh_count: " << high_count 83 << "\n\tTOTAL: " << TOTAL 84 << "\n\tget_target(TOTAL): " << _get_target 85 << "\n\tis_stream_set(): " << (this->stream_is_set() ? "true" : "false" ) 86 << "\n\tget_target_called(): " << (this->get_target_called() ? "true" : "false" ) 87 ); 88 89 // call the real function 90 decoder::decode(low_count,high_count); 91 } 92 93 // ---------------------------------------------------------------------------------------- 94 95 template < 96 typename decoder 97 > 98 uint32 entropy_decoder_kernel_c<decoder>:: get_target(uint32 total)99 get_target ( 100 uint32 total 101 ) 102 { 103 // make sure requires clause is not broken 104 DLIB_CASSERT( (total > 0) && (total < 65536) && (this->stream_is_set() == true), 105 "\tvoid entropy_decoder::get_target()" 106 << "\n\tyou must set a stream for this object before you can get the " 107 << "\n\rnext target." 108 << "\n\tthis: " << this 109 << "\n\ttotal: " << total 110 ); 111 112 // call the real function 113 _get_target = decoder::get_target(total); 114 TOTAL = total; 115 return _get_target; 116 } 117 118 // ---------------------------------------------------------------------------------------- 119 120 } 121 122 #endif // DLIB_ENTROPY_ENCODER_KERNEl_C_ 123 124