oasys::Formatter Class Reference

#include <Formatter.h>

Inheritance diagram for oasys::Formatter:

dtn::Bundle dtn::Link dtn::RouteEntry oasys::ByteBufShim oasys::IntShim oasys::NullStringShim oasys::RefCountedObject oasys::SparseBitmap< _inttype_t > oasys::StringShim oasys::UIntShim List of all members.

Detailed Description

This class is intended to be used with a modified implementation of snprintf/vsnprintf, defined in Formatter.cc.

The modification implements a special control code combination of '*p' that triggers a call to Formatter::format(), called on the object pointer passed in the vararg list.

For example:

 class FormatterTest : public Formatter {
 public:
     virtual int format(char* buf, size_t sz) {
         return snprintf(buf, sz, "FormatterTest");
     }
 };

 FormatterTest f;
 char buf[256];
 snprintf(buf, sizeof(buf), "pointer %p, format *%p\n");
 // buf contains "pointer 0xabcd1234, format FormatterTest\n"

Definition at line 53 of file Formatter.h.

Public Member Functions

virtual int format (char *buf, size_t sz) const =0
 Virtual callback, called from this vsnprintf implementation whenever it encounters a format string of the form "*%p".
int debug_dump ()
 Print out to a statically allocated buffer which can be called from gdb.
virtual ~Formatter ()
 Formatter ()
 Formatter (const Formatter &)

Static Public Member Functions

static void assert_valid (const Formatter *obj)
 Assertion check to make sure that obj is a valid formatter.

Public Attributes

unsigned int format_magic_


Constructor & Destructor Documentation

virtual oasys::Formatter::~Formatter (  )  [inline, virtual]

Definition at line 85 of file Formatter.h.

oasys::Formatter::Formatter (  )  [inline]

Definition at line 89 of file Formatter.h.

oasys::Formatter::Formatter ( const Formatter  )  [inline]

Definition at line 90 of file Formatter.h.


Member Function Documentation

virtual int oasys::Formatter::format ( char *  buf,
size_t  sz 
) const [pure virtual]

Virtual callback, called from this vsnprintf implementation whenever it encounters a format string of the form "*%p".

The output routine must not write more than sz bytes and is not null terminated.

Returns:
The number of bytes written, or the number of bytes that would have been written if the output is truncated.
XXX/bowei -- this contract is fairly annoying to implement.

Implemented in oasys::IntShim, oasys::UIntShim, oasys::StringShim, oasys::NullStringShim, oasys::ByteBufShim, oasys::RefCountedObject, oasys::SparseBitmap< _inttype_t >, dtn::Bundle, dtn::Contact, dtn::Link, and dtn::RouteEntry.

void oasys::Formatter::assert_valid ( const Formatter obj  )  [inline, static]

Assertion check to make sure that obj is a valid formatter.

This basically just makes sure that in any multiple inheritance situation where each base class has virtual functions, Formatter _must_ be the first class in the inheritance chain.

Definition at line 103 of file Formatter.h.

References oasys::__log_assert(), FORMAT_MAGIC, and format_magic_.

int oasys::Formatter::debug_dump (  ) 

Print out to a statically allocated buffer which can be called from gdb.

Note: must not be inlined in order for gdb to be able to execute this function.


Member Data Documentation

unsigned int oasys::Formatter::format_magic_

Definition at line 91 of file Formatter.h.

Referenced by assert_valid().


The documentation for this class was generated from the following file:
Generated on Thu Jun 7 16:56:59 2007 for DTN Reference Implementation by  doxygen 1.5.1