- Timestamp:
- Aug 11, 2011, 11:20:39 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.