[Orxonox-commit 4179] r8850 - in code/branches/output/src/libraries/util: . output
landauf at orxonox.net
landauf at orxonox.net
Sun Aug 21 18:27:31 CEST 2011
Author: landauf
Date: 2011-08-21 18:27:30 +0200 (Sun, 21 Aug 2011)
New Revision: 8850
Added:
code/branches/output/src/libraries/util/output/SubcontextOutputListener.cc
code/branches/output/src/libraries/util/output/SubcontextOutputListener.h
Modified:
code/branches/output/src/libraries/util/CMakeLists.txt
code/branches/output/src/libraries/util/output/BaseWriter.cc
code/branches/output/src/libraries/util/output/BaseWriter.h
code/branches/output/src/libraries/util/output/OutputListener.cc
code/branches/output/src/libraries/util/output/OutputListener.h
Log:
moved filtering of sub-contexts from BaseWriter to a new interface SubcontextOutputListener
Modified: code/branches/output/src/libraries/util/CMakeLists.txt
===================================================================
--- code/branches/output/src/libraries/util/CMakeLists.txt 2011-08-21 14:50:36 UTC (rev 8849)
+++ code/branches/output/src/libraries/util/CMakeLists.txt 2011-08-21 16:27:30 UTC (rev 8850)
@@ -45,6 +45,7 @@
output/ConsoleWriter.cc
output/LogWriter.cc
output/MemoryWriter.cc
+ output/SubcontextOutputListener.cc
)
ORXONOX_ADD_LIBRARY(util
Modified: code/branches/output/src/libraries/util/output/BaseWriter.cc
===================================================================
--- code/branches/output/src/libraries/util/output/BaseWriter.cc 2011-08-21 14:50:36 UTC (rev 8849)
+++ code/branches/output/src/libraries/util/output/BaseWriter.cc 2011-08-21 16:27:30 UTC (rev 8850)
@@ -32,7 +32,7 @@
namespace orxonox
{
- BaseWriter::BaseWriter(const std::string& name, bool bRegister) : OutputListener(bRegister)
+ BaseWriter::BaseWriter(const std::string& name, bool bRegister) : SubcontextOutputListener(bRegister)
{
this->name_ = name;
@@ -40,9 +40,6 @@
this->configurableAdditionalContextsMaxLevel_ = level::verbose;
this->configurableAdditionalContexts_.push_back("example");
- this->subcontextsCheckMask_ = context::none;
- this->subcontextsNoCheckMask_ = context::none;
-
this->changedConfigurableLevel();
this->changedConfigurableAdditionalContextsLevel();
this->changedConfigurableAdditionalContexts();
@@ -54,16 +51,11 @@
void BaseWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
{
- if (((this->subcontextsCheckMask_ & context.mask) == 0) ||
- (this->subcontextsNoCheckMask_ & context.mask) ||
- (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end()))
- {
- const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
- std::string blanks(prefix.length(), ' ');
+ const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
+ std::string blanks(prefix.length(), ' ');
- for (size_t i = 0; i < lines.size(); ++i)
- this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
- }
+ for (size_t i = 0; i < lines.size(); ++i)
+ this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
}
void BaseWriter::setLevelMax(OutputLevel max)
@@ -90,12 +82,9 @@
void BaseWriter::changedConfigurableAdditionalContexts()
{
- OutputContextMask context_mask = context::none;
- this->subcontextsCheckMask_ = context::none;
- this->subcontextsNoCheckMask_ = context::none;
+ OutputContextMask main_contexts = context::none;
+ std::set<const OutputContextContainer*> sub_contexts;
- this->subcontexts_.clear();
-
for (size_t i = 0; i < this->configurableAdditionalContexts_.size(); ++i)
{
const std::string& full_name = this->configurableAdditionalContexts_[i];
@@ -110,21 +99,15 @@
subname = full_name.substr(pos + 2);
}
- const OutputContextContainer& container = OutputManager::getInstance().registerContext(name, subname);
+ const OutputContextContainer& context = OutputManager::getInstance().registerContext(name, subname);
- context_mask |= container.mask;
-
- if (container.sub_id != context::no_subcontext)
- {
- this->subcontexts_.insert(container.sub_id);
- this->subcontextsCheckMask_ |= container.mask;
- }
+ if (context.sub_id == context::no_subcontext)
+ main_contexts |= context.mask;
else
- {
- this->subcontextsNoCheckMask_ |= container.mask;
- }
+ sub_contexts.insert(&context);
}
- this->setAdditionalContextsMask(context_mask);
+ this->setAdditionalContextsMask(main_contexts);
+ this->setAdditionalSubcontexts(sub_contexts);
}
}
Modified: code/branches/output/src/libraries/util/output/BaseWriter.h
===================================================================
--- code/branches/output/src/libraries/util/output/BaseWriter.h 2011-08-21 14:50:36 UTC (rev 8849)
+++ code/branches/output/src/libraries/util/output/BaseWriter.h 2011-08-21 16:27:30 UTC (rev 8850)
@@ -30,15 +30,11 @@
#define _BaseWriter_H__
#include "util/UtilPrereqs.h"
+#include "SubcontextOutputListener.h"
-#include <set>
-#include <vector>
-
-#include "OutputListener.h"
-
namespace orxonox
{
- class _UtilExport BaseWriter : public OutputListener
+ class _UtilExport BaseWriter : public SubcontextOutputListener
{
public:
BaseWriter(const std::string& name, bool bRegister = true);
@@ -82,10 +78,6 @@
void setAdditionalContextsLevelMask(OutputLevel mask);
std::string name_;
-
- OutputContextMask subcontextsCheckMask_;
- OutputContextMask subcontextsNoCheckMask_;
- std::set<OutputContextSubID> subcontexts_;
};
}
Modified: code/branches/output/src/libraries/util/output/OutputListener.cc
===================================================================
--- code/branches/output/src/libraries/util/output/OutputListener.cc 2011-08-21 14:50:36 UTC (rev 8849)
+++ code/branches/output/src/libraries/util/output/OutputListener.cc 2011-08-21 16:27:30 UTC (rev 8850)
@@ -129,4 +129,21 @@
OutputManager::getInstance().updateCombinedAdditionalContextsMask();
}
+
+ /**
+ @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks.
+ */
+ bool OutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
+ {
+ // check if the output level is accepted by the level mask (independent of the context)
+ if (this->levelMask_ & level)
+ return true;
+
+ // check if the output context is accepted by the additional context mask and if the level matches as well
+ if ((this->additionalContextsMask_ & context.mask) && (this->additionalContextsLevelMask_ & level))
+ return true;
+
+ // otherwise we don't accept the output
+ return false;
+ }
}
Modified: code/branches/output/src/libraries/util/output/OutputListener.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputListener.h 2011-08-21 14:50:36 UTC (rev 8849)
+++ code/branches/output/src/libraries/util/output/OutputListener.h 2011-08-21 16:27:30 UTC (rev 8850)
@@ -74,11 +74,7 @@
inline OutputLevel getAdditionalContextsLevelMask() const
{ return this->additionalContextsLevelMask_; }
- /// @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks.
- inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
- {
- return (this->levelMask_ & level) ||
- ((this->additionalContextsLevelMask_ & level) && (this->additionalContextsMask_ & context.mask)); }
+ virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const;
/// @brief Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function.
inline void unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
Added: code/branches/output/src/libraries/util/output/SubcontextOutputListener.cc
===================================================================
--- code/branches/output/src/libraries/util/output/SubcontextOutputListener.cc (rev 0)
+++ code/branches/output/src/libraries/util/output/SubcontextOutputListener.cc 2011-08-21 16:27:30 UTC (rev 8850)
@@ -0,0 +1,92 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "SubcontextOutputListener.h"
+
+namespace orxonox
+{
+ SubcontextOutputListener::SubcontextOutputListener(bool bRegister) : OutputListener(bRegister)
+ {
+ this->subcontextsCheckMask_ = context::none;
+ this->subcontextsNoCheckMask_ = context::none;
+ }
+
+ SubcontextOutputListener::~SubcontextOutputListener()
+ {
+ }
+
+ void SubcontextOutputListener::setAdditionalContextsMask(OutputContextMask mask)
+ {
+ this->subcontextsNoCheckMask_ = mask;
+
+ OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_);
+ }
+
+ void SubcontextOutputListener::setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts)
+ {
+ this->subcontextsCheckMask_ = context::none;
+ this->subcontexts_.clear();
+
+ for (std::set<const OutputContextContainer*>::const_iterator it = subcontexts.begin(); it != subcontexts.end(); ++it)
+ {
+ this->subcontextsCheckMask_ |= (*it)->mask;
+ this->subcontexts_.insert((*it)->sub_id);
+ }
+
+ OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_);
+ }
+
+ /**
+ @brief Returns true if this listener accepts output of the given level and context, based on the levels, contexts masks, and sub-contexts.
+ */
+ bool SubcontextOutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
+ {
+ // check if the output level is accepted by the level mask (independent of the context)
+ if (this->getLevelMask() & level)
+ return true;
+
+ // check if the output level is accepted by the additional contexts level mask
+ if (this->getAdditionalContextsLevelMask() & level)
+ {
+ // check if the output context is accepted by the "no check" mask
+ if (this->subcontextsNoCheckMask_ & context.mask)
+ return true;
+
+ // check if the output context is accepted by the "check" mask
+ if (this->subcontextsCheckMask_ & context.mask)
+ {
+ // check if the output's subcontext is in the set of accepted sub-context
+ if (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end())
+ return true;
+ }
+ }
+
+ // otherwise we don't accept the output
+ return false;
+ }
+}
Property changes on: code/branches/output/src/libraries/util/output/SubcontextOutputListener.cc
___________________________________________________________________
Added: svn:eol-style
+ native
Added: code/branches/output/src/libraries/util/output/SubcontextOutputListener.h
===================================================================
--- code/branches/output/src/libraries/util/output/SubcontextOutputListener.h (rev 0)
+++ code/branches/output/src/libraries/util/output/SubcontextOutputListener.h 2011-08-21 16:27:30 UTC (rev 8850)
@@ -0,0 +1,64 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Output
+ @brief Declaration of the SubcontextOutputListener interface which adds the ability to filter sub-contexts to OutputListener.
+*/
+
+#ifndef _SubcontextOutputListener_H__
+#define _SubcontextOutputListener_H__
+
+#include "util/UtilPrereqs.h"
+
+#include <set>
+
+#include "OutputListener.h"
+
+namespace orxonox
+{
+ class _UtilExport SubcontextOutputListener : public OutputListener
+ {
+ public:
+ SubcontextOutputListener(bool bRegister = true);
+ virtual ~SubcontextOutputListener();
+
+ void setAdditionalContextsMask(OutputContextMask mask);
+ void setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts);
+
+ virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const;
+
+ private:
+ OutputContextMask subcontextsCheckMask_;
+ OutputContextMask subcontextsNoCheckMask_;
+ std::set<OutputContextSubID> subcontexts_;
+ };
+}
+
+#endif /* _SubcontextOutputListener_H__ */
Property changes on: code/branches/output/src/libraries/util/output/SubcontextOutputListener.h
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the Orxonox-commit
mailing list