Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8850


Ignore:
Timestamp:
Aug 21, 2011, 6:27:30 PM (13 years ago)
Author:
landauf
Message:

moved filtering of sub-contexts from BaseWriter to a new interface SubcontextOutputListener

Location:
code/branches/output/src/libraries/util
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/util/CMakeLists.txt

    r8794 r8850  
    4646  output/LogWriter.cc
    4747  output/MemoryWriter.cc
     48  output/SubcontextOutputListener.cc
    4849)
    4950
  • code/branches/output/src/libraries/util/output/BaseWriter.cc

    r8834 r8850  
    3333namespace orxonox
    3434{
    35     BaseWriter::BaseWriter(const std::string& name, bool bRegister) : OutputListener(bRegister)
     35    BaseWriter::BaseWriter(const std::string& name, bool bRegister) : SubcontextOutputListener(bRegister)
    3636    {
    3737        this->name_ = name;
     
    4040        this->configurableAdditionalContextsMaxLevel_ = level::verbose;
    4141        this->configurableAdditionalContexts_.push_back("example");
    42 
    43         this->subcontextsCheckMask_ = context::none;
    44         this->subcontextsNoCheckMask_ = context::none;
    4542
    4643        this->changedConfigurableLevel();
     
    5552    void BaseWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
    5653    {
    57         if (((this->subcontextsCheckMask_ & context.mask) == 0) ||
    58             (this->subcontextsNoCheckMask_ & context.mask) ||
    59             (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end()))
    60         {
    61             const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
    62             std::string blanks(prefix.length(), ' ');
     54        const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
     55        std::string blanks(prefix.length(), ' ');
    6356
    64             for (size_t i = 0; i < lines.size(); ++i)
    65                 this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
    66         }
     57        for (size_t i = 0; i < lines.size(); ++i)
     58            this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
    6759    }
    6860
     
    9183    void BaseWriter::changedConfigurableAdditionalContexts()
    9284    {
    93         OutputContextMask context_mask = context::none;
    94         this->subcontextsCheckMask_ = context::none;
    95         this->subcontextsNoCheckMask_ = context::none;
    96 
    97         this->subcontexts_.clear();
     85        OutputContextMask main_contexts = context::none;
     86        std::set<const OutputContextContainer*> sub_contexts;
    9887
    9988        for (size_t i = 0; i < this->configurableAdditionalContexts_.size(); ++i)
     
    111100            }
    112101
    113             const OutputContextContainer& container = OutputManager::getInstance().registerContext(name, subname);
     102            const OutputContextContainer& context = OutputManager::getInstance().registerContext(name, subname);
    114103
    115             context_mask |= container.mask;
    116 
    117             if (container.sub_id != context::no_subcontext)
    118             {
    119                 this->subcontexts_.insert(container.sub_id);
    120                 this->subcontextsCheckMask_ |= container.mask;
    121             }
     104            if (context.sub_id == context::no_subcontext)
     105                main_contexts |= context.mask;
    122106            else
    123             {
    124                 this->subcontextsNoCheckMask_ |= container.mask;
    125             }
     107                sub_contexts.insert(&context);
    126108        }
    127109
    128         this->setAdditionalContextsMask(context_mask);
     110        this->setAdditionalContextsMask(main_contexts);
     111        this->setAdditionalSubcontexts(sub_contexts);
    129112    }
    130113}
  • code/branches/output/src/libraries/util/output/BaseWriter.h

    r8834 r8850  
    3131
    3232#include "util/UtilPrereqs.h"
    33 
    34 #include <set>
    35 #include <vector>
    36 
    37 #include "OutputListener.h"
     33#include "SubcontextOutputListener.h"
    3834
    3935namespace orxonox
    4036{
    41     class _UtilExport BaseWriter : public OutputListener
     37    class _UtilExport BaseWriter : public SubcontextOutputListener
    4238    {
    4339        public:
     
    8379
    8480            std::string name_;
    85 
    86             OutputContextMask subcontextsCheckMask_;
    87             OutputContextMask subcontextsNoCheckMask_;
    88             std::set<OutputContextSubID> subcontexts_;
    8981    };
    9082}
  • code/branches/output/src/libraries/util/output/OutputListener.cc

    r8848 r8850  
    130130        OutputManager::getInstance().updateCombinedAdditionalContextsMask();
    131131    }
     132
     133    /**
     134        @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks.
     135    */
     136    bool OutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
     137    {
     138        // check if the output level is accepted by the level mask (independent of the context)
     139        if (this->levelMask_ & level)
     140            return true;
     141
     142        // check if the output context is accepted by the additional context mask and if the level matches as well
     143        if ((this->additionalContextsMask_ & context.mask) && (this->additionalContextsLevelMask_ & level))
     144            return true;
     145
     146        // otherwise we don't accept the output
     147        return false;
     148    }
    132149}
  • code/branches/output/src/libraries/util/output/OutputListener.h

    r8848 r8850  
    7575                { return this->additionalContextsLevelMask_; }
    7676
    77             /// @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks.
    78             inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
    79             {
    80                 return (this->levelMask_ & level) ||
    81                        ((this->additionalContextsLevelMask_ & level) && (this->additionalContextsMask_ & context.mask)); }
     77            virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const;
    8278
    8379            /// @brief Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function.
Note: See TracChangeset for help on using the changeset viewer.