Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.