Public Types | Public Member Functions

Configuration_Stream_Converter Class Reference

Class is used to convert streams containing network configuration from text to binary and vice-versa. More...

#include <Configuration_Stream_Converter.h>

Inheritance diagram for Configuration_Stream_Converter:
Inheritance graph
[legend]
Collaboration diagram for Configuration_Stream_Converter:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Mode { convert_from_text, convert_from_binary }
 

List of possible conversion directions.

More...

Public Member Functions

virtual int Read (char *buf, size_t count, size_t *read)
 This is how data gets converted from input stream. User should provide sufficient buffer for Read() method to hold the converted data (there is no way to read the same data twice if first time read failed e.g. because of too small buffer).
virtual int Write (char *buf, size_t count, size_t *written)
 Not supported.
virtual int Flush ()
 Flushes the internal buffer, useful when you need to make sure the data is passed to the Stream backend (could be some file) from Stream internal buffer.
void Set_Mode (Mode conversion_mode)
 Sets direction of conversion: text->binary or binary->text.
void Set_Input_Stream (Simple_Stream< char > *input_stream)
 Sets a stream to serve as the source of data to convert.

Detailed Description

Class is used to convert streams containing network configuration from text to binary and vice-versa.

Text parser works very simple: it reads text entries from whitespace to next whitespace or EOF (e.g. "hell o world" contains 3 tokens: "hell", "o" and "world").
Then it tries to recognize integer or floating point number in the read sequence. If number is recognized then either sizeof(int) or sizeof(double) number of bytes are returned. If chars sequence is not recognized as a number it is returned as text unconverted.
Please note that chars sequences of length sizeof(int) and sizeof(double) should not be used for something other than numbers because binary to text conversion of such sequences will treat the sequence as a number and will try to convert a simple string of text to some number.
Int/double/text recognition when converting from binary is based on size for simplicity (if binary length is sizeof(int) then we have an int, etc.).


Member Enumeration Documentation

enum Mode

List of possible conversion directions.

Enumerator:
convert_from_text 

text->binary

convert_from_binary 

binary->text

MCPN Logo
kr0st © 2010