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 164 165 166 167
|
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_TOKENIZER_KERNEl_C_
#define DLIB_TOKENIZER_KERNEl_C_
#include "tokenizer_kernel_abstract.h"
#include "../assert.h"
#include <string>
#include <iostream>
namespace dlib
{
template <
typename tokenizer
>
class tokenizer_kernel_c : public tokenizer
{
public:
std::istream& get_stream (
) const;
void get_token (
int& type,
std::string& token
);
void set_identifier_token (
const std::string& head,
const std::string& body
);
int peek_type (
) const;
const std::string& peek_token (
) const;
};
template <
typename tokenizer
>
inline void swap (
tokenizer_kernel_c<tokenizer>& a,
tokenizer_kernel_c<tokenizer>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename tokenizer
>
void tokenizer_kernel_c<tokenizer>::
set_identifier_token (
const std::string& head,
const std::string& body
)
{
using namespace std;
// make sure requires clause is not broken
DLIB_CASSERT( head.find_first_of(" \r\t\n0123456789") == string::npos &&
body.find_first_of(" \r\t\n") == string::npos ,
"\tvoid tokenizer::set_identifier_token()"
<< "\n\tyou can't define the IDENTIFIER token this way."
<< "\n\thead: " << head
<< "\n\tbody: " << body
<< "\n\tthis: " << this
);
// call the real function
tokenizer::set_identifier_token(head,body);
}
// ----------------------------------------------------------------------------------------
template <
typename tokenizer
>
std::istream& tokenizer_kernel_c<tokenizer>::
get_stream (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( this->stream_is_set() == true,
"\tstd::istream& tokenizer::get_stream()"
<< "\n\tyou must set a stream for this object before you can get it"
<< "\n\tthis: " << this
);
// call the real function
return tokenizer::get_stream();
}
// ----------------------------------------------------------------------------------------
template <
typename tokenizer
>
int tokenizer_kernel_c<tokenizer>::
peek_type (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( this->stream_is_set() == true,
"\tint tokenizer::peek_type()"
<< "\n\tyou must set a stream for this object before you peek at what it contains"
<< "\n\tthis: " << this
);
// call the real function
return tokenizer::peek_type();
}
// ----------------------------------------------------------------------------------------
template <
typename tokenizer
>
const std::string& tokenizer_kernel_c<tokenizer>::
peek_token (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( this->stream_is_set() == true,
"\tint tokenizer::peek_token()"
<< "\n\tyou must set a stream for this object before you peek at what it contains"
<< "\n\tthis: " << this
);
// call the real function
return tokenizer::peek_token();
}
// ----------------------------------------------------------------------------------------
template <
typename tokenizer
>
void tokenizer_kernel_c<tokenizer>::
get_token (
int& type,
std::string& token
)
{
// make sure requires clause is not broken
DLIB_CASSERT( this->stream_is_set() == true,
"\tvoid tokenizer::get_token()"
<< "\n\tyou must set a stream for this object before you can get tokens from it."
<< "\n\tthis: " << this
);
// call the real function
tokenizer::get_token(type,token);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_TOKENIZER_KERNEl_C_
|