File: lzp_buffer_kernel_c.h

package info (click to toggle)
mldemos 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,224 kB
  • ctags: 46,525
  • sloc: cpp: 306,887; ansic: 167,718; ml: 126; sh: 109; makefile: 2
file content (101 lines) | stat: -rw-r--r-- 2,822 bytes parent folder | download | duplicates (14)
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
// Copyright (C) 2003  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#ifndef DLIB_LZP_BUFFER_KERNEl_C_
#define DLIB_LZP_BUFFER_KERNEl_C_

#include "lzp_buffer_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
#include <iostream>

namespace dlib
{

    template <
        typename lzp_base
        >
    class lzp_buffer_kernel_c : public lzp_base
    {
        
        public:
        lzp_buffer_kernel_c (
            unsigned long buffer_size         
        );

     
        unsigned char operator[] (
            unsigned long index
        ) const;


        unsigned long make_safe (
            unsigned long buffer_size
        )
        /*!
            ensures
                - if ( 10 < buffer_size < 32) then
                    - returns buffer_size
                - else
                    - throws due to failed CASSERT
        !*/
        {

            // make sure requires clause is not broken
            DLIB_CASSERT( 10 < buffer_size && buffer_size < 32,
                "\tlzp_buffer::lzp_buffer(unsigned long)"
                << "\n\tbuffer_size must be in the range 11 to 31."
                << "\n\tthis:         " << this
                << "\n\tbuffer_size:  " << buffer_size
                );

            return buffer_size;
        }

    };

// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
    // member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------

    template <
        typename lzp_base
        >
    unsigned char lzp_buffer_kernel_c<lzp_base>::
    operator[] (
            unsigned long index
    ) const
    {
        // make sure requires clause is not broken
        DLIB_CASSERT( index < this->size(),
            "\tunsigned char lzp_buffer::operator[](unsigned long) const"
            << "\n\tindex must be in the range 0 to size()()-1"
            << "\n\tthis:    " << this
            << "\n\tsize():  " << this->size()
            << "\n\tindex:   " << index
            );

        // call the real function
        return lzp_base::operator[](index);
    }

// ----------------------------------------------------------------------------------------

    template <
        typename lzp_base
        >
    lzp_buffer_kernel_c<lzp_base>::
    lzp_buffer_kernel_c (
        unsigned long buffer_size
    ) :
        lzp_base(make_safe(buffer_size))
    {
    }

// ----------------------------------------------------------------------------------------

}

#endif // DLIB_LZP_BUFFER_KERNEl_C_