Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8833


Ignore:
Timestamp:
Aug 11, 2011, 11:20:39 PM (13 years ago)
Author:
landauf
Message:

A context is now defined by a struct instead of only a mask.

Introduced sub-contexts. Sub-contexts of the same main-context share the same mask, but have a different ID.
Main-contexts are filtered using a bitmask which happens for every line of output and is very fast.
Sub-contexts are filtered using a set which is slow but happens only if a specific sub-context is enabled in the config file which is usually not the case.

The concept of filtering normal output + additional contexts was moved from BaseWriter directly to OutputListener and OutputManager which makes the whole system faster.
BaseWriter now calls registerContext() for each configured output context, which basically allows the usage of more than 64 contexts as long as these contexts are not used before loading the config file. Though by design it's not recommended.

Location:
code/branches/output/src/libraries
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/core/Core.cc

    r8830 r8833  
    263263                               LogWriter::getInstance().configurableMaxLevel_)
    264264            .description("The maximum level of output shown in the log file")
    265             .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevels);
    266         SetConfigValueExternal(LogWriter::getInstance().configurableContextsMaxLevel_,
     265            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevel);
     266        SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContextsMaxLevel_,
    267267                               LogWriter::getInstance().getConfigurableSectionName(),
    268                                LogWriter::getInstance().getConfigurableContextsMaxLevelName(),
    269                                LogWriter::getInstance().configurableContextsMaxLevel_)
     268                               LogWriter::getInstance().getConfigurableAdditionalContextsMaxLevelName(),
     269                               LogWriter::getInstance().configurableAdditionalContextsMaxLevel_)
    270270            .description("The maximum level of output shown in the log file for additional contexts")
    271             .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevels);
    272         SetConfigValueExternal(LogWriter::getInstance().configurableContexts_,
     271            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
     272        SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContexts_,
    273273                               LogWriter::getInstance().getConfigurableSectionName(),
    274                                LogWriter::getInstance().getConfigurableContextsName(),
    275                                LogWriter::getInstance().configurableContexts_)
     274                               LogWriter::getInstance().getConfigurableAdditionalContextsName(),
     275                               LogWriter::getInstance().configurableAdditionalContexts_)
    276276            .description("Additional output contexts shown in the log file")
    277             .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableContexts);
     277            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContexts);
    278278
    279279        SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
  • code/branches/output/src/libraries/core/command/Shell.cc

    r8831 r8833  
    123123                               this->configurableMaxLevel_)
    124124            .description("The maximum level of output shown in the " + this->getName())
    125             .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
    126         SetConfigValueExternal(this->configurableContextsMaxLevel_,
     125            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevel);
     126        SetConfigValueExternal(this->configurableAdditionalContextsMaxLevel_,
    127127                               this->getConfigurableSectionName(),
    128                                this->getConfigurableContextsMaxLevelName(),
    129                                this->configurableContextsMaxLevel_)
     128                               this->getConfigurableAdditionalContextsMaxLevelName(),
     129                               this->configurableAdditionalContextsMaxLevel_)
    130130            .description("The maximum level of output shown in the " + this->getName() + " for additional contexts")
    131             .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableLevels);
    132         SetConfigValueExternal(this->configurableContexts_,
     131            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableAdditionalContextsLevel);
     132        SetConfigValueExternal(this->configurableAdditionalContexts_,
    133133                               this->getConfigurableSectionName(),
    134                                this->getConfigurableContextsName(),
    135                                this->configurableContexts_)
     134                               this->getConfigurableAdditionalContextsName(),
     135                               this->configurableAdditionalContexts_)
    136136            .description("Additional output contexts shown in the " + this->getName())
    137             .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableContexts);
     137            .callback(static_cast<BaseWriter*>(this), &BaseWriter::changedConfigurableAdditionalContexts);
    138138    }
    139139
  • code/branches/output/src/libraries/util/Output.h

    r8812 r8833  
    3838    using std::endl;
    3939
    40     inline OutputStream& orxout(OutputLevel level = level::debug_output, OutputContext context = context::undefined())
     40    inline OutputStream& orxout(OutputLevel level = level::debug_output, const OutputContextContainer& context = context::undefined())
    4141    {
    4242        static OutputStream stream;
  • code/branches/output/src/libraries/util/output/BaseWriter.cc

    r8831 r8833  
    3838
    3939        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();
    4348    }
    4449
     
    4752    }
    4853
    49     void BaseWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines)
     54    void BaseWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
    5055    {
    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()))
    5257        {
    5358            const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
     
    6267    {
    6368        this->configurableMaxLevel_ = max;
    64         this->changedConfigurableLevels();
     69        this->changedConfigurableLevel();
    6570    }
    6671
    67     void BaseWriter::changedConfigurableLevels()
     72    void BaseWriter::setAdditionalContextsLevelMax(OutputLevel max)
    6873    {
    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();
    7176    }
    7277
    73     void BaseWriter::changedConfigurableContexts()
     78    void BaseWriter::changedConfigurableLevel()
    7479    {
    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_));
    7881    }
    7982
    80     bool BaseWriter::isAdditionalContext(OutputContext context) const
     83    void BaseWriter::changedConfigurableAdditionalContextsLevel()
    8184    {
    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);
    85122    }
    86123}
  • code/branches/output/src/libraries/util/output/BaseWriter.h

    r8808 r8833  
    4545            virtual ~BaseWriter();
    4646
     47            void setLevelMax(OutputLevel max);
     48            void setAdditionalContextsLevelMax(OutputLevel max);
     49
    4750            const std::string& getName() const
    4851                { return this->name_; }
    4952
    50             void setLevelMax(OutputLevel max);
    51 
    5253            int configurableMaxLevel_;
    5354            inline std::string getConfigurableMaxLevelName() const
    54                 { return "outputLevel" + this->name_; }
     55                { return this->name_ + "Level"; }
    5556
    56             int configurableContextsMaxLevel_;
    57             inline std::string getConfigurableContextsMaxLevelName() const
    58                 { return "outputContextsLevel" + this->name_; }
     57            int configurableAdditionalContextsMaxLevel_;
     58            inline std::string getConfigurableAdditionalContextsMaxLevelName() const
     59                { return this->name_ + "AdditionalContextsLevel"; }
    5960
    60             std::vector<std::string> configurableContexts_;
    61             inline std::string getConfigurableContextsName() const
    62                 { return "outputContexts" + this->name_; }
     61            std::vector<std::string> configurableAdditionalContexts_;
     62            inline std::string getConfigurableAdditionalContextsName() const
     63                { return this->name_ + "AdditionalContexts"; }
    6364
    64             void changedConfigurableLevels();
    65             void changedConfigurableContexts();
     65            void changedConfigurableLevel();
     66            void changedConfigurableAdditionalContextsLevel();
     67            void changedConfigurableAdditionalContexts();
    6668
    6769            static inline std::string getConfigurableSectionName()
     
    6971
    7072        protected:
    71             virtual void output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines);
     73            virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines);
    7274
    7375        private:
     
    7779            void setLevelMask(OutputLevel mask);
    7880
    79             bool isAdditionalContext(OutputContext context) const;
     81            void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max);
     82            void setAdditionalContextsLevelMask(OutputLevel mask);
    8083
    8184            std::string name_;
    82             std::set<std::string> configurableContextsSet_;
     85
     86            OutputContextMask subcontextsCheckMask_;
     87            std::set<OutputContextSubID> subcontexts_;
    8388    };
    8489}
  • code/branches/output/src/libraries/util/output/LogWriter.cc

    r8831 r8833  
    3030
    3131#include <ctime>
     32#include <cstdlib>
    3233
    3334#include "OutputManager.h"
  • code/branches/output/src/libraries/util/output/MemoryWriter.cc

    r8787 r8833  
    4848    }
    4949
    50     void MemoryWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines)
     50    void MemoryWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
    5151    {
    5252        this->messages_.push_back(Message(level, context, lines));
     
    5858        {
    5959            const Message& message = this->messages_[i];
    60             listener->unfilteredOutput(message.level, message.context, message.lines);
     60            listener->unfilteredOutput(message.level, *message.context, message.lines);
    6161        }
    6262    }
  • code/branches/output/src/libraries/util/output/MemoryWriter.h

    r8794 r8833  
    3939        struct Message
    4040        {
    41             Message(OutputLevel level, OutputContext context, 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) {}
    4343
    4444            OutputLevel level;
    45             OutputContext context;
     45            const OutputContextContainer* context;
    4646            std::vector<std::string> lines;
    4747        };
     
    5454
    5555        protected:
    56             virtual void output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines);
     56            virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines);
    5757
    5858        private:
  • code/branches/output/src/libraries/util/output/OutputDefinitions.h

    r8831 r8833  
    3434
    3535#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; }
    3740
    3841namespace orxonox
     
    6366    using namespace level;
    6467
    65     typedef uint64_t OutputContext;
    66     typedef OutputContext (OutputContextFunction)();
     68    typedef uint64_t OutputContextMask;
     69    typedef uint16_t OutputContextSubID;
    6770
    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 = "");
    6981
    7082    namespace context
    7183    {
    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;
    7488
    7589        namespace
     
    103117            REGISTER_OUTPUT_CONTEXT(triggers);
    104118            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);
    105165        }
    106166    }
  • code/branches/output/src/libraries/util/output/OutputListener.cc

    r8808 r8833  
    3636    {
    3737        this->levelMask_ = level::none;
    38         this->contextMask_ = context::all;
     38        this->additionalContextsLevelMask_ = level::none;
     39        this->additionalContextsMask_ = context::none;
    3940
    4041        OutputManager::getInstance().registerListener(this);
     
    6768    }
    6869
    69     void OutputListener::setContextMask(OutputContext mask)
     70    void OutputListener::setAdditionalContextsLevelMax(OutputLevel max)
    7071    {
    71         this->contextMask_ = mask;
     72        this->setAdditionalContextsLevelRange(static_cast<OutputLevel>(0x1), max);
     73    }
    7274
    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();
    7496    }
    7597}
  • code/branches/output/src/libraries/util/output/OutputListener.h

    r8794 r8833  
    4848            void setLevelMask(OutputLevel mask);
    4949
     50            void setAdditionalContextsLevelMax(OutputLevel max);
     51            void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max);
     52            void setAdditionalContextsLevelMask(OutputLevel mask);
     53
     54            void setAdditionalContextsMask(OutputContextMask mask);
     55
    5056            inline OutputLevel getLevelMask() const
    5157                { return this->levelMask_; }
     58            inline OutputLevel getAdditionalContextsLevelMask() const
     59                { return this->additionalContextsLevelMask_; }
     60            inline OutputContextMask getAdditionalContextsMask() const
     61                { return this->additionalContextsMask_; }
    5262
    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)); }
    5467
    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)
    6269                { if (this->acceptsOutput(level, context)) this->output(level, context, lines); }
    6370
    6471        protected:
    65             virtual void output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines) = 0;
     72            virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0;
    6673
    6774        private:
    68             OutputLevel   levelMask_;
    69             OutputContext contextMask_;
     75            OutputLevel       levelMask_;
     76            OutputLevel       additionalContextsLevelMask_;
     77            OutputContextMask additionalContextsMask_;
    7078    };
    7179}
  • code/branches/output/src/libraries/util/output/OutputManager.cc

    r8808 r8833  
    3232#include "ConsoleWriter.h"
    3333#include "LogWriter.h"
     34#include "util/Output.h"
    3435#include "util/StringUtils.h"
    3536
     
    3940    {
    4041        this->combinedLevelMask_ = level::none;
    41         this->combinedContextMask_ = 0;
     42        this->combinedAdditionalContextsLevelMask_ = level::none;
     43        this->combinedAdditionalContextsMask_ = context::none;
     44
     45        this->subcontextCounter_ = 0;
    4246    }
    4347
     
    6367    }
    6468
    65     void OutputManager::pushMessage(OutputLevel level, OutputContext context, const std::string& message)
     69    void OutputManager::pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message)
    6670    {
    6771        std::vector<std::string> lines;
     
    9498    {
    9599        this->updateCombinedLevelMask();
    96         this->updateCombinedContextMask();
     100        this->updateCombinedAdditionalContextsLevelMask();
     101        this->updateCombinedAdditionalContextsMask();
    97102    }
    98103
     
    105110    }
    106111
    107     void OutputManager::updateCombinedContextMask()
     112    void OutputManager::updateCombinedAdditionalContextsLevelMask()
    108113    {
    109         this->combinedContextMask_ = 0;
     114        int mask = 0;
    110115        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);
    112118    }
    113119
    114     OutputContext OutputManager::registerContext(const std::string& name)
     120    void OutputManager::updateCombinedAdditionalContextsMask()
    115121    {
    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())
    118142        {
    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;
    122144        }
    123145        else
    124146        {
    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;
    126152        }
     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);
    127160    }
    128161
    129     OutputContext registerContext(const std::string& name)
     162    const OutputContextContainer& registerContext(const std::string& name, const std::string& subname)
    130163    {
    131         return OutputManager::getInstance().registerContext(name);
     164        return OutputManager::getInstance().registerContext(name, subname);
    132165    }
    133166
     
    154187    }
    155188
    156     const std::string& OutputManager::getContextName(OutputContext context) const
     189    std::string OutputManager::getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const
    157190    {
    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;
    166192
    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 + "] ";
    175196
    176     std::string OutputManager::getComposedContextName(OutputContext context) const
    177     {
    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) const
    199     {
    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         }
    208197        return prefix;
    209198    }
  • code/branches/output/src/libraries/util/output/OutputManager.h

    r8799 r8833  
    3333
    3434#include <vector>
    35 #include <boost/bimap.hpp>
     35#include <map>
    3636
    3737#include "OutputDefinitions.h"
     
    4545            static OutputManager& getInstanceAndCreateListeners();
    4646
    47             void pushMessage(OutputLevel level, OutputContext context, const std::string& message);
     47            void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message);
    4848
    4949            void registerListener(OutputListener* listener);
     
    5252            void updateMasks();
    5353            void updateCombinedLevelMask();
    54             void updateCombinedContextMask();
     54            void updateCombinedAdditionalContextsLevelMask();
     55            void updateCombinedAdditionalContextsMask();
    5556
    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            }
    6062
    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 = "");
    6564
    6665            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;
    7267
    7368        private:
     
    7873            std::vector<OutputListener*> listeners_;
    7974
    80             OutputLevel   combinedLevelMask_;
    81             OutputContext combinedContextMask_;
     75            OutputLevel       combinedLevelMask_;
     76            OutputLevel       combinedAdditionalContextsLevelMask_;
     77            OutputContextMask combinedAdditionalContextsMask_;
    8278
    83             boost::bimap<OutputContext, std::string> contexts_;
     79            std::map<std::string, OutputContextMask> contextMasks_;
     80            std::map<std::string, OutputContextContainer> contextContainers_;
     81            OutputContextSubID subcontextCounter_;
    8482    };
    8583}
  • code/branches/output/src/libraries/util/output/OutputStream.cc

    r8789 r8833  
    3838    }
    3939
    40     OutputStream::OutputStream(OutputLevel level, OutputContext context)
     40    OutputStream::OutputStream(OutputLevel level, const OutputContextContainer& context)
    4141    {
    4242        this->setOutputAttributes(level, context);
     
    4545    void OutputStream::sendMessage()
    4646    {
    47         OutputManager::getInstanceAndCreateListeners().pushMessage(this->level_, this->context_, this->str());
     47        OutputManager::getInstanceAndCreateListeners().pushMessage(this->level_, *this->context_, this->str());
    4848        this->str("");
    4949    }
    5050
    51     void OutputStream::setOutputAttributes(OutputLevel level, OutputContext context)
     51    void OutputStream::setOutputAttributes(OutputLevel level, const OutputContextContainer& context)
    5252    {
    5353        this->level_ = level;
    54         this->context_ = context;
     54        this->context_ = &context;
    5555
    5656        this->bAcceptsOutput_ = OutputManager::getInstanceAndCreateListeners().acceptsOutput(level, context);
  • code/branches/output/src/libraries/util/output/OutputStream.h

    r8789 r8833  
    4444        public:
    4545            _UtilExport OutputStream();
    46             _UtilExport OutputStream(OutputLevel level, OutputContext context);
     46            _UtilExport OutputStream(OutputLevel level, const OutputContextContainer& context);
    4747
    48             void _UtilExport setOutputAttributes(OutputLevel level, OutputContext context);
     48            void _UtilExport setOutputAttributes(OutputLevel level, const OutputContextContainer& context);
    4949
    5050            template <class T>
     
    7676
    7777            OutputLevel level_;
    78             OutputContext context_;
     78            const OutputContextContainer* context_;
    7979            bool bAcceptsOutput_;
    8080    };
Note: See TracChangeset for help on using the changeset viewer.