friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
+ typedef const std::initializer_list<std::pair<std::string,std::string>> & HeaderInitializerList;
+
public:
/** "ACK" command. */
static const std::string & ackCommand();
/** "ERROR" command. */
static const std::string & errorCommand();
+ /** "_ENOMETHOD" command. */
+ static const std::string & enomethodCommand();
public:
/** Default exception type */
/** Ctor taking command and body
* \throw PluginFrameException If \ref setCommand throws
*/
- PluginFrame( const std::string & command_r, const std::string body_r );
+ PluginFrame( const std::string & command_r, const std::string & body_r );
+
+ /** Ctor taking the command and a HeaderInitializerList
+ * \throw PluginFrameException If \ref setCommand throws
+ */
+ PluginFrame( const std::string & command_r, HeaderInitializerList contents_r );
+
+ /** Ctor taking command, body and a HeaderInitializerList
+ * \throw PluginFrameException If \ref setCommand throws
+ */
+ PluginFrame( const std::string & command_r, const std::string & body_r, HeaderInitializerList contents_r );
/** Ctor reading frame data from a stream
* \throw PluginFrameException On error reading from stream
/** Whether this is an empty frame. */
bool empty() const;
- /** Evaluate in a boolean context (empty frame) */
+ /** Evaluate in a boolean context (not an empty frame) */
explicit operator bool() const
- { return empty(); }
+ { return !empty(); }
public:
/** Return the frame command. */
bool isErrorCommand() const
{return command() == errorCommand(); }
+ /** Convenience to identify an _ENOMETHOD command. */
+ bool isEnomethodCommand() const
+ {return command() == enomethodCommand(); }
+
/** Return the frame body. */
const std::string & body() const;
/** Whether the header list contains at least one entry for \c key_r. */
bool hasKey( const std::string & key_r ) const
- { return keyEmpty( key_r ); }
+ { return ! keyEmpty( key_r ); }
/** \overload */
bool keyEmpty( const std::string & key_r ) const
{ return headerList().find( key_r ) == headerEnd(); }
- /** Return number of header entires for \c key_r. */
+ /** Return number of header entries for \c key_r. */
bool keySize( const std::string & key_r ) const
{ return headerList().count( key_r ); }
/** Not throwing version returing one of the matching header values or \c default_r string. */
const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
- /** Set header for \c key_r removing all other occurences of \c key_r.
+ /** Set header for \c key_r removing all other occurrences of \c key_r.
* \throw PluginFrameException If key contains illegal chars (\c NL or \c :)
* \throw PluginFrameException If value contains illegal chars (\c NL)
*/
void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
+ /** Set a new header list
+ * \throw PluginFrameException If key contains illegal chars (\c NL or \c :)
+ * \throw PluginFrameException If value contains illegal chars (\c NL)
+ */
+ void setHeader( HeaderInitializerList contents_r )
+ { headerList().clear(); addHeader( contents_r ); }
+
/** Add header for \c key_r leaving already existing headers for \c key_r unchanged.
* \throw PluginFrameException If key contains illegal chars (\c NL or \c :)
* \throw PluginFrameException If value contains illegal chars (\c NL)
*/
void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
+ /** \overload taking an initializer_list */
+ void addHeader( HeaderInitializerList contents_r );
/** Remove all headers for \c key_r. */
void clearHeader( const std::string & key_r );
/** \relates PluginFrame Stream output for logging */
std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
- /** \relates PluginFrame Stream output sending all data */
+ /** \relates PluginFrame Stream output writing all data for logging (no throw) */
inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
- { return PluginFrame::writeTo( str, obj ); }
+ { if ( str ) try { PluginFrame::writeTo( str, obj ); } catch(...){}; return str; }
/** \relates PluginFrame Construct from stream. */
inline std::istream & operator>>( std::istream & str, PluginFrame & obj )