Changeset 6688 for code/branches/chat/src/orxonox/ChatHistory.cc
- Timestamp:
- Apr 12, 2010, 3:15:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/chat/src/orxonox/ChatHistory.cc
r6652 r6688 27 27 */ 28 28 29 #include <ChatHistory.h>29 #include "ChatHistory.h" 30 30 31 #ifndef TEST 31 32 namespace orxonox 32 33 { 34 #endif 33 35 /* is this necessary? if yes uncomment please :P */ 34 36 //CreateFactory(ChatHistory); 35 37 36 38 /* constructor */ 39 #ifndef TEST 37 40 ChatHistory(BaseObject* creator) : BaseObject(creator) 41 #else 42 ChatHistory::ChatHistory() 43 #endif 38 44 { 39 45 /* register the object */ 46 #ifndef TEST 40 47 RegisterObject(ChatHistory); 48 #endif 49 50 this->hist_log_enabled = true; 41 51 42 52 /* Read setting for logfiles */ 43 if( true ) /* NOTE Make this a check for the logfile setting */ 44 this->chat_hist_openlog(); 53 if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */ 54 { this->chat_hist_openlog(); 55 56 /* push starting line */ 57 this->chat_hist_logline( "--- Logfile opened ---" ); 58 } 45 59 46 60 /* Read setting for maximum number of lines and set limit */ 47 61 this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */ 48 49 /* push starting line */50 this->hist_buffer.push_front( "--- Logfile opened ---" )51 62 } 52 63 53 64 /* destructor */ 54 virtualChatHistory::~ChatHistory()65 ChatHistory::~ChatHistory() 55 66 { 56 /* check if loggin is enabled */ 57 /* y -> synchronize the logfile */ 67 chat_hist_closelog(); 68 69 /* TODO clear list */ 58 70 } 59 71 60 72 /* react to incoming chat */ 61 v irtual void ChatHistory::incomingChat(const std::string& message,73 void ChatHistory::incomingChat(const std::string& message, 62 74 unsigned int senderID) 63 75 { … … 66 78 67 79 /* format the message and senderID into a line */ 68 std::string buf = " empty"; /* NOTE to be changed */80 std::string buf = "" + senderID; /* NOTE to be changed */ 69 81 82 /* TODO */ 70 83 /* --> a) look up the actual name of the sender */ 71 84 /* --> b) add sender name and string up with a separator … … 74 87 75 88 /* add the line to the history */ 76 this->chat_hist_addline( buf );89 this->chat_hist_addline( buf + ": " + message ); 77 90 78 91 /* add the line to the log */ 79 this->chat_hist_logline( buf );92 this->chat_hist_logline( buf + ": " + message ); 80 93 } 81 94 82 95 /* Synchronize logfile onto the hard drive */ /* MARK MARK */ 83 int ChatHistory::syncLog(); 96 int ChatHistory::syncLog() 97 { 98 //if( this->hist_logfile ) 99 //this->hist_logfile.sync(); 100 } 84 101 85 102 /* add a line to this history */ 86 int ChatHistory::chat_hist_addline( const std::string& toadd ) ;103 int ChatHistory::chat_hist_addline( const std::string& toadd ) 87 104 { 105 /* crop history at the end if it's too large */ 106 while( this->hist_buffer.size() > this->hist_maxlines+1 ) 107 this->hist_buffer.pop_front(); 108 88 109 /* push to the front of the history */ 89 this->hist_buffer.push_ front( toadd );110 this->hist_buffer.push_back( toadd ); 90 111 91 /* crop history at the end if it's too large */92 this->hist_buffer.resize( this->hist_maxlines );93 112 } 94 113 … … 101 120 /* output the line to the file if logging is enabled */ 102 121 if( this->hist_log_enabled ) 103 this->hist_logfile << buf<< std::endl;122 this->hist_logfile << toadd << std::endl; 104 123 } 105 124 … … 111 130 */ 112 131 this->hist_logfile.open( "/tmp/setsomepath.txt", 113 fstream::out |fstream::app );132 std::fstream::out | std::fstream::app ); 114 133 115 134 /* TODO check whether this works (not sure how you'd like it?) */ … … 119 138 } 120 139 140 /* close logfile */ 141 void ChatHistory::chat_hist_closelog() 142 { 143 if( this->hist_logfile ) 144 { this->chat_hist_logline( "--- Logfile closed ---" ); 145 this->hist_logfile.close(); 146 } 147 } 148 149 /* output history for debugging */ 150 void ChatHistory::debug_printhist() 151 { 152 std::deque<std::string>::iterator it; 153 154 for( it = this->hist_buffer.begin(); it != this->hist_buffer.end(); 155 ++it ) 156 std::cout << *it << std::endl; 157 158 std::cout << "Size: " << hist_buffer.size() << std::endl; 159 160 161 } 162 163 #ifndef TEST 121 164 } 165 #endif
Note: See TracChangeset
for help on using the changeset viewer.