#include "Msg.h" #include #include #include #include "MsgPipePuts.h" Msg msg(new MsgPipePuts()); Msg::Msg() { pipe =NULL; indentLevel=0; indentState=0; } Msg::Msg(MsgPipe *pipein) { pipe = pipein; indentLevel=0; indentState=0; } Msg::~Msg() { } // Fix up all strings for indention and unindention void Msg::indentFilter(char *str) { // Build correct output string char newstr[1024]=""; if (!indentState) for (short i=0;iprint(newstr); // Set the indentState correctly if (str[strlen(str)-1]=='\n') // If (End-Of-Line) indentState=0; else indentState=1; } Msg &Msg::print(char *str) { indentFilter(str); indentFilter("\n"); return *this; } Msg &Msg::printRaw(char *str) { indentFilter(str); return *this; } Msg &Msg::print(int val) { char s[1024]; sprintf(s,"%d ",val); indentFilter(s); return *this; } Msg &Msg::printRaw(int val) { char s[1024]; sprintf(s,"%d",val); indentFilter(s); return *this; } Msg &Msg::print(float val) { char s[1024]; sprintf(s,"%f ",val); indentFilter(s); return *this; } Msg &Msg::printRaw(float val) { char s[1024]; sprintf(s,"%f",val); indentFilter(s); return *this; } Msg &Msg::err(char *str) { char s[1024]; sprintf(s,"\nERR: %s\n\n",str); pipe->print(s); return *this; } void Msg::halt(char *str) { err(str); exit(2); } Msg &Msg::indent(short lvls) { if (lvls==0) indentLevel=0; else indentLevel += lvls; if (indentLevel<0) indentLevel =0; return *this; } Msg &Msg::unindent() { indent(-1); return *this; } // Returns the previous top pipe // Also chains the previous to the new pipe MsgPipe *Msg::pushPipe(MsgPipe *newpipe) { newpipe->nextPipe=pipe; pipe=newpipe; return newpipe->nextPipe; } // Returns the popped pipe MsgPipe *Msg::popPipe() { MsgPipe *oldpipe = pipe; if (pipe!=NULL) pipe = pipe->nextPipe; return oldpipe; }