nidas  v1.2-1520
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
nidas::core::AsciiSscanf Class Reference

Class providing sscanf functionality for parsing ASCII data. More...

#include <AsciiSscanf.h>

Classes

struct  FormatField
 Information we determine from each conversion field in the sscanf format. More...
 

Public Types

enum  fieldtype {
  DOUBLE =258, FLOAT, INT, SHORT,
  CHAR, UINT, USHORT, LONG,
  ULONG, UNKNOWN
}
 

Public Member Functions

 AsciiSscanf ()
 
virtual ~AsciiSscanf ()
 
void setFormat (const std::string &val) throw (nidas::util::ParseException)
 Set the format to be used to sscanf samples. More...
 
const std::string & getFormat () const
 
void setSampleTag (SampleTag *val)
 
const SampleTaggetSampleTag () const
 
SampleTaggetSampleTag ()
 
int sscanf (const char *input, float *output, int nout) throw ()
 scan input, storing up to nout number of values into output, as floats. More...
 
int getNumberOfFields () const
 

Public Attributes

const int MAX_OUTPUT_VALUES
 Maximum number of fields that we can scan. More...
 

Private Member Functions

 AsciiSscanf (const AsciiSscanf &)
 No copying. More...
 
AsciiSscanfoperator= (const AsciiSscanf &)
 No assignment. More...
 

Private Attributes

std::string _format
 scanf format that we scan to count the number and type of % converters. More...
 
char * _charfmt
 Same scanf format, converted to character for quick use by sscanf. More...
 
int _lexpos
 Current lexical scanner position. More...
 
struct FormatField_currentField
 Pointer to current FormatField that we are scanning. More...
 
std::vector< FormatField * > _fields
 Information scanned from each field. More...
 
bool _allFloats
 Are all fields floats? More...
 
char * _databuf0
 A local buffer to store results of sscanf. More...
 
char ** _bufptrs
 Pointers into the local buffer for each field in the format string. More...
 
SampleTag_sampleTag
 A scanner may produce dsm samples. More...
 
AsciiSscanfAdapter_lexer
 

Friends

class AsciiSscanfAdapter
 

Detailed Description

Class providing sscanf functionality for parsing ASCII data.

One sets the sscanf format with setFormat then calls sscanf method. This class does a lexical parse of the sscanf conversion format string to determine the number and types of the conversions.

Member Enumeration Documentation

Enumerator
DOUBLE 
FLOAT 
INT 
SHORT 
CHAR 
UINT 
USHORT 
LONG 
ULONG 
UNKNOWN 

Constructor & Destructor Documentation

*********** AsciiSscanf::AsciiSscanf ( )
Initial value:
{LETTER} {
}
[ \t]+
Definition: AsciiSscanf.h:69

References _bufptrs, _lexer, and MAX_OUTPUT_VALUES.

AsciiSscanf::~AsciiSscanf ( )
virtual

References _bufptrs, _charfmt, _databuf0, _fields, and _lexer.

nidas::core::AsciiSscanf::AsciiSscanf ( const AsciiSscanf )
private

No copying.

Member Function Documentation

const std::string& nidas::core::AsciiSscanf::getFormat ( ) const
inline
int nidas::core::AsciiSscanf::getNumberOfFields ( ) const
inline
const SampleTag* nidas::core::AsciiSscanf::getSampleTag ( ) const
inline
SampleTag* nidas::core::AsciiSscanf::getSampleTag ( )
inline

References _sampleTag.

AsciiSscanf& nidas::core::AsciiSscanf::operator= ( const AsciiSscanf )
private

No assignment.

void AsciiSscanf::setFormat ( const std::string &  val)
throw (nidas::util::ParseException
)

Set the format to be used to sscanf samples.

Throws ParseException if there is a conversion field that it doesn't recognize. Supports the basic conversions: f, g, d, o, x, u, c. The 'l' flag can be used with f and g for converting to a double: lf. The 'h' flag can be used with the integer conversions for converting to a short int: hd. Each can also include a maximum field width. Each can also have the suppression flag ('*'). Example: "%*2c%f%f%*5c%x" skips two characters, converts 2 float fields, skips five characters, converts a hex value.

References UNKNOWN.

Referenced by nidas::core::CharacterSensor::init().

void nidas::core::AsciiSscanf::setSampleTag ( SampleTag val)
inline
int AsciiSscanf::sscanf ( const char *  input,
float *  output,
int  nout 
)
throw (
)

scan input, storing up to nout number of values into output, as floats.

If a conversion field is not for a float, like "%d", then the field is scanned into a the appropriate type (integer in this example) and then cast to a float. So a scanf of "99" with a "%d" will result in a float, with value 99.0.

References nidas::core::floatNAN, and UNKNOWN.

Referenced by nidas::dynld::TSI_CPC3772::process(), and nidas::core::CharacterSensor::scanSample().

Friends And Related Function Documentation

friend class AsciiSscanfAdapter
friend

Member Data Documentation

bool nidas::core::AsciiSscanf::_allFloats
private

Are all fields floats?

char** nidas::core::AsciiSscanf::_bufptrs
private

Pointers into the local buffer for each field in the format string.

The pointers are aligned appropriately for the type of the format conversion. The sscanf looks like so: sscanf(inputstr,format,bufptrs[0],bufptrs[1],bufptrs[2],...)

Referenced by AsciiSscanf(), and ~AsciiSscanf().

char* nidas::core::AsciiSscanf::_charfmt
private

Same scanf format, converted to character for quick use by sscanf.

Referenced by ~AsciiSscanf().

struct FormatField* nidas::core::AsciiSscanf::_currentField
private

Pointer to current FormatField that we are scanning.

char* nidas::core::AsciiSscanf::_databuf0
private

A local buffer to store results of sscanf.

Referenced by ~AsciiSscanf().

std::vector<FormatField*> nidas::core::AsciiSscanf::_fields
private

Information scanned from each field.

Referenced by getNumberOfFields(), and ~AsciiSscanf().

std::string nidas::core::AsciiSscanf::_format
private

scanf format that we scan to count the number and type of % converters.

This format is then used to do sscanf's on ASCII data coming from a sensor.

Referenced by getFormat().

AsciiSscanfAdapter* nidas::core::AsciiSscanf::_lexer
private

Referenced by AsciiSscanf(), and ~AsciiSscanf().

int nidas::core::AsciiSscanf::_lexpos
private

Current lexical scanner position.

SampleTag* nidas::core::AsciiSscanf::_sampleTag
private

A scanner may produce dsm samples.

sampleTag points to to SampleTag describing the samples produced.

Referenced by getSampleTag(), and setSampleTag().

const int nidas::core::AsciiSscanf::MAX_OUTPUT_VALUES

Maximum number of fields that we can scan.

Referenced by AsciiSscanf().


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