[Orxonox-commit 4861] r9530 - in code/branches/testing/src/libraries/util: . output
landauf at orxonox.net
landauf at orxonox.net
Sun Feb 24 16:26:33 CET 2013
Author: landauf
Date: 2013-02-24 16:26:33 +0100 (Sun, 24 Feb 2013)
New Revision: 9530
Added:
code/branches/testing/src/libraries/util/output/AdditionalContextListener.h
Modified:
code/branches/testing/src/libraries/util/UtilPrereqs.h
code/branches/testing/src/libraries/util/output/OutputListener.cc
code/branches/testing/src/libraries/util/output/OutputListener.h
code/branches/testing/src/libraries/util/output/OutputManager.cc
code/branches/testing/src/libraries/util/output/OutputManager.h
Log:
small refactoring in output system
Modified: code/branches/testing/src/libraries/util/UtilPrereqs.h
===================================================================
--- code/branches/testing/src/libraries/util/UtilPrereqs.h 2013-02-23 22:39:22 UTC (rev 9529)
+++ code/branches/testing/src/libraries/util/UtilPrereqs.h 2013-02-24 15:26:33 UTC (rev 9530)
@@ -83,6 +83,7 @@
namespace orxonox
{
+ class AdditionalContextListener;
class Clock;
class Exception;
class ExprParser;
Added: code/branches/testing/src/libraries/util/output/AdditionalContextListener.h
===================================================================
--- code/branches/testing/src/libraries/util/output/AdditionalContextListener.h (rev 0)
+++ code/branches/testing/src/libraries/util/output/AdditionalContextListener.h 2013-02-24 15:26:33 UTC (rev 9530)
@@ -0,0 +1,58 @@
+/*
+ * 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 AdditionalContextListener interface
+*/
+
+#ifndef _AdditionalContextListener_H__
+#define _AdditionalContextListener_H__
+
+#include "util/UtilPrereqs.h"
+
+#include <vector>
+
+#include "OutputDefinitions.h"
+
+namespace orxonox
+{
+ /**
+ @brief AdditionalContextListener is an interface which is used to notify OutputManager about additional contexts in OutputListeners
+ */
+ class _UtilExport AdditionalContextListener
+ {
+ public:
+ virtual void updatedLevelMask(const OutputListener* listener) = 0;
+ virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener) = 0;
+ virtual void updatedAdditionalContextsMask(const OutputListener* listener) = 0;
+ };
+}
+
+#endif /* _AdditionalContextListener_H__ */
Modified: code/branches/testing/src/libraries/util/output/OutputListener.cc
===================================================================
--- code/branches/testing/src/libraries/util/output/OutputListener.cc 2013-02-23 22:39:22 UTC (rev 9529)
+++ code/branches/testing/src/libraries/util/output/OutputListener.cc 2013-02-24 15:26:33 UTC (rev 9530)
@@ -61,6 +61,29 @@
}
/**
+ @brief Adds a listener to the list.
+ */
+ void OutputListener::registerListener(AdditionalContextListener* listener)
+ {
+ this->listeners_.push_back(listener);
+ }
+
+ /**
+ @brief Removes a listener from the list.
+ */
+ void OutputListener::unregisterListener(AdditionalContextListener* listener)
+ {
+ for (std::vector<AdditionalContextListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+ {
+ if (*it == listener)
+ {
+ this->listeners_.erase(it);
+ break;
+ }
+ }
+ }
+
+ /**
@brief Defines the level mask in a way which accepts all output up to the level \c max.
*/
void OutputListener::setLevelMax(OutputLevel max)
@@ -87,7 +110,8 @@
{
this->levelMask_ = mask;
- OutputManager::getInstance().updateCombinedLevelMask();
+ for (size_t i = 0; i < this->listeners_.size(); ++i)
+ this->listeners_[i]->updatedLevelMask(this);
}
/**
@@ -117,7 +141,8 @@
{
this->additionalContextsLevelMask_ = mask;
- OutputManager::getInstance().updateCombinedAdditionalContextsLevelMask();
+ for (size_t i = 0; i < this->listeners_.size(); ++i)
+ this->listeners_[i]->updatedAdditionalContextsLevelMask(this);
}
/**
@@ -127,7 +152,8 @@
{
this->additionalContextsMask_ = mask;
- OutputManager::getInstance().updateCombinedAdditionalContextsMask();
+ for (size_t i = 0; i < this->listeners_.size(); ++i)
+ this->listeners_[i]->updatedAdditionalContextsMask(this);
}
/**
Modified: code/branches/testing/src/libraries/util/output/OutputListener.h
===================================================================
--- code/branches/testing/src/libraries/util/output/OutputListener.h 2013-02-23 22:39:22 UTC (rev 9529)
+++ code/branches/testing/src/libraries/util/output/OutputListener.h 2013-02-24 15:26:33 UTC (rev 9530)
@@ -54,6 +54,9 @@
OutputListener(bool bRegister = true);
virtual ~OutputListener();
+ void registerListener(AdditionalContextListener* listener);
+ void unregisterListener(AdditionalContextListener* listener);
+
void setLevelMax(OutputLevel max);
void setLevelRange(OutputLevel min, OutputLevel max);
void setLevelMask(OutputLevel mask);
@@ -84,10 +87,15 @@
/// @brief Pure virtual function, needs to be implemented in order to receive output.
virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0;
+ inline const std::vector<AdditionalContextListener*>& getListeners() const
+ { return this->listeners_; }
+
private:
- OutputLevel levelMask_; ///< Mask of accepted output levels, independent of contexts
- OutputContextMask additionalContextsMask_; ///< Mask of accepted additional contexts
- OutputLevel additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts
+ std::vector<AdditionalContextListener*> listeners_; ///< List of all registered additional context listeners
+
+ OutputLevel levelMask_; ///< Mask of accepted output levels, independent of contexts
+ OutputContextMask additionalContextsMask_; ///< Mask of accepted additional contexts
+ OutputLevel additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts
};
/**
Modified: code/branches/testing/src/libraries/util/output/OutputManager.cc
===================================================================
--- code/branches/testing/src/libraries/util/output/OutputManager.cc 2013-02-23 22:39:22 UTC (rev 9529)
+++ code/branches/testing/src/libraries/util/output/OutputManager.cc 2013-02-24 15:26:33 UTC (rev 9530)
@@ -112,6 +112,7 @@
*/
void OutputManager::registerListener(OutputListener* listener)
{
+ listener->registerListener(this);
this->listeners_.push_back(listener);
this->updateMasks();
}
@@ -121,6 +122,7 @@
*/
void OutputManager::unregisterListener(OutputListener* listener)
{
+ listener->unregisterListener(this);
for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
{
if (*it == listener)
Modified: code/branches/testing/src/libraries/util/output/OutputManager.h
===================================================================
--- code/branches/testing/src/libraries/util/output/OutputManager.h 2013-02-23 22:39:22 UTC (rev 9529)
+++ code/branches/testing/src/libraries/util/output/OutputManager.h 2013-02-24 15:26:33 UTC (rev 9530)
@@ -42,6 +42,7 @@
#include <map>
#include "OutputDefinitions.h"
+#include "AdditionalContextListener.h"
namespace orxonox
{
@@ -60,7 +61,7 @@
Additionally OutputManager is used to register output contexts.
*/
- class _UtilExport OutputManager
+ class _UtilExport OutputManager : public AdditionalContextListener
{
public:
static OutputManager& getInstance();
@@ -71,10 +72,12 @@
void registerListener(OutputListener* listener);
void unregisterListener(OutputListener* listener);
- void updateMasks();
- void updateCombinedLevelMask();
- void updateCombinedAdditionalContextsLevelMask();
- void updateCombinedAdditionalContextsMask();
+ virtual void updatedLevelMask(const OutputListener* listener)
+ { this->updateCombinedLevelMask(); }
+ virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener)
+ { this->updateCombinedAdditionalContextsLevelMask(); }
+ virtual void updatedAdditionalContextsMask(const OutputListener* listener)
+ { this->updateCombinedAdditionalContextsMask(); }
/**
@brief Returns true if at least one of the output listeners will accept output with the given level and context.
@@ -94,11 +97,20 @@
const std::string& getLevelName(OutputLevel level) const;
std::string getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const;
+ protected:
+ inline const std::vector<OutputListener*>& getListeners() const
+ { return this->listeners_; }
+
private:
OutputManager();
OutputManager(const OutputManager&);
~OutputManager();
+ void updateMasks();
+ void updateCombinedLevelMask();
+ void updateCombinedAdditionalContextsLevelMask();
+ void updateCombinedAdditionalContextsMask();
+
std::vector<OutputListener*> listeners_; ///< List of all registered output listeners
OutputLevel combinedLevelMask_; ///< The combined mask of accepted levels of all listeners
More information about the Orxonox-commit
mailing list