Teh first one
[mldemos:kalians-mldemos.git] / _AlgorithmsPlugins / KernelMethods / dlib / bit_stream / bit_stream_kernel_1.h
1 // Copyright (C) 2003  Davis E. King (davis@dlib.net)\r
2 // License: Boost Software License   See LICENSE.txt for the full license.\r
3 #ifndef DLIB_BIT_STREAM_KERNEl_1_\r
4 #define DLIB_BIT_STREAM_KERNEl_1_\r
5 \r
6 #include "bit_stream_kernel_abstract.h"\r
7 #include <iosfwd>\r
8 \r
9 namespace dlib\r
10 {\r
11 \r
12     class bit_stream_kernel_1\r
13     {\r
14 \r
15         /*!\r
16             INITIAL VALUE\r
17                 write_mode          == false\r
18                 read_mode           == false    \r
19 \r
20             CONVENTION\r
21                 write_mode          == is_in_write_mode()\r
22                 read_mode           == is_in_read_mode()\r
23 \r
24                 if (write_mode)\r
25                 {\r
26                     osp             == pointer to an ostream object\r
27                     buffer          == the low order bits of buffer are the bits to be \r
28                                        written\r
29                     buffer_size     == the number of low order bits in buffer that are \r
30                                        bits that should be written\r
31                     the lowest order bit is the last bit entered by the user\r
32                 }\r
33 \r
34                 if (read_mode)\r
35                 {\r
36                     isp             == pointer to an istream object\r
37                     buffer          == the high order bits of buffer are the bits \r
38                                        waiting to be read by the user\r
39                     buffer_size     == the number of high order bits in buffer that \r
40                                        are bits that are waiting to be read\r
41                     the highest order bit is the next bit to give to the user\r
42                 }\r
43         !*/\r
44 \r
45 \r
46     public:\r
47 \r
48         bit_stream_kernel_1 (\r
49         ) :\r
50             write_mode(false),\r
51             read_mode(false)\r
52         {}\r
53 \r
54         virtual ~bit_stream_kernel_1 (\r
55         )\r
56         {}\r
57 \r
58         void clear (\r
59         );\r
60 \r
61         void set_input_stream (\r
62             std::istream& is\r
63         );\r
64 \r
65         void set_output_stream (\r
66             std::ostream& os\r
67         );\r
68 \r
69         void close (\r
70         );\r
71 \r
72         inline bool is_in_write_mode (\r
73         ) const;\r
74 \r
75         inline bool is_in_read_mode (\r
76         ) const;\r
77 \r
78         inline void write (\r
79             int bit\r
80         );\r
81 \r
82         bool read (\r
83             int& bit\r
84         );\r
85 \r
86         void swap (\r
87             bit_stream_kernel_1& item\r
88         );\r
89 \r
90         private:\r
91 \r
92             // member data\r
93             std::istream* isp;\r
94             std::ostream* osp;\r
95             bool write_mode;\r
96             bool read_mode;\r
97             unsigned char buffer;\r
98             unsigned short buffer_size;\r
99             \r
100             // restricted functions\r
101             bit_stream_kernel_1(bit_stream_kernel_1&);        // copy constructor\r
102             bit_stream_kernel_1& operator=(bit_stream_kernel_1&);  // assignment operator\r
103 \r
104     };\r
105 \r
106     inline void swap (\r
107         bit_stream_kernel_1& a, \r
108         bit_stream_kernel_1& b\r
109     );\r
110 \r
111 // ----------------------------------------------------------------------------------------\r
112 \r
113 }\r
114 \r
115 #ifdef NO_MAKEFILE\r
116 #include "bit_stream_kernel_1.cpp"\r
117 #endif\r
118 \r
119 #endif // DLIB_BIT_STREAM_KERNEl_1_\r
120 \r