[Orxonox-commit 1971] r6688 - code/branches/chat/src/orxonox
smerkli at orxonox.net
smerkli at orxonox.net
Mon Apr 12 15:15:44 CEST 2010
Author: smerkli
Date: 2010-04-12 15:15:44 +0200 (Mon, 12 Apr 2010)
New Revision: 6688
Modified:
code/branches/chat/src/orxonox/ChatHistory.cc
code/branches/chat/src/orxonox/ChatHistory.h
Log:
Completed and tested the code as far as I could, now preparing questions.
Modified: code/branches/chat/src/orxonox/ChatHistory.cc
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.cc 2010-04-12 12:57:28 UTC (rev 6687)
+++ code/branches/chat/src/orxonox/ChatHistory.cc 2010-04-12 13:15:44 UTC (rev 6688)
@@ -26,70 +26,89 @@
*
*/
-#include <ChatHistory.h>
+#include "ChatHistory.h"
+#ifndef TEST
namespace orxonox
{
+#endif
/* is this necessary? if yes uncomment please :P */
//CreateFactory(ChatHistory);
/* constructor */
+ #ifndef TEST
ChatHistory(BaseObject* creator) : BaseObject(creator)
+ #else
+ ChatHistory::ChatHistory()
+ #endif
{
/* register the object */
+ #ifndef TEST
RegisterObject(ChatHistory);
+ #endif
+ this->hist_log_enabled = true;
+
/* Read setting for logfiles */
- if( true ) /* NOTE Make this a check for the logfile setting */
- this->chat_hist_openlog();
+ if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */
+ { this->chat_hist_openlog();
+ /* push starting line */
+ this->chat_hist_logline( "--- Logfile opened ---" );
+ }
+
/* Read setting for maximum number of lines and set limit */
this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
-
- /* push starting line */
- this->hist_buffer.push_front( "--- Logfile opened ---" )
}
/* destructor */
- virtual ChatHistory::~ChatHistory()
+ ChatHistory::~ChatHistory()
{
- /* check if loggin is enabled */
- /* y -> synchronize the logfile */
+ chat_hist_closelog();
+
+ /* TODO clear list */
}
/* react to incoming chat */
- virtual void ChatHistory::incomingChat(const std::string& message,
+ void ChatHistory::incomingChat(const std::string& message,
unsigned int senderID)
{
/* sanity - check for valid senderID */
/* sanity - check for valid string format */
/* format the message and senderID into a line */
- std::string buf = "empty"; /* NOTE to be changed */
+ std::string buf = "" + senderID; /* NOTE to be changed */
+ /* TODO */
/* --> a) look up the actual name of the sender */
/* --> b) add sender name and string up with a separator
* to make up the actual message
*/
/* add the line to the history */
- this->chat_hist_addline( buf );
+ this->chat_hist_addline( buf + ": " + message );
/* add the line to the log */
- this->chat_hist_logline( buf );
+ this->chat_hist_logline( buf + ": " + message );
}
/* Synchronize logfile onto the hard drive */ /* MARK MARK */
- int ChatHistory::syncLog();
+ int ChatHistory::syncLog()
+ {
+ //if( this->hist_logfile )
+ //this->hist_logfile.sync();
+ }
/* add a line to this history */
- int ChatHistory::chat_hist_addline( const std::string& toadd );
+ int ChatHistory::chat_hist_addline( const std::string& toadd )
{
+ /* crop history at the end if it's too large */
+ while( this->hist_buffer.size() > this->hist_maxlines+1 )
+ this->hist_buffer.pop_front();
+
/* push to the front of the history */
- this->hist_buffer.push_front( toadd );
+ this->hist_buffer.push_back( toadd );
- /* crop history at the end if it's too large */
- this->hist_buffer.resize( this->hist_maxlines );
}
/* log a line to a logfile */
@@ -100,7 +119,7 @@
*/
/* output the line to the file if logging is enabled */
if( this->hist_log_enabled )
- this->hist_logfile << buf << std::endl;
+ this->hist_logfile << toadd << std::endl;
}
/* open logfile */
@@ -110,7 +129,7 @@
* and set the this->hist_logfile_path variable to it
*/
this->hist_logfile.open( "/tmp/setsomepath.txt",
- fstream::out | fstream::app );
+ std::fstream::out | std::fstream::app );
/* TODO check whether this works (not sure how you'd like it?) */
@@ -118,4 +137,29 @@
return 0;
}
+ /* close logfile */
+ void ChatHistory::chat_hist_closelog()
+ {
+ if( this->hist_logfile )
+ { this->chat_hist_logline( "--- Logfile closed ---" );
+ this->hist_logfile.close();
+ }
+ }
+
+ /* output history for debugging */
+ void ChatHistory::debug_printhist()
+ {
+ std::deque<std::string>::iterator it;
+
+ for( it = this->hist_buffer.begin(); it != this->hist_buffer.end();
+ ++it )
+ std::cout << *it << std::endl;
+
+ std::cout << "Size: " << hist_buffer.size() << std::endl;
+
+
+ }
+
+#ifndef TEST
}
+#endif
Modified: code/branches/chat/src/orxonox/ChatHistory.h
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.h 2010-04-12 12:57:28 UTC (rev 6687)
+++ code/branches/chat/src/orxonox/ChatHistory.h 2010-04-12 13:15:44 UTC (rev 6688)
@@ -26,24 +26,45 @@
*
*/
-#include <list>
+#include <deque>
+#include <string>
+#include <fstream>
+#include <iostream>
+
+#define TEST 0
+
+#ifndef TEST
#include <core/BaseObject.h>
+#endif
#ifndef _ChatHistory_H__
#define _ChatHistory_H__
+
/* Class to implement chat history */
+#ifndef TEST
namespace orxonox
{
+#endif
+
+ /* constructor */
+ #ifndef TEST
class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener
+ #else
+ class ChatHistory
+ #endif
{
public:
/* constructors, destructors */
+ #ifndef TEST
ChatHistory(BaseObject* creator);
+ #else
+ ChatHistory();
+ #endif
virtual ~ChatHistory();
- protected:
+ //protected:
/** what to do with incoming chat
*
* \param message The incoming message
@@ -57,11 +78,14 @@
* \return 0 for success, other for error
*/
int syncLog();
+
+ /** debug-print */
+ void debug_printhist();
private:
/* FIELDS */
/** Vector to store the history in */
- list<std::string> hist_buffer;
+ std::deque<std::string> hist_buffer;
/** Maximum number of lines stored in this history */
unsigned int hist_maxlines;
@@ -73,7 +97,7 @@
std::string hist_logfile_path;
/** Output file stream for logfile */
- ofstream hist_logfile;
+ std::ofstream hist_logfile;
@@ -98,8 +122,15 @@
* \return 0 for success,s other for error
*/
int chat_hist_openlog();
- }
+
+
+ /** close logfile */
+ void chat_hist_closelog();
+ };
+
+#ifndef TEST
}
+#endif
#endif /* _ChatHistory_H__ */
More information about the Orxonox-commit
mailing list