File size: 5,231 Bytes
9375c9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
// Copyright (C) 2003 Davis E. King ([email protected])
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_CONDITIONING_CLASS_KERNEl_C_
#define DLIB_CONDITIONING_CLASS_KERNEl_C_
#include "conditioning_class_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
#include <iostream>
namespace dlib
{
template <
typename cc_base
>
class conditioning_class_kernel_c : public cc_base
{
const unsigned long alphabet_size;
public:
conditioning_class_kernel_c (
typename cc_base::global_state_type& global_state
) : cc_base(global_state),alphabet_size(cc_base::get_alphabet_size()) {}
bool increment_count (
unsigned long symbol,
unsigned short amount = 1
);
unsigned long get_count (
unsigned long symbol
) const;
unsigned long get_range (
unsigned long symbol,
unsigned long& low_count,
unsigned long& high_count,
unsigned long& total_count
) const;
void get_symbol (
unsigned long target,
unsigned long& symbol,
unsigned long& low_count,
unsigned long& high_count
) const;
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename cc_base
>
bool conditioning_class_kernel_c<cc_base>::
increment_count (
unsigned long symbol,
unsigned short amount
)
{
// make sure requires clause is not broken
DLIB_CASSERT(symbol < alphabet_size &&
0 < amount && amount < 32768,
"\tvoid conditioning_class::increment_count()"
<< "\n\tthe symbol must be in the range 0 to alphabet_size-1. and"
<< "\n\tamount must be in the range 1 to 32767"
<< "\n\talphabet_size: " << alphabet_size
<< "\n\tsymbol: " << symbol
<< "\n\tamount: " << amount
<< "\n\tthis: " << this
);
// call the real function
return cc_base::increment_count(symbol,amount);
}
// ----------------------------------------------------------------------------------------
template <
typename cc_base
>
unsigned long conditioning_class_kernel_c<cc_base>::
get_count (
unsigned long symbol
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(symbol < alphabet_size,
"\tvoid conditioning_class::get_count()"
<< "\n\tthe symbol must be in the range 0 to alphabet_size-1"
<< "\n\talphabet_size: " << alphabet_size
<< "\n\tsymbol: " << symbol
<< "\n\tthis: " << this
);
// call the real function
return cc_base::get_count(symbol);
}
// ----------------------------------------------------------------------------------------
template <
typename cc_base
>
unsigned long conditioning_class_kernel_c<cc_base>::
get_range (
unsigned long symbol,
unsigned long& low_count,
unsigned long& high_count,
unsigned long& total_count
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(symbol < alphabet_size,
"\tvoid conditioning_class::get_range()"
<< "\n\tthe symbol must be in the range 0 to alphabet_size-1"
<< "\n\talphabet_size: " << alphabet_size
<< "\n\tsymbol: " << symbol
<< "\n\tthis: " << this
);
// call the real function
return cc_base::get_range(symbol,low_count,high_count,total_count);
}
// ----------------------------------------------------------------------------------------
template <
typename cc_base
>
void conditioning_class_kernel_c<cc_base>::
get_symbol (
unsigned long target,
unsigned long& symbol,
unsigned long& low_count,
unsigned long& high_count
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( target < this->get_total(),
"\tvoid conditioning_class::get_symbol()"
<< "\n\tthe target must be in the range 0 to get_total()-1"
<< "\n\tget_total(): " << this->get_total()
<< "\n\ttarget: " << target
<< "\n\tthis: " << this
);
// call the real function
cc_base::get_symbol(target,symbol,low_count,high_count);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_CONDITIONING_CLASS_KERNEl_C_
|