Public Types | Public Member Functions | Data Fields

ts::ConstBuffer Struct Reference

A chunk of read only memory. More...

#include <TsBuffer.h>

Public Types

typedef ConstBuffer self
 Self reference type.
typedef bool(self::* pseudo_bool )() const

Public Member Functions

 ConstBuffer ()
 Default constructor (empty buffer).
 ConstBuffer (char const *ptr, size_t n)
 Construct from pointer and size.
 ConstBuffer (char const *start, char const *end)
 Construct from two pointers.
 ConstBuffer (Buffer const &buffer)
 Construct from writable buffer.
bool operator== (self const &that) const
 Equality.
bool operator== (Buffer const &that) const
 Equality.
bool operator!= (self const &that) const
 Inequality.
bool operator!= (Buffer const &that) const
 Inequality.
selfoperator= (Buffer const &that)
 Assign from non-const Buffer.
char operator* () const
selfoperator++ ()
 Discard the first character in the buffer.
selfoperator+= (size_t n)
 Discard the first n characters.
bool operator! () const
 Check for empty buffer.
 operator pseudo_bool () const
 Check for non-empty buffer.
bool contains (char const *p) const
selfset (char const *ptr, size_t n=0)
 Set the chunk.
selfset (char const *start, char const *end)
 Set from 2 pointers.
selfreset ()
 Reset to empty.
char const * find (char c) const
 Find a character.
self splitOn (char const *p)
 Split the buffer on the character at p.
self splitOn (char c)
 Split the buffer on the character c.
self after (char const *p) const
 Get a trailing segment of the buffer.
self after (char c) const
 Get a trailing segment of the buffer.
selfclip (char const *p)
 Remove trailing segment.
Accessors.

char const * data () const
 Get the data in the buffer.
size_t size () const
 Get the size of the buffer.
char operator[] (int n) const
 Access a character (no bounds check).

Data Fields

char const * _ptr
 Pointer to base of memory chunk.
size_t _size
 Size of memory chunk.

Detailed Description

A chunk of read only memory.

A convenience class because we pass this kind of pair frequently.

Definition at line 131 of file TsBuffer.h.


Member Typedef Documentation

typedef bool(self::* ts::ConstBuffer::pseudo_bool)() const

Definition at line 133 of file TsBuffer.h.

Self reference type.

Definition at line 132 of file TsBuffer.h.


Constructor & Destructor Documentation

ts::ConstBuffer::ConstBuffer (  )  [inline]

Default constructor (empty buffer).

Definition at line 322 of file TsBuffer.h.

ts::ConstBuffer::ConstBuffer ( char const *  ptr,
size_t  n 
) [inline]

Construct from pointer and size.

Parameters:
ptr Pointer to buffer.
n Size of buffer.

Definition at line 323 of file TsBuffer.h.

ts::ConstBuffer::ConstBuffer ( char const *  start,
char const *  end 
) [inline]

Construct from two pointers.

Note:
This presumes a half open range (start, end]
Due to ambiguity issues do not invoke this with start == 0.
Parameters:
start First valid character.
end First invalid character.

Definition at line 324 of file TsBuffer.h.

ts::ConstBuffer::ConstBuffer ( Buffer const &  buffer  )  [inline]

Construct from writable buffer.

Parameters:
buffer Buffer to copy.

Definition at line 325 of file TsBuffer.h.


Member Function Documentation

ConstBuffer ts::ConstBuffer::after ( char const *  p  )  const [inline]

Get a trailing segment of the buffer.

Returns:
A buffer that contains all data after p.

Definition at line 383 of file TsBuffer.h.

References _ptr, _size, and contains().

Referenced by after(), and ats_ip_parse().

ConstBuffer ts::ConstBuffer::after ( char  c  )  const [inline]

Get a trailing segment of the buffer.

Returns:
A buffer that contains all data after the first occurrence of c.

Definition at line 386 of file TsBuffer.h.

References after(), and find().

ConstBuffer & ts::ConstBuffer::clip ( char const *  p  )  [inline]

Remove trailing segment.

Data at p and beyond is removed from the buffer. If p is not in the buffer, no change is made.

Returns:
this.

Definition at line 389 of file TsBuffer.h.

References _ptr, _size, and contains().

Referenced by ats_ip_parse().

bool ts::ConstBuffer::contains ( char const *  p  )  const [inline]
Returns:
true if p points at a character in this.

Definition at line 360 of file TsBuffer.h.

References _ptr, and _size.

Referenced by after(), clip(), MIMEHdr::get_host_port_values(), and splitOn().

char const * ts::ConstBuffer::data (  )  const [inline]

Get the data in the buffer.

Definition at line 357 of file TsBuffer.h.

References _ptr.

Referenced by ats_ip_check_characters(), ats_ip_getbestaddrinfo(), ats_ip_parse(), ats_ip_pton(), Ink_Inet(), and LogHost::set_name_or_ipstr().

char const * ts::ConstBuffer::find ( char  c  )  const [inline]

Find a character.

Returns:
A pointer to the first occurrence of c in this or NULL if c is not found.

Definition at line 375 of file TsBuffer.h.

References _ptr, and _size.

Referenced by after(), ats_ip_parse(), ats_ip_pton(), and splitOn().

ts::ConstBuffer::operator pseudo_bool (  )  const [inline]

Check for non-empty buffer.

Returns:
true if the buffer has a non-zero pointer and size.

Definition at line 345 of file TsBuffer.h.

References _ptr, and _size.

bool ts::ConstBuffer::operator! (  )  const [inline]

Check for empty buffer.

Returns:
true if the buffer has a zero pointer or size.

Definition at line 344 of file TsBuffer.h.

References _ptr, and _size.

bool ts::ConstBuffer::operator!= ( Buffer const &  that  )  const [inline]

Inequality.

Returns:
true if that does not refer to the same memory as this, false otherwise.

Definition at line 336 of file TsBuffer.h.

bool ts::ConstBuffer::operator!= ( self const &  that  )  const [inline]

Inequality.

Returns:
true if that does not refer to the same memory as this, false otherwise.

Definition at line 335 of file TsBuffer.h.

char ts::ConstBuffer::operator* (  )  const [inline]
Returns:
The first character in the buffer.

Definition at line 346 of file TsBuffer.h.

References _ptr.

ConstBuffer & ts::ConstBuffer::operator++ (  )  [inline]

Discard the first character in the buffer.

Returns:
this object.

Definition at line 347 of file TsBuffer.h.

References _ptr, and _size.

ConstBuffer & ts::ConstBuffer::operator+= ( size_t  n  )  [inline]

Discard the first n characters.

Returns:
this object.

Definition at line 352 of file TsBuffer.h.

References _ptr, and _size.

ConstBuffer & ts::ConstBuffer::operator= ( Buffer const &  that  )  [inline]

Assign from non-const Buffer.

Parameters:
that Source buffer.

Definition at line 340 of file TsBuffer.h.

References ts::Buffer::_ptr, _ptr, ts::Buffer::_size, and _size.

bool ts::ConstBuffer::operator== ( Buffer const &  that  )  const [inline]

Equality.

Returns:
true if that refers to the same memory as this, false otherwise.

Definition at line 341 of file TsBuffer.h.

References ts::Buffer::_ptr, _ptr, ts::Buffer::_size, and _size.

bool ts::ConstBuffer::operator== ( self const &  that  )  const [inline]

Equality.

Returns:
true if that refers to the same memory as this, false otherwise.

Definition at line 337 of file TsBuffer.h.

References _ptr, and _size.

char ts::ConstBuffer::operator[] ( int  n  )  const [inline]

Access a character (no bounds check).

Definition at line 358 of file TsBuffer.h.

References _ptr.

ConstBuffer & ts::ConstBuffer::reset (  )  [inline]

Reset to empty.

Definition at line 334 of file TsBuffer.h.

References _ptr, and _size.

Referenced by ats_ip_parse(), and ts::config::Path::Parser::parse().

ConstBuffer & ts::ConstBuffer::set ( char const *  ptr,
size_t  n = 0 
) [inline]

Set the chunk.

Any previous values are discarded.

Returns:
this object.
Parameters:
ptr Buffer address.
n Buffer size.

Definition at line 326 of file TsBuffer.h.

References _ptr, and _size.

Referenced by ats_ip_getbestaddrinfo(), ats_ip_pton(), ts::config::Path::Parser::parse(), and url_parse_internet().

ConstBuffer & ts::ConstBuffer::set ( char const *  start,
char const *  end 
) [inline]

Set from 2 pointers.

Note:
This presumes a half open range (start, end]
Parameters:
start First valid character.
end First invalid character.

Definition at line 328 of file TsBuffer.h.

References _ptr, and _size.

size_t ts::ConstBuffer::size ( void   )  const [inline]

Get the size of the buffer.

Definition at line 359 of file TsBuffer.h.

References _size.

Referenced by ats_ip_check_characters(), ats_ip_getbestaddrinfo(), ats_ip_pton(), Ink_Inet(), and LogHost::set_name_or_ipstr().

ConstBuffer ts::ConstBuffer::splitOn ( char  c  )  [inline]

Split the buffer on the character c.

The buffer is split in to two parts and the occurrence of c is discarded. this retains all data after c. The initial part of the buffer is returned. Neither buffer will contain the first occurrence of c.

This is convenient when tokenizing and c is the token separator.

Note:
If c is not found then this is not changed and an empty buffer is returned.
Returns:
A buffer containing data up to but not including p.

Definition at line 379 of file TsBuffer.h.

References find(), and splitOn().

ConstBuffer ts::ConstBuffer::splitOn ( char const *  p  )  [inline]

Split the buffer on the character at p.

The buffer is split in to two parts and the character at p is discarded. this retains all data after p. The initial part of the buffer is returned. Neither buffer will contain the character at p.

This is convenient when tokenizing and p points at the token separator.

Note:
If *p is in the buffer then this is not changed and an empty buffer is returned. This means the caller can simply pass the result of find and check for an empty buffer returned to detect no more separators.
Returns:
A buffer containing data up to but not including p.

Definition at line 364 of file TsBuffer.h.

References _ptr, _size, and contains().

Referenced by ats_ip_parse(), MIMEHdr::get_host_port_values(), and splitOn().


Field Documentation

char const* ts::ConstBuffer::_ptr

The documentation for this struct was generated from the following file: