[Orxonox-commit 4094] r8765 - in code/branches/output/src/libraries/util: . output

landauf at orxonox.net landauf at orxonox.net
Tue Jul 19 21:26:33 CEST 2011


Author: landauf
Date: 2011-07-19 21:26:32 +0200 (Tue, 19 Jul 2011)
New Revision: 8765

Added:
   code/branches/output/src/libraries/util/Output.h
   code/branches/output/src/libraries/util/output/
   code/branches/output/src/libraries/util/output/OutputDefinitions.h
   code/branches/output/src/libraries/util/output/OutputListener.cc
   code/branches/output/src/libraries/util/output/OutputListener.h
   code/branches/output/src/libraries/util/output/OutputManager.cc
   code/branches/output/src/libraries/util/output/OutputManager.h
   code/branches/output/src/libraries/util/output/OutputStream.cc
   code/branches/output/src/libraries/util/output/OutputStream.h
Modified:
   code/branches/output/src/libraries/util/CMakeLists.txt
Log:
added draft for the the new output system

Modified: code/branches/output/src/libraries/util/CMakeLists.txt
===================================================================
--- code/branches/output/src/libraries/util/CMakeLists.txt	2011-07-18 21:07:05 UTC (rev 8764)
+++ code/branches/output/src/libraries/util/CMakeLists.txt	2011-07-19 19:26:32 UTC (rev 8765)
@@ -39,6 +39,9 @@
   Math.cc
   SignalHandler.cc
   StringUtils.cc
+  output/OutputStream.cc
+  output/OutputManager.cc
+  output/OutputListener.cc
 )
 
 ORXONOX_ADD_LIBRARY(util

Added: code/branches/output/src/libraries/util/Output.h
===================================================================
--- code/branches/output/src/libraries/util/Output.h	                        (rev 0)
+++ code/branches/output/src/libraries/util/Output.h	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,51 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _Output_H__
+#define _Output_H__
+
+#include "UtilPrereqs.h"
+#include "output/OutputStream.h"
+
+namespace orxonox
+{
+using namespace test;
+namespace test
+{
+    using namespace level;
+
+    inline OutputStream& orxout(OutputLevel level = level::debug_output, OutputContext context = context::undefined)
+    {
+        static OutputStream stream;
+        stream.setOutputAttributes(level, context);
+        return stream;
+    }
+}
+}
+
+#endif /* _Output_H__ */


Property changes on: code/branches/output/src/libraries/util/Output.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputDefinitions.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputDefinitions.h	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputDefinitions.h	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,72 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _OutputDefinitions_H__
+#define _OutputDefinitions_H__
+
+#include "util/UtilPrereqs.h"
+
+namespace orxonox
+{
+namespace test
+{
+    typedef uint16_t OutputLevel;
+
+    namespace level
+    {
+        static const OutputLevel all              = 0xFFFF;
+        static const OutputLevel none             = 0x0000;
+        static const OutputLevel debug_output     = 0x0001;
+        static const OutputLevel user_error       = 0x0002;
+        static const OutputLevel user_warning     = 0x0004;
+        static const OutputLevel user_status      = 0x0008;
+        static const OutputLevel user_info        = 0x0010;
+        static const OutputLevel internal_error   = 0x0020;
+        static const OutputLevel internal_warning = 0x0040;
+        static const OutputLevel internal_status  = 0x0080;
+        static const OutputLevel internal_info    = 0x0100;
+        static const OutputLevel verbose          = 0x0200;
+        static const OutputLevel verbose_more     = 0x0400;
+        static const OutputLevel verbose_ultra    = 0x0800;
+    }
+
+    typedef uint64_t OutputContext;
+
+    namespace context
+    {
+        static const OutputContext all       = 0xFFFFFFFFFFFFFFFF;
+        static const OutputContext none      = 0x0000000000000000;
+        static const OutputContext undefined = 0x0000000000000001;
+
+        static const OutputContext test1     = 0x0000000000000002;
+        static const OutputContext test2     = 0x0000000000000004;
+    }
+}
+}
+
+#endif /* _OutputDefinitions_H__ */


Property changes on: code/branches/output/src/libraries/util/output/OutputDefinitions.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputListener.cc
===================================================================
--- code/branches/output/src/libraries/util/output/OutputListener.cc	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputListener.cc	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,79 @@
+/*
+ *   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 "OutputListener.h"
+
+#include "OutputManager.h"
+
+namespace orxonox
+{
+namespace test
+{
+    OutputListener::OutputListener()
+    {
+        this->levelMask_ = level::none;
+        this->contextMask_ = context::all;
+
+        OutputManager::getInstanceInternal().registerListener(this);
+    }
+
+    OutputListener::~OutputListener()
+    {
+        OutputManager::getInstanceInternal().unregisterListener(this);
+    }
+
+    void OutputListener::setLevelMax(OutputLevel max)
+    {
+        this->setLevelRange(level::debug_output, max);
+    }
+
+    void OutputListener::setLevelRange(OutputLevel min, OutputLevel max)
+    {
+        OutputLevel mask = 0;
+
+        for (OutputLevel level = min; level <= max; level = level << 1)
+            mask |= level;
+
+        this->setLevelMask(mask);
+    }
+
+    void OutputListener::setLevelMask(OutputLevel mask)
+    {
+        this->levelMask_ = mask;
+
+        OutputManager::getInstanceInternal().updateCombinedLevelMask();
+    }
+
+    void OutputListener::setContextMask(OutputContext mask)
+    {
+        this->contextMask_ = mask;
+
+        OutputManager::getInstanceInternal().updateCombinedContextMask();
+    }
+}
+}


Property changes on: code/branches/output/src/libraries/util/output/OutputListener.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputListener.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputListener.h	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputListener.h	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,72 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _OutputListener_H__
+#define _OutputListener_H__
+
+#include "util/UtilPrereqs.h"
+#include "OutputDefinitions.h"
+
+namespace orxonox
+{
+namespace test
+{
+    class _UtilExport OutputListener
+    {
+        friend class OutputManager;
+
+        public:
+            OutputListener();
+            ~OutputListener();
+
+            void setLevelMax(OutputLevel max);
+            void setLevelRange(OutputLevel min, OutputLevel max);
+            void setLevelMask(OutputLevel mask);
+
+            inline OutputLevel getLevelMask() const
+                { return this->levelMask_; }
+
+            void setContextMask(OutputContext mask);
+
+            inline OutputContext getContextMask() const
+                { return this->contextMask_; }
+
+            inline bool acceptsOutput(OutputLevel level, OutputContext context) const
+                { return ((this->levelMask_ & level) && (this->contextMask_ & context)); }
+
+        protected:
+            virtual void output(OutputLevel level, OutputContext context, const std::string& message) = 0;
+
+        private:
+            OutputLevel   levelMask_;
+            OutputContext contextMask_;
+    };
+}
+}
+
+#endif /* _OutputListener_H__ */


Property changes on: code/branches/output/src/libraries/util/output/OutputListener.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputManager.cc
===================================================================
--- code/branches/output/src/libraries/util/output/OutputManager.cc	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputManager.cc	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,122 @@
+/*
+ *   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 "OutputManager.h"
+
+#include "util/Debug.h"
+#include "OutputListener.h"
+
+namespace orxonox
+{
+namespace test
+{
+    class ConsoleOutput : public OutputListener
+    {
+        public:
+            ConsoleOutput()
+            {
+                this->setLevelMax(level::user_info);
+            }
+
+        protected:
+            virtual void output(OutputLevel level, OutputContext context, const std::string& message)
+            {
+                COUT(0) << (int)level << " / " << context << " : " << message << endl;
+            }
+    };
+
+    OutputManager::OutputManager()
+    {
+        this->combinedLevelMask_ = 0;
+        this->combinedContextMask_ = 0;
+    }
+
+    OutputManager::~OutputManager()
+    {
+    }
+
+    /*static*/ OutputManager& OutputManager::getInstance()
+    {
+        static OutputManager& instance = OutputManager::getInstanceInternal();
+        static ConsoleOutput consoleOutputInstance;
+        return instance;
+    }
+
+    /*static*/ OutputManager& OutputManager::getInstanceInternal()
+    {
+        static OutputManager instance;
+        return instance;
+    }
+
+    void OutputManager::pushMessage(OutputLevel level, OutputContext context, const std::string& message)
+    {
+        for (size_t i = 0; i < this->listeners_.size(); ++i)
+            if (this->listeners_[i]->acceptsOutput(level, context))
+                this->listeners_[i]->output(level, context, message);
+    }
+
+    void OutputManager::registerListener(OutputListener* listener)
+    {
+        this->listeners_.push_back(listener);
+        this->updateMasks();
+    }
+
+    void OutputManager::unregisterListener(OutputListener* listener)
+    {
+        for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        {
+            if (*it == listener)
+            {
+                this->listeners_.erase(it);
+                break;
+            }
+        }
+        this->updateMasks();
+    }
+
+    void OutputManager::updateMasks()
+    {
+        this->updateCombinedLevelMask();
+        this->updateCombinedContextMask();
+    }
+
+    void OutputManager::updateCombinedLevelMask()
+    {
+        this->combinedLevelMask_ = 0;
+        for (size_t i = 0; i < this->listeners_.size(); ++i)
+            this->combinedLevelMask_ |= this->listeners_[i]->getLevelMask();
+    }
+
+    void OutputManager::updateCombinedContextMask()
+    {
+        this->combinedContextMask_ = 0;
+        for (size_t i = 0; i < this->listeners_.size(); ++i)
+            this->combinedContextMask_ |= this->listeners_[i]->getContextMask();
+    }
+}
+}


Property changes on: code/branches/output/src/libraries/util/output/OutputManager.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputManager.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputManager.h	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputManager.h	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,83 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _OutputManager_H__
+#define _OutputManager_H__
+
+#include "util/UtilPrereqs.h"
+
+#include <vector>
+
+#include "OutputDefinitions.h"
+
+namespace orxonox
+{
+namespace test
+{
+    class OutputListener;
+
+    class _UtilExport OutputManager
+    {
+        friend class OutputListener;
+
+        public:
+            static OutputManager& getInstance();
+
+            void pushMessage(OutputLevel level, OutputContext context, const std::string& message);
+
+            void registerListener(OutputListener* listener);
+            void unregisterListener(OutputListener* listener);
+
+            void updateMasks();
+            void updateCombinedLevelMask();
+            void updateCombinedContextMask();
+
+            inline OutputLevel getCombinedLevelMask() const
+                { return this->combinedLevelMask_; }
+            inline OutputContext getCombinedContextMask() const
+                { return this->combinedContextMask_; }
+
+            inline bool acceptsOutput(OutputLevel level, OutputContext context) const
+                { return ((this->combinedLevelMask_ & level) && (this->combinedContextMask_ & context)); }
+
+        private:
+            OutputManager();
+            OutputManager(const OutputManager&);
+            ~OutputManager();
+
+            static OutputManager& getInstanceInternal();
+
+            std::vector<OutputListener*> listeners_;
+
+            OutputLevel   combinedLevelMask_;
+            OutputContext combinedContextMask_;
+    };
+}
+}
+
+#endif /* _OutputManager_H__ */


Property changes on: code/branches/output/src/libraries/util/output/OutputManager.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputStream.cc
===================================================================
--- code/branches/output/src/libraries/util/output/OutputStream.cc	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputStream.cc	2011-07-19 19:26:32 UTC (rev 8765)
@@ -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:
+ *      ...
+ *
+ */
+
+#include "OutputStream.h"
+
+#include "OutputManager.h"
+
+namespace orxonox
+{
+namespace test
+{
+    OutputStream::OutputStream()
+    {
+        this->level_ = level::none;
+        this->context_ = context::none;
+        this->bAcceptsOutput_ = false;
+    }
+
+    void OutputStream::sendMessage()
+    {
+        OutputManager::getInstance().pushMessage(this->level_, this->context_, this->str());
+        this->str("");
+    }
+
+    void OutputStream::setOutputAttributes(OutputLevel level, OutputContext context)
+    {
+        this->level_ = level;
+        this->context_ = context;
+
+        this->bAcceptsOutput_ = OutputManager::getInstance().acceptsOutput(level, context);
+    }
+}
+}


Property changes on: code/branches/output/src/libraries/util/output/OutputStream.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/libraries/util/output/OutputStream.h
===================================================================
--- code/branches/output/src/libraries/util/output/OutputStream.h	                        (rev 0)
+++ code/branches/output/src/libraries/util/output/OutputStream.h	2011-07-19 19:26:32 UTC (rev 8765)
@@ -0,0 +1,85 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _OutputStream_H__
+#define _OutputStream_H__
+
+#include "util/UtilPrereqs.h"
+
+#include <sstream>
+
+#include "OutputDefinitions.h"
+
+namespace orxonox
+{
+namespace test
+{
+    class _UtilExport OutputStream : public std::ostringstream
+    {
+        typedef std::ostream& (*EndlType)(std::ostream&);
+
+        public:
+            OutputStream();
+
+            void setOutputAttributes(OutputLevel level, OutputContext context);
+
+            template <class T>
+            inline OutputStream& operator<<(const T& val) { return this->output(val); }
+            inline OutputStream& operator<<(std::ios_base& (*manipulator)(std::ios_base&)) { return this->output(manipulator); }
+            inline OutputStream& operator<<(std::ios&      (*manipulator)(std::ios&))      { return this->output(manipulator); }
+            inline OutputStream& operator<<(std::ostream&  (*manipulator)(std::ostream&))
+            {
+                if (this->bAcceptsOutput_)
+                {
+                    if (manipulator == static_cast<EndlType>(std::endl))
+                        this->sendMessage();
+                    else
+                        return this->output(manipulator);
+                }
+                return *this;
+            }
+
+        private:
+            template <class T>
+            inline OutputStream& output(const T& val)
+            {
+                if (this->bAcceptsOutput_)
+                    static_cast<std::ostringstream&>(*this) << val;
+                return *this;
+            }
+
+            void sendMessage();
+
+            OutputLevel level_;
+            OutputContext context_;
+            bool bAcceptsOutput_;
+    };
+}
+}
+
+#endif /* _OutputStream_H__ */


Property changes on: code/branches/output/src/libraries/util/output/OutputStream.h
___________________________________________________________________
Added: svn:eol-style
   + native




More information about the Orxonox-commit mailing list