BSDL Device Tree Compiler
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | Protected Attributes | List of all members
dtc::input_buffer Class Reference
Inheritance diagram for dtc::input_buffer:
dtc::mmap_input_buffer dtc::stream_input_buffer

Public Member Functions

virtual ~input_buffer ()
 
 input_buffer ()
 
 input_buffer (const char *b, size_t s)
 
input_buffer buffer_from_offset (size_t offset, size_t s=0)
 
bool empty ()
 
char operator* ()
 
char operator[] (int offset)
 
input_bufferoperator++ ()
 
 operator const char * ()
 
bool consume (char c)
 
bool consume (const char *str)
 
bool consume_integer (long long &outInt)
 
template<typename T >
bool consume_binary (T &out)
 
bool consume_hex_byte (uint8_t &outByte)
 
input_buffernext_token ()
 
void parse_error (const char *msg)
 
void dump ()
 
template<>
bool consume_binary (uint8_t &out)
 

Protected Attributes

const char * buffer
 
size_t size
 

Detailed Description

Class encapsulating the input file. Can be used as a const char*, but has range checking. Attempting to access anything out of range will return a 0 byte. The input buffer can be cheaply copied, without copying the underlying memory, however it is the user's responsibility to ensure that such copies do not persist beyond the lifetime of the underlying memory.

This also contains methods for reporting errors and for consuming the token stream.

Constructor & Destructor Documentation

virtual dtc::input_buffer::~input_buffer ( )
inlinevirtual

Virtual destructor. Does nothing, but exists so that subclasses that own the memory can run cleanup code for deallocating it.

dtc::input_buffer::input_buffer ( )
inline

Constructs an empty buffer.

dtc::input_buffer::input_buffer ( const char *  b,
size_t  s 
)
inline

Constructs a new buffer with a specified memory region and size.

Member Function Documentation

input_buffer dtc::input_buffer::buffer_from_offset ( size_t  offset,
size_t  s = 0 
)
inline

Returns a new input buffer referring into this input, clamped to the specified size. If the requested buffer would fall outside the range of this one, then it returns an empty buffer.

The returned buffer shares the same underlying storage as the original. This is intended to be used for splitting up the various sections of a device tree blob. Requesting a size of 0 will give a buffer that extends to the end of the available memory.

bool dtc::input_buffer::consume ( char  c)
inline

Consumes a character. Moves the cursor one character forward if the next character matches the argument, returning true. If the current character does not match the argument, returns false.

bool dtc::input_buffer::consume ( const char *  str)
inline

Consumes a string. If the (null-terminated) string passed as the argument appears in the input, advances the cursor to the end and returns true. Returns false if the string does not appear at the current point in the input.

template<typename T >
bool dtc::input_buffer::consume_binary ( T &  out)
inline

Template function that consumes a binary value in big-endian format from the input stream. Returns true and advances the cursor if there is a value of the correct size. This function assumes that all values must be natively aligned, and so advances the cursor to the correct alignment before reading.

template<>
bool dtc::input_buffer::consume_binary ( uint8_t &  out)

Explicit specialisation for reading a single byte.

bool dtc::input_buffer::consume_hex_byte ( uint8_t &  outByte)
inline

Consumes two hex digits and return the resulting byte via the first argument. If the next two characters are hex digits, returns true and advances the cursor. If not, then returns false and leaves the cursor in place.

bool dtc::input_buffer::consume_integer ( long long &  outInt)
inline

Reads an integer in base 8, 10, or 16. Returns true and advances the cursor to the end of the integer if the cursor points to an integer, returns false and does not move the cursor otherwise.

The parsed value is returned via the argument.

void dtc::input_buffer::dump ( )
inline

Dumps the current cursor value and the unconsumed values in the input buffer to the standard error. This method is intended solely for debugging.

bool dtc::input_buffer::empty ( )
inline

Returns true if this buffer has no unconsumed space in it.

input_buffer& dtc::input_buffer::next_token ( )
inline

Advances the cursor to the start of the next token, skipping comments and whitespace. If the cursor already points to the start of a token, then this function does nothing.

dtc::input_buffer::operator const char * ( )
inline

Cast to char* operator. Returns a pointer into the buffer that can be used for constructing strings.

char dtc::input_buffer::operator* ( )
inline

Dereferencing operator, allows the buffer to be treated as a char* and dereferenced to give a character. This returns a null byte if the cursor is out of range.

input_buffer& dtc::input_buffer::operator++ ( )
inline

Increments the cursor, iterating forward in the buffer.

char dtc::input_buffer::operator[] ( int  offset)
inline

Array subscripting operator, returns a character at the specified index offset from the current cursor. The offset may be negative, to reread characters that have already been read. If the current cursor plus offset is outside of the range, this returns a nul byte.

void dtc::input_buffer::parse_error ( const char *  msg)
inline

Prints a message indicating the location of a parse error.

Member Data Documentation

const char* dtc::input_buffer::buffer
protected

The buffer. This class doesn't own the buffer, but the mmap_input_buffer subclass does.

size_t dtc::input_buffer::size
protected

The size of the buffer.


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