Changeset 6688 for code/branches/chat/src/orxonox
- Timestamp:
- Apr 12, 2010, 3:15:44 PM (15 years ago)
- Location:
- code/branches/chat/src/orxonox
- Files:
-
- 2 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 -
code/branches/chat/src/orxonox/ChatHistory.h
r6652 r6688 27 27 */ 28 28 29 #include <list> 29 #include <deque> 30 #include <string> 31 #include <fstream> 32 #include <iostream> 33 34 #define TEST 0 35 36 #ifndef TEST 30 37 #include <core/BaseObject.h> 38 #endif 31 39 32 40 #ifndef _ChatHistory_H__ 33 41 #define _ChatHistory_H__ 34 42 43 35 44 /* Class to implement chat history */ 45 #ifndef TEST 36 46 namespace orxonox 37 47 { 48 #endif 49 50 /* constructor */ 51 #ifndef TEST 38 52 class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener 53 #else 54 class ChatHistory 55 #endif 39 56 { 40 57 public: 41 58 /* constructors, destructors */ 59 #ifndef TEST 42 60 ChatHistory(BaseObject* creator); 61 #else 62 ChatHistory(); 63 #endif 43 64 virtual ~ChatHistory(); 44 65 45 66 46 protected:67 //protected: 47 68 /** what to do with incoming chat 48 69 * … … 58 79 */ 59 80 int syncLog(); 81 82 /** debug-print */ 83 void debug_printhist(); 60 84 61 85 private: 62 86 /* FIELDS */ 63 87 /** Vector to store the history in */ 64 list<std::string> hist_buffer;88 std::deque<std::string> hist_buffer; 65 89 66 90 /** Maximum number of lines stored in this history */ … … 74 98 75 99 /** Output file stream for logfile */ 76 ofstream hist_logfile;100 std::ofstream hist_logfile; 77 101 78 102 … … 99 123 */ 100 124 int chat_hist_openlog(); 101 } 125 126 127 /** close logfile */ 128 void chat_hist_closelog(); 129 }; 130 131 #ifndef TEST 102 132 } 133 #endif 103 134 104 135
Note: See TracChangeset
for help on using the changeset viewer.