• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# A game debug console - help

## Recommended Posts

I have this little game debug console thing. It all works nice and fins and everything, I just want to simplyfy the syntax for it. The way I have it now, you can just spit messages out to the console, like so sConsole() << "here is some message"; sConsole().End(); The End() method adds the constructed string finally to the console, and prepares for another msg, etc. what I want to be able to do is sConsole() << "here is some message" << End(); But I cannot figure out for the life of me the syntax to allow this to work. Any help? btw - I dont just have an ''End'' function, I have other functions such as changing the current color of the text, etc... -Vulcan

##### Share on other sites
Simple.

  // struct that is used to set the colorstruct SetColor{    int mColor;  // actual color value    // constructor that initializes member     SetColor(const int nColor) : mColor(nColor)    {}    // convert to integer    const operator int() const    {        return mColor;    }};// just an empty typestruct End {};class Console{     // other stuff here     void SetColor(cont int nColor)     {         // change our text color for output here     }     // text output     Console& operator << (const string& strText)     {         // call your printing function here         return *this;     }     // end output     Console& operator << (const End& sEnd)     {         return (*this << "\n"; // or whatever you use to end     }          // change output color     Console& operator << (const SetColor& sColor)     {         SetTextColor(sColor);         return *this;     }};// usage exampleConsole sColor;sColor << "This is a " << SetColor(GREEN) << "green" << SetColor(GREY) << " text" << End();

Just my 0.02€,
Pat

##### Share on other sites
Ohhhhhhh I see now.... so the End() would not actually be a method but a struct/class called End but then overloaded by the Console so simply end the line?

thanks much for the help, i was thinking it would be more of a method than overloading for a constructed object

thx
-Vulcan

[edited by - Vulcan on January 29, 2003 9:17:15 PM]

##### Share on other sites
Actually, I was gonna post my SDL based pluggable console here in a bit, but what I did for it was this:

  class SDL_Console{public:  // some stuff  // Stream operators  enum OpFlag   {    Flush = 0x01,    Exec = 0x02,    Term = Flush | Exec  };    SDL_Console& operator<<(OpFlag op);  // some other stuff};SDL_Console& SDL_Console::operator<<(SDL_Console::OpFlag of){  if(of & Exec)    Execute(m_stringBuffer.str());  if(of & Flush)  {    Out(m_stringBuffer.str());    m_stringBuffer.str("");  }  return *this;}

That way, you can do things like:

  con << "echo here" << SDL_Console::Term;// output: "here"con << "echo this" << SDL_Console::Exec << " is a test" << Flush;// output: this// output: echo this is a test

I hope that makes sense.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627661
• Total Posts
2978496

• 10
• 12
• 22
• 13
• 33