#ifndef __FORMAT_H__
#define __FORMAT_H__
#include "MString.h"
#include "simple_stack.h"
#include "i_integer.h"
class PrintAddress {
public:
virtual String get_pointer_as_string(void *addr) = 0;
virtual ~PrintAddress() {}
};
// This class supports output of formatted text in a simple
// minded way.
//
// Typical entries consist of the form
//
// StartBlock
// Text with Separator calls
// EndBlock
//
// A typical use of this might be
// SuifObject *something;
// FormattedText txt;
// something->print(txt);
// String s = txt.get_value();
//
class TextBlock;
class FormattedText
{
int max_line;
int indent;
bool no_line_merge;
int max_header_len;
TextBlock *root;
TextBlock *current;
public:
FormattedText( int maxline = 80,
int the_indent = 4,
bool nolinemerge=false);
String pointer_header(class String, void *);
void set_use_diff_mode(bool diff); // set to use diff mode
void set_special_print_mode(PrintAddress *p); // or your own pointer print
~FormattedText();
void start_block(const String &title);
void set_value(const String &val);
void set_value(const LString &val);
void set_value(int i);
void set_value(bool b);
void set_value(long l);
void set_value(double d);
void set_value(LString &l);
void set_value(const char *c);
void set_value(const IInteger &v);
void set_value(const void *p);
void end_block();
int get_indent(int cur,TextBlock *block) const;
int total_len(TextBlock *block) const;
String get_value() const;
String get_value(const String cur_pad,const String indent,bool no_newlines,TextBlock *block) const;
private:
PrintAddress* _pa;
FormattedText(const FormattedText &);
FormattedText &operator=(const FormattedText &);
};
#endif