Changeset 8833
- Timestamp:
- Aug 11, 2011, 11:20:39 PM (13 years ago)
- Location:
- code/branches/output/src/libraries
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/output/src/libraries/core/Core.cc
r8830 r8833 263 263 LogWriter::getInstance().configurableMaxLevel_) 264 264 .description("The maximum level of output shown in the log file") 265 .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevel s);266 SetConfigValueExternal(LogWriter::getInstance().configurable ContextsMaxLevel_,265 .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevel); 266 SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContextsMaxLevel_, 267 267 LogWriter::getInstance().getConfigurableSectionName(), 268 LogWriter::getInstance().getConfigurable ContextsMaxLevelName(),269 LogWriter::getInstance().configurable ContextsMaxLevel_)268 LogWriter::getInstance().getConfigurableAdditionalContextsMaxLevelName(), 269 LogWriter::getInstance().configurableAdditionalContextsMaxLevel_) 270 270 .description("The maximum level of output shown in the log file for additional contexts") 271 .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurable Levels);272 SetConfigValueExternal(LogWriter::getInstance().configurable Contexts_,271 .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContextsLevel); 272 SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContexts_, 273 273 LogWriter::getInstance().getConfigurableSectionName(), 274 LogWriter::getInstance().getConfigurable ContextsName(),275 LogWriter::getInstance().configurable Contexts_)274 LogWriter::getInstance().getConfigurableAdditionalContextsName(), 275 LogWriter::getInstance().configurableAdditionalContexts_) 276 276 .description("Additional output contexts shown in the log file") 277 .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurable Contexts);277 .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContexts); 278 278 279 279 SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun()) -
code/branches/output/src/libraries/core/command/Shell.cc
r8831 r8833 123 123 this->configurableMaxLevel_) 124 124 .description("The maximum level of output shown in the " + this->getName()) 125 .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevel s);126 SetConfigValueExternal(this->configurable ContextsMaxLevel_,125 .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevel); 126 SetConfigValueExternal(this->configurableAdditionalContextsMaxLevel_, 127 127 this->getConfigurableSectionName(), 128 this->getConfigurable ContextsMaxLevelName(),129 this->configurable ContextsMaxLevel_)128 this->getConfigurableAdditionalContextsMaxLevelName(), 129 this->configurableAdditionalContextsMaxLevel_) 130 130 .description("The maximum level of output shown in the " + this->getName() + " for additional contexts") 131 .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurable Levels);132 SetConfigValueExternal(this->configurable Contexts_,131 .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableAdditionalContextsLevel); 132 SetConfigValueExternal(this->configurableAdditionalContexts_, 133 133 this->getConfigurableSectionName(), 134 this->getConfigurable ContextsName(),135 this->configurable Contexts_)134 this->getConfigurableAdditionalContextsName(), 135 this->configurableAdditionalContexts_) 136 136 .description("Additional output contexts shown in the " + this->getName()) 137 .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurable Contexts);137 .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableAdditionalContexts); 138 138 } 139 139 -
code/branches/output/src/libraries/util/Output.h
r8812 r8833 38 38 using std::endl; 39 39 40 inline OutputStream& orxout(OutputLevel level = level::debug_output, OutputContextcontext = context::undefined())40 inline OutputStream& orxout(OutputLevel level = level::debug_output, const OutputContextContainer& context = context::undefined()) 41 41 { 42 42 static OutputStream stream; -
code/branches/output/src/libraries/util/output/BaseWriter.cc
r8831 r8833 38 38 39 39 this->configurableMaxLevel_ = level::none; 40 this->configurableContextsMaxLevel_ = level::verbose; 41 this->configurableContexts_.push_back("example"); 42 this->changedConfigurableLevels(); 40 this->configurableAdditionalContextsMaxLevel_ = level::verbose; 41 this->configurableAdditionalContexts_.push_back("example"); 42 43 this->subcontextsCheckMask_ = context::none; 44 45 this->changedConfigurableLevel(); 46 this->changedConfigurableAdditionalContextsLevel(); 47 this->changedConfigurableAdditionalContexts(); 43 48 } 44 49 … … 47 52 } 48 53 49 void BaseWriter::output(OutputLevel level, OutputContextcontext, const std::vector<std::string>& lines)54 void BaseWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 50 55 { 51 if ( level <= this->configurableMaxLevel_ || (level <= this->configurableContextsMaxLevel_ && this->isAdditionalContext(context)))56 if (((this->subcontextsCheckMask_ & context.mask) == 0) || (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end())) 52 57 { 53 58 const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context); … … 62 67 { 63 68 this->configurableMaxLevel_ = max; 64 this->changedConfigurableLevel s();69 this->changedConfigurableLevel(); 65 70 } 66 71 67 void BaseWriter:: changedConfigurableLevels()72 void BaseWriter::setAdditionalContextsLevelMax(OutputLevel max) 68 73 { 69 int max_level = std::max(this->configurableMaxLevel_, this->configurableContextsMaxLevel_);70 OutputListener::setLevelMax(static_cast<OutputLevel>(max_level));74 this->configurableAdditionalContextsMaxLevel_ = max; 75 this->changedConfigurableAdditionalContextsLevel(); 71 76 } 72 77 73 void BaseWriter::changedConfigurable Contexts()78 void BaseWriter::changedConfigurableLevel() 74 79 { 75 this->configurableContextsSet_.clear(); 76 for (size_t i = 0; i < this->configurableContexts_.size(); ++i) 77 this->configurableContextsSet_.insert(this->configurableContexts_[i]); 80 OutputListener::setLevelMax(static_cast<OutputLevel>(this->configurableMaxLevel_)); 78 81 } 79 82 80 bool BaseWriter::isAdditionalContext(OutputContext context) const83 void BaseWriter::changedConfigurableAdditionalContextsLevel() 81 84 { 82 const std::string& name = OutputManager::getInstance().getContextName(context); 83 std::set<std::string>::const_iterator it = this->configurableContextsSet_.find(name); 84 return (it != this->configurableContextsSet_.end()); 85 OutputListener::setAdditionalContextsLevelMax(static_cast<OutputLevel>(this->configurableAdditionalContextsMaxLevel_)); 86 } 87 88 void BaseWriter::changedConfigurableAdditionalContexts() 89 { 90 OutputContextMask context_mask = context::none; 91 this->subcontextsCheckMask_ = context::none; 92 93 this->subcontexts_.clear(); 94 this->subcontexts_.insert(context::no_subcontext); 95 96 for (size_t i = 0; i < this->configurableAdditionalContexts_.size(); ++i) 97 { 98 const std::string& full_name = this->configurableAdditionalContexts_[i]; 99 100 std::string name = full_name; 101 std::string subname; 102 103 size_t pos = full_name.find("::"); 104 if (pos != std::string::npos) 105 { 106 name = full_name.substr(0, pos); 107 subname = full_name.substr(pos + 2); 108 } 109 110 const OutputContextContainer& container = OutputManager::getInstance().registerContext(name, subname); 111 112 context_mask |= container.mask; 113 114 if (container.sub_id != context::no_subcontext) 115 { 116 this->subcontexts_.insert(container.sub_id); 117 this->subcontextsCheckMask_ |= container.mask; 118 } 119 } 120 121 this->setAdditionalContextsMask(context_mask); 85 122 } 86 123 } -
code/branches/output/src/libraries/util/output/BaseWriter.h
r8808 r8833 45 45 virtual ~BaseWriter(); 46 46 47 void setLevelMax(OutputLevel max); 48 void setAdditionalContextsLevelMax(OutputLevel max); 49 47 50 const std::string& getName() const 48 51 { return this->name_; } 49 52 50 void setLevelMax(OutputLevel max);51 52 53 int configurableMaxLevel_; 53 54 inline std::string getConfigurableMaxLevelName() const 54 { return "outputLevel" + this->name_; }55 { return this->name_ + "Level"; } 55 56 56 int configurable ContextsMaxLevel_;57 inline std::string getConfigurable ContextsMaxLevelName() const58 { return "outputContextsLevel" + this->name_; }57 int configurableAdditionalContextsMaxLevel_; 58 inline std::string getConfigurableAdditionalContextsMaxLevelName() const 59 { return this->name_ + "AdditionalContextsLevel"; } 59 60 60 std::vector<std::string> configurable Contexts_;61 inline std::string getConfigurable ContextsName() const62 { return "outputContexts" + this->name_; }61 std::vector<std::string> configurableAdditionalContexts_; 62 inline std::string getConfigurableAdditionalContextsName() const 63 { return this->name_ + "AdditionalContexts"; } 63 64 64 void changedConfigurableLevels(); 65 void changedConfigurableContexts(); 65 void changedConfigurableLevel(); 66 void changedConfigurableAdditionalContextsLevel(); 67 void changedConfigurableAdditionalContexts(); 66 68 67 69 static inline std::string getConfigurableSectionName() … … 69 71 70 72 protected: 71 virtual void output(OutputLevel level, OutputContextcontext, const std::vector<std::string>& lines);73 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines); 72 74 73 75 private: … … 77 79 void setLevelMask(OutputLevel mask); 78 80 79 bool isAdditionalContext(OutputContext context) const; 81 void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max); 82 void setAdditionalContextsLevelMask(OutputLevel mask); 80 83 81 84 std::string name_; 82 std::set<std::string> configurableContextsSet_; 85 86 OutputContextMask subcontextsCheckMask_; 87 std::set<OutputContextSubID> subcontexts_; 83 88 }; 84 89 } -
code/branches/output/src/libraries/util/output/LogWriter.cc
r8831 r8833 30 30 31 31 #include <ctime> 32 #include <cstdlib> 32 33 33 34 #include "OutputManager.h" -
code/branches/output/src/libraries/util/output/MemoryWriter.cc
r8787 r8833 48 48 } 49 49 50 void MemoryWriter::output(OutputLevel level, OutputContextcontext, const std::vector<std::string>& lines)50 void MemoryWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 51 51 { 52 52 this->messages_.push_back(Message(level, context, lines)); … … 58 58 { 59 59 const Message& message = this->messages_[i]; 60 listener->unfilteredOutput(message.level, message.context, message.lines);60 listener->unfilteredOutput(message.level, *message.context, message.lines); 61 61 } 62 62 } -
code/branches/output/src/libraries/util/output/MemoryWriter.h
r8794 r8833 39 39 struct Message 40 40 { 41 Message(OutputLevel level, OutputContextcontext, const std::vector<std::string>& lines)42 : level(level), context( context), lines(lines) {}41 Message(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 42 : level(level), context(&context), lines(lines) {} 43 43 44 44 OutputLevel level; 45 OutputContextcontext;45 const OutputContextContainer* context; 46 46 std::vector<std::string> lines; 47 47 }; … … 54 54 55 55 protected: 56 virtual void output(OutputLevel level, OutputContextcontext, const std::vector<std::string>& lines);56 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines); 57 57 58 58 private: -
code/branches/output/src/libraries/util/output/OutputDefinitions.h
r8831 r8833 34 34 35 35 #define REGISTER_OUTPUT_CONTEXT(name) \ 36 OutputContext name() { static OutputContext context = registerContext(#name); return context; } 36 const OutputContextContainer& name() { static const OutputContextContainer& context = registerContext(#name); return context; } 37 38 #define REGISTER_OUTPUT_SUBCONTEXT(name, subname) \ 39 const OutputContextContainer& subname() { static const OutputContextContainer& context = registerContext(#name, #subname); return context; } 37 40 38 41 namespace orxonox … … 63 66 using namespace level; 64 67 65 typedef uint64_t OutputContext ;66 typedef OutputContext (OutputContextFunction)();68 typedef uint64_t OutputContextMask; 69 typedef uint16_t OutputContextSubID; 67 70 68 extern _UtilExport OutputContext registerContext(const std::string& name); 71 struct OutputContextContainer 72 { 73 OutputContextMask mask; 74 OutputContextSubID sub_id; 75 std::string name; 76 }; 77 78 typedef const OutputContextContainer& (OutputContextFunction)(); 79 80 extern _UtilExport const OutputContextContainer& registerContext(const std::string& name, const std::string& subname = ""); 69 81 70 82 namespace context 71 83 { 72 static const OutputContext all = 0xFFFFFFFFFFFFFFFF; 73 static const OutputContext none = 0x0000000000000000; 84 static const OutputContextMask all = 0xFFFFFFFFFFFFFFFF; 85 static const OutputContextMask none = 0x0000000000000000; 86 87 static const OutputContextSubID no_subcontext = 0; 74 88 75 89 namespace … … 103 117 REGISTER_OUTPUT_CONTEXT(triggers); 104 118 REGISTER_OUTPUT_CONTEXT(docking); 119 120 namespace misc 121 { 122 REGISTER_OUTPUT_SUBCONTEXT(misc, testcontext1); 123 REGISTER_OUTPUT_SUBCONTEXT(misc, testcontext2); 124 REGISTER_OUTPUT_SUBCONTEXT(misc, testcontext3); 125 REGISTER_OUTPUT_SUBCONTEXT(misc, testcontext4); 126 } 127 128 REGISTER_OUTPUT_CONTEXT(c30); 129 REGISTER_OUTPUT_CONTEXT(c31); 130 REGISTER_OUTPUT_CONTEXT(c32); 131 REGISTER_OUTPUT_CONTEXT(c33); 132 REGISTER_OUTPUT_CONTEXT(c34); 133 REGISTER_OUTPUT_CONTEXT(c35); 134 REGISTER_OUTPUT_CONTEXT(c36); 135 REGISTER_OUTPUT_CONTEXT(c37); 136 REGISTER_OUTPUT_CONTEXT(c38); 137 REGISTER_OUTPUT_CONTEXT(c39); 138 REGISTER_OUTPUT_CONTEXT(c40); 139 REGISTER_OUTPUT_CONTEXT(c41); 140 REGISTER_OUTPUT_CONTEXT(c42); 141 REGISTER_OUTPUT_CONTEXT(c43); 142 REGISTER_OUTPUT_CONTEXT(c44); 143 REGISTER_OUTPUT_CONTEXT(c45); 144 REGISTER_OUTPUT_CONTEXT(c46); 145 REGISTER_OUTPUT_CONTEXT(c47); 146 REGISTER_OUTPUT_CONTEXT(c48); 147 REGISTER_OUTPUT_CONTEXT(c49); 148 REGISTER_OUTPUT_CONTEXT(c50); 149 REGISTER_OUTPUT_CONTEXT(c51); 150 REGISTER_OUTPUT_CONTEXT(c52); 151 REGISTER_OUTPUT_CONTEXT(c53); 152 REGISTER_OUTPUT_CONTEXT(c54); 153 REGISTER_OUTPUT_CONTEXT(c55); 154 REGISTER_OUTPUT_CONTEXT(c56); 155 REGISTER_OUTPUT_CONTEXT(c57); 156 REGISTER_OUTPUT_CONTEXT(c58); 157 REGISTER_OUTPUT_CONTEXT(c59); 158 REGISTER_OUTPUT_CONTEXT(c60); 159 REGISTER_OUTPUT_CONTEXT(c61); 160 REGISTER_OUTPUT_CONTEXT(c62); 161 REGISTER_OUTPUT_CONTEXT(c63); 162 REGISTER_OUTPUT_CONTEXT(c64); 163 REGISTER_OUTPUT_CONTEXT(c65); 164 REGISTER_OUTPUT_CONTEXT(c66); 105 165 } 106 166 } -
code/branches/output/src/libraries/util/output/OutputListener.cc
r8808 r8833 36 36 { 37 37 this->levelMask_ = level::none; 38 this->contextMask_ = context::all; 38 this->additionalContextsLevelMask_ = level::none; 39 this->additionalContextsMask_ = context::none; 39 40 40 41 OutputManager::getInstance().registerListener(this); … … 67 68 } 68 69 69 void OutputListener::set ContextMask(OutputContext mask)70 void OutputListener::setAdditionalContextsLevelMax(OutputLevel max) 70 71 { 71 this->contextMask_ = mask; 72 this->setAdditionalContextsLevelRange(static_cast<OutputLevel>(0x1), max); 73 } 72 74 73 OutputManager::getInstance().updateCombinedContextMask(); 75 void OutputListener::setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max) 76 { 77 int mask = 0; 78 for (int level = min; level <= max; level = level << 1) 79 mask |= level; 80 81 this->setAdditionalContextsLevelMask(static_cast<OutputLevel>(mask)); 82 } 83 84 void OutputListener::setAdditionalContextsLevelMask(OutputLevel mask) 85 { 86 this->additionalContextsLevelMask_ = mask; 87 88 OutputManager::getInstance().updateCombinedAdditionalContextsLevelMask(); 89 } 90 91 void OutputListener::setAdditionalContextsMask(OutputContextMask mask) 92 { 93 this->additionalContextsMask_ = mask; 94 95 OutputManager::getInstance().updateCombinedAdditionalContextsMask(); 74 96 } 75 97 } -
code/branches/output/src/libraries/util/output/OutputListener.h
r8794 r8833 48 48 void setLevelMask(OutputLevel mask); 49 49 50 void setAdditionalContextsLevelMax(OutputLevel max); 51 void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max); 52 void setAdditionalContextsLevelMask(OutputLevel mask); 53 54 void setAdditionalContextsMask(OutputContextMask mask); 55 50 56 inline OutputLevel getLevelMask() const 51 57 { return this->levelMask_; } 58 inline OutputLevel getAdditionalContextsLevelMask() const 59 { return this->additionalContextsLevelMask_; } 60 inline OutputContextMask getAdditionalContextsMask() const 61 { return this->additionalContextsMask_; } 52 62 53 void setContextMask(OutputContext mask); 63 inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const 64 { 65 return (this->levelMask_ & level) || 66 ((this->additionalContextsLevelMask_ & level) && (this->additionalContextsMask_ & context.mask)); } 54 67 55 inline OutputContext getContextMask() const 56 { return this->contextMask_; } 57 58 inline bool acceptsOutput(OutputLevel level, OutputContext context) const 59 { return ((this->levelMask_ & level) && (this->contextMask_ & context)); } 60 61 inline void unfilteredOutput(OutputLevel level, OutputContext context, const std::vector<std::string>& lines) 68 inline void unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 62 69 { if (this->acceptsOutput(level, context)) this->output(level, context, lines); } 63 70 64 71 protected: 65 virtual void output(OutputLevel level, OutputContextcontext, const std::vector<std::string>& lines) = 0;72 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0; 66 73 67 74 private: 68 OutputLevel levelMask_; 69 OutputContext contextMask_; 75 OutputLevel levelMask_; 76 OutputLevel additionalContextsLevelMask_; 77 OutputContextMask additionalContextsMask_; 70 78 }; 71 79 } -
code/branches/output/src/libraries/util/output/OutputManager.cc
r8808 r8833 32 32 #include "ConsoleWriter.h" 33 33 #include "LogWriter.h" 34 #include "util/Output.h" 34 35 #include "util/StringUtils.h" 35 36 … … 39 40 { 40 41 this->combinedLevelMask_ = level::none; 41 this->combinedContextMask_ = 0; 42 this->combinedAdditionalContextsLevelMask_ = level::none; 43 this->combinedAdditionalContextsMask_ = context::none; 44 45 this->subcontextCounter_ = 0; 42 46 } 43 47 … … 63 67 } 64 68 65 void OutputManager::pushMessage(OutputLevel level, OutputContextcontext, const std::string& message)69 void OutputManager::pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message) 66 70 { 67 71 std::vector<std::string> lines; … … 94 98 { 95 99 this->updateCombinedLevelMask(); 96 this->updateCombinedContextMask(); 100 this->updateCombinedAdditionalContextsLevelMask(); 101 this->updateCombinedAdditionalContextsMask(); 97 102 } 98 103 … … 105 110 } 106 111 107 void OutputManager::updateCombined ContextMask()112 void OutputManager::updateCombinedAdditionalContextsLevelMask() 108 113 { 109 this->combinedContextMask_= 0;114 int mask = 0; 110 115 for (size_t i = 0; i < this->listeners_.size(); ++i) 111 this->combinedContextMask_ |= this->listeners_[i]->getContextMask(); 116 mask |= this->listeners_[i]->getAdditionalContextsLevelMask(); 117 this->combinedAdditionalContextsLevelMask_ = static_cast<OutputLevel>(mask); 112 118 } 113 119 114 OutputContext OutputManager::registerContext(const std::string& name)120 void OutputManager::updateCombinedAdditionalContextsMask() 115 121 { 116 boost::bimap<OutputContext, std::string>::right_map::iterator it = this->contexts_.right.find(name); 117 if (it == this->contexts_.right.end()) 122 this->combinedAdditionalContextsMask_ = 0; 123 for (size_t i = 0; i < this->listeners_.size(); ++i) 124 this->combinedAdditionalContextsMask_ |= this->listeners_[i]->getAdditionalContextsMask(); 125 } 126 127 const OutputContextContainer& OutputManager::registerContext(const std::string& name, const std::string& subname) 128 { 129 std::string full_name = name; 130 if (subname != "") 131 full_name += "::" + subname; 132 133 std::map<std::string, OutputContextContainer>::iterator it_container = this->contextContainers_.find(full_name); 134 if (it_container != this->contextContainers_.end()) 135 return it_container->second; 136 137 OutputContextContainer container; 138 container.name = full_name; 139 140 std::map<std::string, OutputContextMask>::iterator it_mask = this->contextMasks_.find(name); 141 if (it_mask != this->contextMasks_.end()) 118 142 { 119 OutputContext context = 0x1 << this->contexts_.size(); 120 this->contexts_.insert(boost::bimap<OutputContext, std::string>::value_type(context, name)); 121 return context; 143 container.mask = it_mask->second; 122 144 } 123 145 else 124 146 { 125 return it->second; 147 container.mask = static_cast<OutputContextMask>(0x1) << this->contextMasks_.size(); 148 this->contextMasks_[name] = container.mask; 149 150 if (container.mask == 0) 151 orxout(internal_warning) << "More than " << sizeof(OutputContextMask) * 8 << " output contexts defined. Context '" << name << "' might not get filtered correctly" << endl; 126 152 } 153 154 if (subname == "") 155 container.sub_id = context::no_subcontext; 156 else 157 container.sub_id = ++this->subcontextCounter_; // start with 1 158 159 return (this->contextContainers_[full_name] = container); 127 160 } 128 161 129 OutputContext registerContext(const std::string&name)162 const OutputContextContainer& registerContext(const std::string& name, const std::string& subname) 130 163 { 131 return OutputManager::getInstance().registerContext(name );164 return OutputManager::getInstance().registerContext(name, subname); 132 165 } 133 166 … … 154 187 } 155 188 156 const std::string& OutputManager::getContextName(OutputContextcontext) const189 std::string OutputManager::getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const 157 190 { 158 if (context != context::undefined()) 159 { 160 boost::bimap<OutputContext, std::string>::left_map::const_iterator it = this->contexts_.left.find(context); 161 if (it != this->contexts_.left.end()) 162 return it->second; 163 } 164 return BLANKSTRING; 165 } 191 static OutputContextMask undefined_mask = context::undefined().mask; 166 192 167 OutputContext OutputManager::getContextValue(const std::string& name) const 168 { 169 boost::bimap<OutputContext, std::string>::right_map::const_iterator it = this->contexts_.right.find(name); 170 if (it != this->contexts_.right.end()) 171 return it->second; 172 else 173 return context::none; 174 } 193 std::string prefix = this->getLevelName(level) + ": "; 194 if (context.mask != undefined_mask) 195 prefix += "[" + context.name + "] "; 175 196 176 std::string OutputManager::getComposedContextName(OutputContext context) const177 {178 std::string name;179 size_t counter = 0;180 for (OutputContext context_test = 0x1; context_test != 0x0; context_test = context_test << 1)181 {182 if (context & context_test)183 {184 boost::bimap<OutputContext, std::string>::left_map::const_iterator it = this->contexts_.left.find(context_test);185 if (it != this->contexts_.left.end())186 {187 if (counter)188 name += ", ";189 190 name += it->second;191 ++counter;192 }193 }194 }195 return name;196 }197 198 std::string OutputManager::getDefaultPrefix(OutputLevel level, OutputContext context) const199 {200 std::string prefix = this->getLevelName(level) + ": ";201 if (context != context::undefined())202 {203 std::string context_name = this->getContextName(context);204 if (context_name == "")205 context_name = this->getComposedContextName(context);206 prefix += "[" + context_name + "] ";207 }208 197 return prefix; 209 198 } -
code/branches/output/src/libraries/util/output/OutputManager.h
r8799 r8833 33 33 34 34 #include <vector> 35 #include < boost/bimap.hpp>35 #include <map> 36 36 37 37 #include "OutputDefinitions.h" … … 45 45 static OutputManager& getInstanceAndCreateListeners(); 46 46 47 void pushMessage(OutputLevel level, OutputContextcontext, const std::string& message);47 void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message); 48 48 49 49 void registerListener(OutputListener* listener); … … 52 52 void updateMasks(); 53 53 void updateCombinedLevelMask(); 54 void updateCombinedContextMask(); 54 void updateCombinedAdditionalContextsLevelMask(); 55 void updateCombinedAdditionalContextsMask(); 55 56 56 inline OutputLevel getCombinedLevelMask() const 57 { return this->combinedLevelMask_; } 58 inline OutputContext getCombinedContextMask() const 59 { return this->combinedContextMask_; } 57 inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const 58 { 59 return (this->combinedLevelMask_ & level) || 60 ((this->combinedAdditionalContextsLevelMask_ & level) && (this->combinedAdditionalContextsMask_ & context.mask)); 61 } 60 62 61 inline bool acceptsOutput(OutputLevel level, OutputContext context) const 62 { return ((this->combinedLevelMask_ & level) && (this->combinedContextMask_ & context)); } 63 64 OutputContext registerContext(const std::string& name); 63 const OutputContextContainer& registerContext(const std::string& name, const std::string& subname = ""); 65 64 66 65 const std::string& getLevelName(OutputLevel level) const; 67 const std::string& getContextName(OutputContext context) const; 68 OutputContext getContextValue(const std::string& name) const; 69 70 std::string getComposedContextName(OutputContext context) const; 71 std::string getDefaultPrefix(OutputLevel level, OutputContext context) const; 66 std::string getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const; 72 67 73 68 private: … … 78 73 std::vector<OutputListener*> listeners_; 79 74 80 OutputLevel combinedLevelMask_; 81 OutputContext combinedContextMask_; 75 OutputLevel combinedLevelMask_; 76 OutputLevel combinedAdditionalContextsLevelMask_; 77 OutputContextMask combinedAdditionalContextsMask_; 82 78 83 boost::bimap<OutputContext, std::string> contexts_; 79 std::map<std::string, OutputContextMask> contextMasks_; 80 std::map<std::string, OutputContextContainer> contextContainers_; 81 OutputContextSubID subcontextCounter_; 84 82 }; 85 83 } -
code/branches/output/src/libraries/util/output/OutputStream.cc
r8789 r8833 38 38 } 39 39 40 OutputStream::OutputStream(OutputLevel level, OutputContextcontext)40 OutputStream::OutputStream(OutputLevel level, const OutputContextContainer& context) 41 41 { 42 42 this->setOutputAttributes(level, context); … … 45 45 void OutputStream::sendMessage() 46 46 { 47 OutputManager::getInstanceAndCreateListeners().pushMessage(this->level_, this->context_, this->str());47 OutputManager::getInstanceAndCreateListeners().pushMessage(this->level_, *this->context_, this->str()); 48 48 this->str(""); 49 49 } 50 50 51 void OutputStream::setOutputAttributes(OutputLevel level, OutputContextcontext)51 void OutputStream::setOutputAttributes(OutputLevel level, const OutputContextContainer& context) 52 52 { 53 53 this->level_ = level; 54 this->context_ = context;54 this->context_ = &context; 55 55 56 56 this->bAcceptsOutput_ = OutputManager::getInstanceAndCreateListeners().acceptsOutput(level, context); -
code/branches/output/src/libraries/util/output/OutputStream.h
r8789 r8833 44 44 public: 45 45 _UtilExport OutputStream(); 46 _UtilExport OutputStream(OutputLevel level, OutputContextcontext);46 _UtilExport OutputStream(OutputLevel level, const OutputContextContainer& context); 47 47 48 void _UtilExport setOutputAttributes(OutputLevel level, OutputContextcontext);48 void _UtilExport setOutputAttributes(OutputLevel level, const OutputContextContainer& context); 49 49 50 50 template <class T> … … 76 76 77 77 OutputLevel level_; 78 OutputContextcontext_;78 const OutputContextContainer* context_; 79 79 bool bAcceptsOutput_; 80 80 };
Note: See TracChangeset
for help on using the changeset viewer.