libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
CharInBuffer.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// CharInBuffer.h
4
//------------------------------------------------------------------------------
5
// Copyright (C) 2002,2005 Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//------------------------------------------------------------------------------
12
#ifndef CHAR_IN_BUFFER_H
13
#define CHAR_IN_BUFFER_H
14
21
#include <sys/types.h>
22
23
#include "
assa/Assure.h
"
24
#include "
assa/Socket.h
"
25
26
#include <string>
27
using
std::string;
28
29
namespace
ASSA {
30
44
class
CharInBuffer
45
{
46
public
:
51
CharInBuffer
(
size_t
size_,
const
string
& delimiter_);
52
57
friend
ASSA::Socket
&
operator>>
(
ASSA::Socket
&,
ASSA::CharInBuffer
&);
58
63
operator
void
* ()
const
;
64
66
const
char
*
c_str
()
const
{
return
m_buffer
.c_str (); }
67
69
size_t
length
()
const
{
return
m_buffer
.length (); }
70
72
size_t
size
()
const
{
return
m_buffer
.size (); }
73
77
void
reset
();
78
80
void
dump
()
const
;
81
85
enum
state_t
{
86
start
,
87
waiting
,
88
complete
,
89
error
90
};
91
93
state_t
state
()
const
{
return
m_state
; }
94
95
private
:
97
static
const
char
*
state_name
(
state_t
state_);
98
100
void
state
(
state_t
new_state_) {
m_state
= new_state_; }
101
103
void
chop
();
104
105
private
:
107
state_t
m_state
;
108
110
std::string
m_buffer
;
111
113
size_t
m_max_size
;
114
116
std::string
m_delimiter
;
117
};
118
119
}
// end namespace ASSA
120
121
/*******************************************************************************
122
Inline member functions
123
*******************************************************************************/
124
using namespace
ASSA;
125
126
inline
127
CharInBuffer::
128
operator
void
* ()
const
129
{
130
return
(m_state == complete
131
? (
void
*) (-1)
// good state
132
: (
void
*) 0);
// bad state
133
}
134
135
inline
void
136
CharInBuffer::
137
reset
()
138
{
139
m_buffer
=
""
;
140
state
(
waiting
);
141
}
142
143
inline
void
144
CharInBuffer::
145
chop
()
146
{
147
m_buffer
.replace (
m_buffer
.find (
m_delimiter
),
m_delimiter
.length (),
""
);
148
}
149
150
#endif
/* CHAR_IN_BUFFER_H */
Generated on Tue Jun 19 2012 08:07:21 for libassa by
1.8.1.1