Changeset 8772
- Timestamp:
- Jul 24, 2011, 4:09:41 PM (13 years ago)
- Location:
- code/branches/output/src/libraries/util/output
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/output/src/libraries/util/output/OutputListener.h
r8765 r8772 31 31 32 32 #include "util/UtilPrereqs.h" 33 34 #include <vector> 35 33 36 #include "OutputDefinitions.h" 34 37 … … 60 63 { return ((this->levelMask_ & level) && (this->contextMask_ & context)); } 61 64 62 protected: 63 virtual void output(OutputLevel level, OutputContext context, const std::string& message) = 0; 65 virtual void output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines) = 0; 64 66 65 67 private: -
code/branches/output/src/libraries/util/output/OutputManager.cc
r8771 r8772 44 44 } 45 45 46 protected: 47 virtual void output(OutputLevel level, OutputContext context, const std::string& message) 48 { 49 COUT(0) << OutputManager::getInstance().getLevelName(level) << " / " << OutputManager::getInstance().getContextName(context) << " : " << message << endl; 46 virtual void output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines) 47 { 48 std::string prefix = OutputManager::getInstance().getLevelName(level) + ": "; 49 if (context != context::undefined) 50 { 51 std::string context_name = OutputManager::getInstance().getContextName(context); 52 if (context_name == "") 53 context_name = OutputManager::getInstance().getComposedContextName(context); 54 prefix += "[" + context_name + "] "; 55 } 56 std::string blanks(prefix.length(), ' '); 57 58 for (size_t i = 0; i < lines.size(); ++i) 59 COUT(0) << (i == 0 ? prefix : blanks) << lines[i] << endl; 50 60 } 51 61 }; … … 76 86 void OutputManager::pushMessage(OutputLevel level, OutputContext context, const std::string& message) 77 87 { 88 std::vector<std::string> lines; 89 for (size_t start = 0, end = 0; end != std::string::npos; start = end + 1) 90 { 91 end = message.find_first_of('\n', start); 92 lines.push_back(message.substr(start, end)); 93 } 94 78 95 for (size_t i = 0; i < this->listeners_.size(); ++i) 79 96 if (this->listeners_[i]->acceptsOutput(level, context)) 80 this->listeners_[i]->output(level, context, message);97 this->listeners_[i]->output(level, context, lines); 81 98 } 82 99 … … 168 185 boost::bimap<OutputContext, std::string>::left_map::const_iterator it = this->contexts_.left.find(context); 169 186 if (it != this->contexts_.left.end()) 170 {171 187 return it->second; 172 } 173 else 174 { 175 static std::string composed_context; 176 composed_context = ""; 177 size_t counter = 0; 178 for (OutputContext context_test = 0x1; context_test != 0x0; context_test = context_test << 1) 188 } 189 return BLANKSTRING; 190 } 191 192 std::string OutputManager::getComposedContextName(OutputContext context) const 193 { 194 std::string name; 195 size_t counter = 0; 196 for (OutputContext context_test = 0x1; context_test != 0x0; context_test = context_test << 1) 197 { 198 if (context & context_test) 199 { 200 boost::bimap<OutputContext, std::string>::left_map::const_iterator it = this->contexts_.left.find(context_test); 201 if (it != this->contexts_.left.end()) 179 202 { 180 if (context & context_test) 181 { 182 it = this->contexts_.left.find(context_test); 183 if (it != this->contexts_.left.end()) 184 { 185 if (counter) 186 composed_context += ", "; 187 188 composed_context += it->second; 189 ++counter; 190 } 191 } 203 if (counter) 204 name += ", "; 205 206 name += it->second; 207 ++counter; 192 208 } 193 return composed_context; 194 } 195 } 196 return BLANKSTRING; 209 } 210 } 211 return name; 197 212 } 198 213 } -
code/branches/output/src/libraries/util/output/OutputManager.h
r8771 r8772 72 72 const std::string& getLevelName(OutputLevel level) const; 73 73 const std::string& getContextName(OutputContext context) const; 74 std::string getComposedContextName(OutputContext context) const; 74 75 75 76 private:
Note: See TracChangeset
for help on using the changeset viewer.