AMOS::Message_t Class Reference

A generic AMOS message object for reading and writing data. More...

#include <Message_AMOS.hh>

List of all members.

Public Types

typedef HASHMAP::hash_map<
NCode_t, std::string >::const_iterator 
const_iterator

Public Member Functions

 Message_t ()
 Constructs an empty Message_t.
 ~Message_t ()
 Destroys a Message_t object.
const_iterator begin () const
 Returns a const_iterator to the beginning of the field map.
const_iterator end () const
 Returns a const_iterator to the end of the field map.
void clear ()
 Clears the message.
Size_t countFields () const
 Returns the number of top-level fields in the message.
Size_t countSubMessages () const
 Returns the number of top-level sub-messages in the message.
bool empty () const
 Returns true if the message has no fields or sub messages.
bool exists (NCode_t fcode) const
 Checks for the existence of a field by NCode.
bool exists (const std::string &fname) const
 Checks for the existence of a field by name.
const std::string & getField (NCode_t fcode) const
 Gets field data by field NCode.
const std::string & getField (const std::string &fname) const
 Gets field data by field name.
const std::vector< Message_t > & getSubMessages () const
 Get the vector of submessages for this message.
std::vector< Message_t > & getSubMessages ()
 Get the vector of submessages for this message.
NCode_t getMessageCode () const
 Get the NCode type of this message.
const std::string & operator[] (NCode_t fcode) const
 operator for getField method
const std::string & operator[] (const std::string &fname) const
bool read (std::istream &in)
 Read a message from an input stream.
void removeField (NCode_t fcode)
 Removes a field from the message object by NCode.
void removeField (const std::string &fname)
 Removes a field from the message object.
void setSubMessages (const std::vector< Message_t > &subs)
 Set the vector of submessages for this message.
void setField (NCode_t fcode, const std::string &data)
 Set field data by field NCode.
void setField (const std::string &fname, const std::string &data)
 Set field data by field name.
void setMessageCode (NCode_t mcode)
 Set the NCode type code of this message.
void setMessageCode (const std::string &mname)
 Set the NCode type name of this message.
void write (std::ostream &out) const
 Write the message object to an output stream.

Static Public Member Functions

static NCode_t skip (std::istream &in)
 Skips a message in an input stream, returning its NCode.


Detailed Description

A generic AMOS message object for reading and writing data.

Based on the Celera 3-code format, the AMOS 'NCode' messages are designed for easy parsing and compatibility with the other AMOS modules. This generic message class makes no assumptions about the type of data to be stored within, so it can be used for reading and writing ANY type of ASCII record in NCode format. The main duty of this class is to understand and validate incoming or outgoing NCode format.

Definition at line 100 of file Message_AMOS.hh.


Member Typedef Documentation

typedef HASHMAP::hash_map<NCode_t,std::string>::const_iterator AMOS::Message_t::const_iterator

Definition at line 112 of file Message_AMOS.hh.


Constructor & Destructor Documentation

AMOS::Message_t::Message_t (  )  [inline]

Constructs an empty Message_t.

Definition at line 118 of file Message_AMOS.hh.

References AMOS::M_NULL.

AMOS::Message_t::~Message_t (  )  [inline]

Destroys a Message_t object.

Definition at line 127 of file Message_AMOS.hh.


Member Function Documentation

const_iterator AMOS::Message_t::begin (  )  const [inline]

Returns a const_iterator to the beginning of the field map.

Iterator is of the type hash_map<NCode_t,std::string>::const_iterator. Access NCode with `itr -> first` and data with `itr -> second`.

Returns:
A const_iterator to the beginning of the field map

Definition at line 141 of file Message_AMOS.hh.

void AMOS::Message_t::clear (  )  [inline]

Clears the message.

Returns:
void

Definition at line 166 of file Message_AMOS.hh.

References AMOS::M_NULL.

Size_t AMOS::Message_t::countFields (  )  const [inline]

Returns the number of top-level fields in the message.

Returns:
The number of top-level fields in the message

Definition at line 179 of file Message_AMOS.hh.

Size_t AMOS::Message_t::countSubMessages (  )  const [inline]

Returns the number of top-level sub-messages in the message.

Returns:
The number of top-level sub-messages in the message

Definition at line 190 of file Message_AMOS.hh.

bool AMOS::Message_t::empty (  )  const [inline]

Returns true if the message has no fields or sub messages.

Returns:
True if the message is empty, else false

Definition at line 201 of file Message_AMOS.hh.

const_iterator AMOS::Message_t::end (  )  const [inline]

Returns a const_iterator to the end of the field map.

Iterator is of the type hash_map<NCode_t,std::string>::const_iterator. Access NCode with `itr -> first` and data with `itr -> second`.

Returns:
A const_iterator to the end of the field map

Definition at line 155 of file Message_AMOS.hh.

Referenced by exists(), and getField().

bool AMOS::Message_t::exists ( const std::string &  fname  )  const [inline]

Checks for the existence of a field by name.

Parameters:
fname Check for a field with this name
Returns:
true if exists, false if otherwise

Definition at line 225 of file Message_AMOS.hh.

References AMOS::Encode(), and exists().

bool AMOS::Message_t::exists ( NCode_t  fcode  )  const [inline]

Checks for the existence of a field by NCode.

Parameters:
fcode Check for a field with this NCode
Returns:
true if exists, false if otherwise

Definition at line 213 of file Message_AMOS.hh.

References end().

Referenced by exists().

const std::string& AMOS::Message_t::getField ( const std::string &  fname  )  const [inline]

Gets field data by field name.

Will return the field data, or throws an exception if the field does not exist. You can check if the field exists first with the exists method.

Parameters:
fname Get field data with this field name
Precondition:
The field name exists in the current message
Exceptions:
ArgumentException_t 
Returns:
The field data for fname

Definition at line 264 of file Message_AMOS.hh.

References AMOS::Encode(), and getField().

const std::string& AMOS::Message_t::getField ( NCode_t  fcode  )  const [inline]

Gets field data by field NCode.

Will return the field data, or throws an exception if the field does not exist. You can check if the field exists first with the exists method.

Parameters:
fcode Get field data with this field NCode
Precondition:
The field code exists in the current message
Exceptions:
ArgumentException_t 
Returns:
The field data for fcode

Definition at line 242 of file Message_AMOS.hh.

References AMOS_THROW_ARGUMENT, AMOS::Decode(), and end().

Referenced by getField(), and operator[]().

NCode_t AMOS::Message_t::getMessageCode (  )  const [inline]

Get the NCode type of this message.

Will return M_NULL if the message has not been assigned a type name yet. NCode can be decoded to a string with the 'AMOSDecode' function.

Returns:
The NCode type of this message

Definition at line 300 of file Message_AMOS.hh.

std::vector<Message_t>& AMOS::Message_t::getSubMessages (  )  [inline]

Get the vector of submessages for this message.

Returns:
The vector of submessages for this message

Definition at line 286 of file Message_AMOS.hh.

const std::vector<Message_t>& AMOS::Message_t::getSubMessages (  )  const [inline]

Get the vector of submessages for this message.

Returns:
The vector of submessages for this message

Definition at line 275 of file Message_AMOS.hh.

const std::string& AMOS::Message_t::operator[] ( const std::string &  fname  )  const [inline]

Definition at line 314 of file Message_AMOS.hh.

References getField().

const std::string& AMOS::Message_t::operator[] ( NCode_t  fcode  )  const [inline]

operator for getField method

Definition at line 309 of file Message_AMOS.hh.

References getField().

bool AMOS::Message_t::read ( std::istream &  in  ) 

Read a message from an input stream.

Reads a message from an input stream and populates the message fields with the values read from the stream. Will throw an exception if a message is found, but is not properly formatted.

Parameters:
in The input stream to read from
Precondition:
The incoming message is properly formatted
Exceptions:
IOException_t 
Returns:
true if a message was read, false if no message read (EOF)

void AMOS::Message_t::removeField ( const std::string &  fname  )  [inline]

Removes a field from the message object.

Removes a field from the message. Has no effect if the field name does not exist or is improperly formatted.

Parameters:
fname The field name to remove
Returns:
void

Definition at line 359 of file Message_AMOS.hh.

References AMOS::Encode(), and removeField().

void AMOS::Message_t::removeField ( NCode_t  fcode  )  [inline]

Removes a field from the message object by NCode.

Removes a field from the message by its NCode. Has no effect if the field code does not exist.

Parameters:
fcode The field NCode to remove
Returns:
void

Definition at line 344 of file Message_AMOS.hh.

Referenced by removeField().

void AMOS::Message_t::setField ( const std::string &  fname,
const std::string &  data 
) [inline]

Set field data by field name.

Will set a new, or overwrite and existing field with the supplied data. Throws an exception for an improperly formatted 3-code field name or an improperly formated data record (i.e. a multi-line record that does not end in a newline).

Parameters:
fname The field name
data The new field data
Precondition:
The field name is 3 chars

The data field ends in '
' if it is multiple lines

Exceptions:
ArugmentException_t 
Returns:
void

Definition at line 409 of file Message_AMOS.hh.

References AMOS::Encode(), and setField().

void AMOS::Message_t::setField ( NCode_t  fcode,
const std::string &  data 
)

Set field data by field NCode.

Will set a new, or overwrite and existing field with the supplied data. Throws an exception for an improperly formatted data record (i.e. a multi-line record that does not end in a newline). If the data string is empty, the field will be ignored and will remain uninitialized.

Parameters:
fcode The field NCode
data The new field data
Precondition:
The data field ends in '
' if it is multiple lines
Exceptions:
ArugmentException_t 
Returns:
void

Referenced by setField().

void AMOS::Message_t::setMessageCode ( const std::string &  mname  )  [inline]

Set the NCode type name of this message.

Will throw an exception if the name is improperly formatted.

Parameters:
mname The new NCode type name of this message
Precondition:
The type name is 3 chars
Exceptions:
ArgumentException_t 
Returns:
void

Definition at line 437 of file Message_AMOS.hh.

References AMOS::Encode(), and setMessageCode().

void AMOS::Message_t::setMessageCode ( NCode_t  mcode  )  [inline]

Set the NCode type code of this message.

Parameters:
mcode The new NCode type of this message
Returns:
void

Definition at line 421 of file Message_AMOS.hh.

Referenced by setMessageCode().

void AMOS::Message_t::setSubMessages ( const std::vector< Message_t > &  subs  )  [inline]

Set the vector of submessages for this message.

Parameters:
subs The new vector of submessages
Returns:
void

Definition at line 371 of file Message_AMOS.hh.

static NCode_t AMOS::Message_t::skip ( std::istream &  in  )  [static]

Skips a message in an input stream, returning its NCode.

Skips a message in an input stream, returning its NCode. Will throw an exception if a message is found, but its nesting is not properly formatted. However, complete validation is not performed. Use read method to assure proper formatting.

Parameters:
in The input stream to read from
Precondition:
The incoming message code and nesting are properly formatted
Postcondition:
Information already stored in the message object will not be changed

The istream is repositioned at the beginning of the next message

Exceptions:
IOException_t 
Returns:
NCode of the skipped message, or NULL_NCODE if no message found

void AMOS::Message_t::write ( std::ostream &  out  )  const

Write the message object to an output stream.

Writes the NCode ASCII representation of this object to the supplied output stream. Will throw an exception if there was an error trying to write to the stream.

Parameters:
out The output stream to write to
Precondition:
The ostream is open and writable
Exceptions:
IOException_t 
Returns:
void


The documentation for this class was generated from the following file:
Generated on Mon Feb 22 17:36:37 2010 for libAMOS by  doxygen 1.4.7