- Timestamp:
- Aug 21, 2011, 4:04:54 PM (13 years ago)
- Location:
- code/branches/output/src/libraries/util
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/output/src/libraries/util/Output.h
r8833 r8848 27 27 */ 28 28 29 /** 30 @defgroup Output Output system 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup Output 37 @brief Defines the helper function orxout() and includes all necessary headers to use the output system. 38 39 The output system is used to write output to the console, the logfile, and 40 other instances of orxonox::OutputListener. Each line of output is assigned 41 a level and a context. The level defines the type and importance of a 42 message, e.g. if it's a fatal error or just some internal information. 43 The context defines to which part of the program the output belongs. 44 Levels and contexts are defined in OutputDefinitions.h 45 46 Each orxonox::OutputListener can define a mask of desired levels and 47 contexts, to receive only a part of the output. A derivative of 48 orxonox::BaseWriter is able to define these masks through config values 49 and to filter specific subcontexts. 50 51 @attention 52 A message sent to the output system MUST end with "endl" or the message 53 won't be flushed. 54 55 @code 56 orxout() << "Debug output" << endl; 57 orxout(user_info) << "Orxonox version 1.2.3" << endl; 58 orxout(internal_status, context::input) << "Loading joystick" << endl; 59 @endcode 60 */ 61 29 62 #ifndef _Output_H__ 30 63 #define _Output_H__ … … 38 71 using std::endl; 39 72 73 /** 74 @brief This helper function returns a reference to a commonly used 75 instance of OutputStream. 76 77 It can be used like std::cout except that it is a function. You can 78 pass level and context of the following output as function arguments. 79 */ 40 80 inline OutputStream& orxout(OutputLevel level = level::debug_output, const OutputContextContainer& context = context::undefined()) 41 81 { … … 45 85 } 46 86 87 /** 88 @brief Shortcut for orxout() to allow passing contexts directly as 89 functions without using "()". 90 91 @code 92 orxout(user_info, context::example) << "Hello World" << endl; // calls this function 93 orxout(user_info, context::example()) << "Hello World" << endl; // calls the other orxout function 94 @endcode 95 */ 47 96 inline OutputStream& orxout(OutputLevel level, OutputContextFunction context) 48 97 { … … 53 102 inline __DEPRECATED__(OutputStream& COUT(int level)); 54 103 104 /** 105 @brief Writes output to the orxonox console. This function is deprecated, please use orxout() 106 @note The output level argument is ignored since it's not supported anymore. See orxout() for the new output levels. 107 @deprecated This function is deprecated. Use orxout() instead. 108 */ 55 109 inline OutputStream& COUT(int) 56 110 { -
code/branches/output/src/libraries/util/output/ConsoleWriter.cc
r8799 r8848 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the ConsoleWriter singleton. 32 */ 33 29 34 #include "ConsoleWriter.h" 30 35 … … 35 40 namespace orxonox 36 41 { 42 /** 43 @brief Constructor, initializes the output level. 44 45 In debug builds, it writes output up to level::internal_warning to the 46 console, in release builds only up to level::user_info. 47 48 After creation, the instance is enabled. 49 */ 37 50 ConsoleWriter::ConsoleWriter() : BaseWriter("Console") 38 51 { … … 45 58 } 46 59 60 /** 61 @brief Destructor. 62 */ 47 63 ConsoleWriter::~ConsoleWriter() 48 64 { 49 65 } 50 66 67 /** 68 @brief Returns the only existing instance of this class. 69 */ 51 70 /*static*/ ConsoleWriter& ConsoleWriter::getInstance() 52 71 { … … 55 74 } 56 75 76 /** 77 @brief Inherited function from BaseWriter, writes output to the console using std::cout. 78 */ 57 79 void ConsoleWriter::printLine(const std::string& line, OutputLevel) 58 80 { … … 60 82 } 61 83 84 /** 85 @brief Enables the instance by registering itself as listener at OutputManager. 86 */ 62 87 void ConsoleWriter::enable() 63 88 { … … 69 94 } 70 95 96 /** 97 @brief Disables the instance by unregistering itself from OutputManager. 98 */ 71 99 void ConsoleWriter::disable() 72 100 { -
code/branches/output/src/libraries/util/output/ConsoleWriter.h
r8795 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the ConsoleWriter singleton which is used to write output to the console. 33 */ 34 29 35 #ifndef _ConsoleWriter_H__ 30 36 #define _ConsoleWriter_H__ … … 35 41 namespace orxonox 36 42 { 43 /** 44 @brief ConsoleWriter inherits from BaseWriter and writes output to the console. 45 46 This class can be seen as an equivalent to std::cout within the output 47 system. It is implemented as a singleton for static acces. 48 */ 37 49 class _UtilExport ConsoleWriter : public BaseWriter 38 50 { … … 51 63 virtual ~ConsoleWriter(); 52 64 53 bool bEnabled_; 65 bool bEnabled_; ///< If false, the instance will not write output to the console. 54 66 }; 55 67 } -
code/branches/output/src/libraries/util/output/LogWriter.cc
r8833 r8848 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the LogWriter singleton. 32 */ 33 29 34 #include "LogWriter.h" 30 35 … … 37 42 namespace orxonox 38 43 { 44 /** 45 @brief Constructor, initializes the desired output levels and the name and path of the log-file, and opens the log-file. 46 47 By default, LogWriter receives all output up to level::internal_info. 48 The log-file has a default name which usually doesn't change. The path 49 is initialized with a temporary directory, depending on the system, 50 and can be changed later. 51 */ 39 52 LogWriter::LogWriter() : BaseWriter("Log") 40 53 { … … 43 56 this->filename_ = "orxonox.log"; 44 57 45 // Get path for a temporary file58 // get the path for a temporary file, depending on the system 46 59 #ifdef ORXONOX_PLATFORM_WINDOWS 47 60 this->path_ = getenv("TEMP"); … … 54 67 } 55 68 69 /** 70 @brief Destructor, closes the log-file. 71 */ 56 72 LogWriter::~LogWriter() 57 73 { … … 59 75 } 60 76 77 /** 78 @brief Returns the only existing instance of this class. 79 */ 61 80 /*static*/ LogWriter& LogWriter::getInstance() 62 81 { … … 65 84 } 66 85 86 /** 87 @brief Opens the log-file in order to write output to it. 88 */ 67 89 void LogWriter::openFile() 68 90 { 91 // get the full file-name 69 92 std::string name = this->path_ + '/' + this->filename_; 70 93 94 // if we open the log file in the default directory, send a message to the user so that he can find the file in the case of a crash. 71 95 if (this->bDefaultPath_) 72 96 OutputManager::getInstance().pushMessage(level::user_info, context::undefined(), "Opening log file " + name); 73 97 98 // open the file 74 99 this->file_.open(name.c_str(), std::fstream::out); 75 100 101 // check if it worked and print some output 76 102 if (this->file_.is_open()) 77 103 this->printLine("Log file opened", level::none); … … 80 106 } 81 107 108 /** 109 @brief Closes the log-file. 110 */ 82 111 void LogWriter::closeFile() 83 112 { … … 89 118 } 90 119 120 /** 121 @brief Changes the path of the log-file. Re-writes the log-file by using MemoryWriter. 122 */ 91 123 void LogWriter::setLogPath(const std::string& path) 92 124 { 125 // notify about the change of the log-file (because the old file will no longer be updated) 93 126 OutputManager::getInstance().pushMessage(level::internal_info, context::undefined(), "Migrating log file from " + this->path_ + "\nto " + path); 94 127 128 // close the old file, update the path and open the new file 95 129 this->closeFile(); 96 130 this->path_ = path; … … 98 132 this->openFile(); 99 133 134 // request old output from MemoryWriter 100 135 MemoryWriter::getInstance().resendOutput(this); 101 136 } 102 137 138 /** 139 @brief Inherited function from BaseWriter, writers output together with a timestamp to the log-file. 140 */ 103 141 void LogWriter::printLine(const std::string& line, OutputLevel) 104 142 { … … 106 144 return; 107 145 108 // Getcurrent time146 // get the current time 109 147 time_t rawtime; 110 148 struct tm* timeinfo; … … 112 150 timeinfo = localtime(&rawtime); 113 151 114 // print timestamp and line to the log file152 // print timestamp and output line to the log file 115 153 this->file_ << (timeinfo->tm_hour < 10 ? "0" : "") << timeinfo->tm_hour << ':' << 116 154 (timeinfo->tm_min < 10 ? "0" : "") << timeinfo->tm_min << ':' << -
code/branches/output/src/libraries/util/output/LogWriter.h
r8795 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the LogWriter singleton which writes output to a log-file. 33 */ 34 29 35 #ifndef _LogWriter_H__ 30 36 #define _LogWriter_H__ … … 38 44 namespace orxonox 39 45 { 46 /** 47 @brief The LogWriter class inherits from BaseWriter and writes output to a log-file. 48 49 It is implemented as singleton because we (currently) use only one 50 log-file. The path of the file can be changed, in which case the file 51 is rewritten by using the output stored by MemoryWriter. This adds the 52 possibility to change the desired output levels before changing the 53 path in order to get the complete output with the new output levels 54 at the new path. 55 */ 40 56 class _UtilExport LogWriter : public BaseWriter 41 57 { … … 56 72 void closeFile(); 57 73 58 std::string filename_; 59 std::string path_; 60 bool bDefaultPath_; 74 std::string filename_; ///< The name of the log-file (without directories) 75 std::string path_; ///< The path of the log-file (without file-name) 76 bool bDefaultPath_; ///< If true, the log-file resides at the default path (which is usually a temporary directory) 61 77 62 std::ofstream file_; 78 std::ofstream file_; ///< The output file stream. 63 79 }; 64 80 } -
code/branches/output/src/libraries/util/output/MemoryWriter.cc
r8833 r8848 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the MemoryWriter singleton. 32 */ 33 29 34 #include "MemoryWriter.h" 30 31 35 #include "OutputManager.h" 32 36 33 37 namespace orxonox 34 38 { 39 /** 40 @brief Constructor, initializes the level mask with all levels activated. 41 */ 35 42 MemoryWriter::MemoryWriter() 36 43 { … … 38 45 } 39 46 47 /** 48 @brief Destructor. 49 */ 40 50 MemoryWriter::~MemoryWriter() 41 51 { 42 52 } 43 53 54 /** 55 @brief Returns the only existing instance of this singleton class. 56 */ 44 57 /*static*/ MemoryWriter& MemoryWriter::getInstance() 45 58 { … … 48 61 } 49 62 63 /** 64 @brief Implementation of the output() function inherited from OutputListener, stores the received output in memory. 65 */ 50 66 void MemoryWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 51 67 { … … 53 69 } 54 70 71 /** 72 @brief Iterates over all stored output messages and sends them to the OutputListener. 73 */ 55 74 void MemoryWriter::resendOutput(OutputListener* listener) const 56 75 { … … 62 81 } 63 82 83 /** 84 @brief Unregisters the instance from OutputManager, hence it will not receive any further output. 85 */ 64 86 void MemoryWriter::disable() 65 87 { -
code/branches/output/src/libraries/util/output/MemoryWriter.h
r8833 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the MemoryWriter singleton. 33 */ 34 29 35 #ifndef _MemoryWriter_H__ 30 36 #define _MemoryWriter_H__ … … 35 41 namespace orxonox 36 42 { 43 /** 44 @brief MemoryWriter is a singleton which is derived from OutputListener and writes all output to a list. 45 46 This list can be used to re-send old output to other instances of 47 OutputListener, e.g. if they were newly created or to re-write the 48 log-file. 49 50 Since MemoryWriter receives output of all levels, this means also that 51 all possible output needs to be generated as long as MemoryWriter stays 52 active. Hence disable() should be called as soon as possible. 53 */ 37 54 class _UtilExport MemoryWriter : public OutputListener 38 55 { 56 /// @brief A helper struct which is used to store output and its properties. 39 57 struct Message 40 58 { 59 /// @brief Constructor, assigns all values. 41 60 Message(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 42 61 : level(level), context(&context), lines(lines) {} 43 62 44 OutputLevel level; 45 const OutputContextContainer* context; 46 std::vector<std::string> lines; 63 OutputLevel level; ///< The level of the output message 64 const OutputContextContainer* context; ///< The context of the output message 65 std::vector<std::string> lines; ///< The lines of text of the output message 47 66 }; 48 67 … … 61 80 virtual ~MemoryWriter(); 62 81 63 std::vector<Message> messages_; 82 std::vector<Message> messages_; ///< Stores all output messages from the creation of this instance until disable() is called. 64 83 }; 65 84 } -
code/branches/output/src/libraries/util/output/OutputDefinitions.h
r8840 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Defines output levels and output contexts. 33 */ 34 29 35 #ifndef _OutputDefinitions_H__ 30 36 #define _OutputDefinitions_H__ … … 33 39 #include <string> 34 40 41 /** 42 @brief Defines a context function with a given name. 43 @param name Name of the context 44 45 Context functions return a reference to a OutputContextContainer. Context 46 functions (or the containers they return) can be passed to orxout() as 47 context argument. 48 */ 35 49 #define REGISTER_OUTPUT_CONTEXT(name) \ 36 50 const OutputContextContainer& name() { static const OutputContextContainer& context = registerContext(#name); return context; } 37 51 52 /** 53 @brief Defines a sub-context. 54 @param name Name of the main-context 55 @param subname Name of the sub-context 56 57 Sub-contexts act like normal contexts, except that multiple sub-contexts 58 share the context mask of their main-context. This allows contexts with 59 more descriptive names (e.g. input::keyboard) and they can be filtered 60 individually by derivatives of orxonox::BaseWriter. 61 */ 38 62 #define REGISTER_OUTPUT_SUBCONTEXT(name, subname) \ 39 63 const OutputContextContainer& subname() { static const OutputContextContainer& context = registerContext(#name, #subname); return context; } … … 44 68 namespace level 45 69 { 70 /** 71 @brief Output levels define type and importance of an output message. 72 They can be passed to the orxout() function as level argument. 73 */ 46 74 enum OutputLevel 47 75 { 48 all = 0xFFFF, 49 none = 0x0000, 76 all = 0xFFFF, ///< Level mask with all bits set to 1 77 none = 0x0000, ///< Level mask with all bits set to 0 50 78 51 message = 0x0001, 52 debug_output = 0x0002, 53 user_error = 0x0004, 54 user_warning = 0x0008, 55 user_status = 0x0010, 56 user_info = 0x0020, 57 internal_error = 0x0040, 58 internal_warning = 0x0080, 59 internal_status = 0x0100, 60 internal_info = 0x0200, 61 verbose = 0x0400, 62 verbose_more = 0x0800, 63 verbose_ultra = 0x1000 79 message = 0x0001, ///< Output level, used for messages directed to the user (e.g. "Press any key to continue") 80 debug_output = 0x0002, ///< Output level, used for temporary debug output while writing code 81 user_error = 0x0004, ///< Output level, used for error messages which are important for the user 82 user_warning = 0x0008, ///< Output level, used for warnings which are important for the user 83 user_status = 0x0010, ///< Output level, used to notify the user about the program's state 84 user_info = 0x0020, ///< Output level, used to provide the user with additional progress information 85 internal_error = 0x0040, ///< Output level, used for error messages which are important for developers 86 internal_warning = 0x0080, ///< Output level, used for warnings which are important for developers 87 internal_status = 0x0100, ///< Output level, used to log the program's internal state in the log file 88 internal_info = 0x0200, ///< Output level, used to log information about the program's progress in the log file 89 verbose = 0x0400, ///< Output level, usually not visible, used for unimportant debug information 90 verbose_more = 0x0800, ///< Output level, usually not visible, used for unimportant debug information (less important than verbose) 91 verbose_ultra = 0x1000 ///< Output level, usually not visible, used for unimportant debug information (even less important than verbose_more) 64 92 }; 65 93 } … … 68 96 using namespace level; 69 97 70 typedef uint64_t OutputContextMask; 71 typedef uint16_t OutputContextSubID; 98 typedef uint64_t OutputContextMask; ///< Used to store the context masks. Each bit defines a context. 99 typedef uint16_t OutputContextSubID; ///< Used to store the IDs of sub-contexts. Each number except context::no_subcontext defines a sub-context. 72 100 101 /// @brief Stores all information about a context. 73 102 struct OutputContextContainer 74 103 { 75 OutputContextMask mask; 76 OutputContextSubID sub_id; 77 std::string name; 104 OutputContextMask mask; ///< The mask of the context (or the mask of the main-context if this container defines a sub-context) 105 OutputContextSubID sub_id; ///< The id of the sub-context (or context::no_subcontext if this container doesn't define a sub-context) 106 std::string name; ///< The name of this context 78 107 }; 79 108 80 109 typedef const OutputContextContainer& (OutputContextFunction)(); 81 110 111 /** 112 @brief Registers a context. 113 This is a shortcut to OutputManager::registerContext() to avoid the inclusion of its header file. 114 */ 82 115 extern _UtilExport const OutputContextContainer& registerContext(const std::string& name, const std::string& subname = ""); 83 116 84 117 namespace context 85 118 { 86 static const OutputContextMask all = 0xFFFFFFFFFFFFFFFF; 87 static const OutputContextMask none = 0x0000000000000000; 119 static const OutputContextMask all = 0xFFFFFFFFFFFFFFFF; ///< Context mask, all bits set to 1 120 static const OutputContextMask none = 0x0000000000000000; ///< Context mask, all bits set to 0 88 121 89 static const OutputContextSubID no_subcontext = 0; 122 static const OutputContextSubID no_subcontext = 0; ///< Used as ID for contexts which are not sub-contexts 90 123 91 124 namespace 92 125 { 93 REGISTER_OUTPUT_CONTEXT(undefined); 126 REGISTER_OUTPUT_CONTEXT(undefined); ///< "undefined" context which is implicitly used for all output that has no explicit context 94 127 95 128 REGISTER_OUTPUT_CONTEXT(ogre); -
code/branches/output/src/libraries/util/output/OutputListener.cc
r8834 r8848 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the OutputListener class. 32 */ 33 29 34 #include "OutputListener.h" 30 35 … … 33 38 namespace orxonox 34 39 { 40 /** 41 @brief Constructor, initializes the values and registers the instance at OutputManager if requested. 42 @param bRegister If \c true, the instance is automatically registered at OutputManager. 43 Should be \c false if the constructor of the derived class generates output. 44 */ 35 45 OutputListener::OutputListener(bool bRegister) 36 46 { … … 43 53 } 44 54 55 /** 56 @brief Destructor, unregisters the instance from OutputManager. 57 */ 45 58 OutputListener::~OutputListener() 46 59 { … … 48 61 } 49 62 63 /** 64 @brief Defines the level mask in a way which accepts all output up to the level \c max. 65 */ 50 66 void OutputListener::setLevelMax(OutputLevel max) 51 67 { … … 53 69 } 54 70 71 /** 72 @brief Defines the level mask in a way which accepts all output between the levels \c min and \c max. 73 */ 55 74 void OutputListener::setLevelRange(OutputLevel min, OutputLevel max) 56 75 { … … 62 81 } 63 82 83 /** 84 @brief Defines the level mask. 85 */ 64 86 void OutputListener::setLevelMask(OutputLevel mask) 65 87 { … … 69 91 } 70 92 93 /** 94 @brief Defines the level mask of additional contexts in a way which accepts all output up to the level \c max. 95 */ 71 96 void OutputListener::setAdditionalContextsLevelMax(OutputLevel max) 72 97 { … … 74 99 } 75 100 101 /** 102 @brief Defines the level mask of additional contexts in a way which accepts all output between the levels \c min and \c max. 103 */ 76 104 void OutputListener::setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max) 77 105 { … … 83 111 } 84 112 113 /** 114 @brief Defines the level mask of additional contexts. 115 */ 85 116 void OutputListener::setAdditionalContextsLevelMask(OutputLevel mask) 86 117 { … … 90 121 } 91 122 123 /** 124 @brief Defines the mask of additional contexts. 125 */ 92 126 void OutputListener::setAdditionalContextsMask(OutputContextMask mask) 93 127 { -
code/branches/output/src/libraries/util/output/OutputListener.h
r8834 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the OutputListener interface which receives output 33 from orxonox::OutputManager. 34 */ 35 29 36 #ifndef _OutputListener_H__ 30 37 #define _OutputListener_H__ … … 38 45 namespace orxonox 39 46 { 47 /** 48 @brief OutputListener is an interface which is used to receive output of a certain level and context from OutputManager. 49 */ 50 // See below the class declaration for a more detailed description. 40 51 class _UtilExport OutputListener 41 52 { … … 54 65 void setAdditionalContextsMask(OutputContextMask mask); 55 66 67 /// @brief Returns the level mask. 56 68 inline OutputLevel getLevelMask() const 57 69 { return this->levelMask_; } 70 /// @brief Returns the additional contexts mask. 71 inline OutputContextMask getAdditionalContextsMask() const 72 { return this->additionalContextsMask_; } 73 /// @brief Returns the additional contexts level mask. 58 74 inline OutputLevel getAdditionalContextsLevelMask() const 59 75 { return this->additionalContextsLevelMask_; } 60 inline OutputContextMask getAdditionalContextsMask() const61 { return this->additionalContextsMask_; }62 76 77 /// @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks. 63 78 inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const 64 79 { … … 66 81 ((this->additionalContextsLevelMask_ & level) && (this->additionalContextsMask_ & context.mask)); } 67 82 83 /// @brief Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function. 68 84 inline void unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 69 85 { if (this->acceptsOutput(level, context)) this->output(level, context, lines); } 70 86 71 87 protected: 88 /// @brief Pure virtual function, needs to be implemented in order to receive output. 72 89 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0; 73 90 74 91 private: 75 OutputLevel levelMask_; 76 Output Level additionalContextsLevelMask_;77 Output ContextMask additionalContextsMask_;92 OutputLevel levelMask_; ///< Mask of accepted output levels, independent of contexts 93 OutputContextMask additionalContextsMask_; ///< Mask of accepted additional contexts 94 OutputLevel additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts 78 95 }; 96 97 /** 98 @class OutputListener 99 100 An instance of OutputListener registers itself at OutputManager and 101 declares the desired output levels and contexts. OutputManager will 102 then send output to it by calling the output() function. 103 104 OutputListener has 3 masks to define the desired output. These masks 105 can be used in two different ways (or as a combination of both): 106 \li 1. By defining the \a "level mask": The OutputListener will then 107 receive all output of these levels independent of the context. 108 \li 2. By defining the \a "additional contexts mask" and the 109 \a "additional contexts level mask": This way the listener 110 receives only output of a particular context and level. 111 \li 3. By using all 3 masks which combines the output defined by the 112 first two ways. 113 114 This can be illustrated as follows: 115 116 1. Only level mask: 117 \li level-mask = error | warning; 118 119 @verbatim 120 | Contexts: | 121 | A | B | C | D | 122 --------|---|---|---|---| 123 debug | - | - | - | - | 124 --------|---|---|---|---| 125 error | x | x | x | x | 126 --------|---|---|---|---| [x] Receives output 127 warning | x | x | x | x | [-] Does not receive output 128 --------|---|---|---|---| 129 status | - | - | - | - | 130 --------|---|---|---|---| 131 verbose | - | - | - | - | 132 --------|---|---|---|---| 133 @endverbatim 134 135 2. Only additional contexts: 136 \li additional-contexts-mask = B | D; 137 \li additional-contexts-level-mask = debug | verbose; 138 139 @verbatim 140 | Contexts: | 141 | A | B | C | D | 142 --------|---|---|---|---| 143 debug | - | x | - | x | 144 --------|---|---|---|---| 145 error | - | - | - | - | 146 --------|---|---|---|---| [x] Receives output 147 warning | - | - | - | - | [-] Does not receive output 148 --------|---|---|---|---| 149 status | - | - | - | - | 150 --------|---|---|---|---| 151 verbose | - | x | - | x | 152 --------|---|---|---|---| 153 @endverbatim 154 155 3. Both level mask plus additional contexts: 156 \li level-mask = error | warning; 157 \li additional-contexts-mask = B | D; 158 \li additional-contexts-level-mask = debug | verbose; 159 160 @verbatim 161 | Contexts: | 162 | A | B | C | D | 163 --------|---|---|---|---| 164 debug | - | x | - | x | 165 --------|---|---|---|---| 166 error | x | x | x | x | 167 --------|---|---|---|---| [x] Receives output 168 warning | x | x | x | x | [-] Does not receive output 169 --------|---|---|---|---| 170 status | - | - | - | - | 171 --------|---|---|---|---| 172 verbose | - | x | - | x | 173 --------|---|---|---|---| 174 @endverbatim 175 */ 79 176 } 80 177 -
code/branches/output/src/libraries/util/output/OutputManager.cc
r8833 r8848 26 26 * 27 27 */ 28 29 /** 30 @file 31 @brief Implementation of the OutputManager singleton. 32 */ 28 33 29 34 #include "OutputManager.h" … … 37 42 namespace orxonox 38 43 { 44 /** 45 @brief Constructor, initializes all values. 46 */ 39 47 OutputManager::OutputManager() 40 48 { … … 46 54 } 47 55 56 /** 57 @brief Destructor. 58 */ 48 59 OutputManager::~OutputManager() 49 60 { 50 61 } 51 62 63 /** 64 @brief Returns the only existing instance of the OutputManager singleton. 65 */ 52 66 /*static*/ OutputManager& OutputManager::getInstance() 53 67 { … … 56 70 } 57 71 72 /** 73 @brief Returns the only existing instance of the OutputManager singleton 74 and ensures that the most important output listeners exist. 75 76 You should use this function if you send output to OutputManager and want 77 to be sure that the most important output listeners exist. Don't use it 78 elsewhere inside the output system to avoid circular calls. 79 */ 58 80 /*static*/ OutputManager& OutputManager::getInstanceAndCreateListeners() 59 81 { … … 67 89 } 68 90 91 /** 92 @brief Sends an output message to all output listeners. 93 @param level The level of the message 94 @param context The context of the message 95 @param message The output message (may contain '\\n') 96 97 This function splits the message into lines (if it contains '\\n') and 98 sends it to the output listeners. They may ignore the message if it 99 doesn't match their level- and context-masks. 100 */ 69 101 void OutputManager::pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message) 70 102 { … … 76 108 } 77 109 110 /** 111 @brief Adds an output listener to the list of listeners. 112 */ 78 113 void OutputManager::registerListener(OutputListener* listener) 79 114 { … … 82 117 } 83 118 119 /** 120 @brief Removes an output listener from the list of listeners. 121 */ 84 122 void OutputManager::unregisterListener(OutputListener* listener) 85 123 { … … 95 133 } 96 134 135 /** 136 @brief Updates all three combined level- and context-masks. 137 */ 97 138 void OutputManager::updateMasks() 98 139 { … … 102 143 } 103 144 145 /** 146 @brief Updates the combined level mask. The masks of all listeners are ORed to form the combined mask. 147 */ 104 148 void OutputManager::updateCombinedLevelMask() 105 149 { … … 110 154 } 111 155 156 /** 157 @brief Updates the combined additional contexts level mask. The masks of all listeners are ORed to form the combined mask. 158 */ 112 159 void OutputManager::updateCombinedAdditionalContextsLevelMask() 113 160 { … … 118 165 } 119 166 167 /** 168 @brief Updates the combined additional contexts mask. The masks of all listeners are ORed to form the combined mask. 169 */ 120 170 void OutputManager::updateCombinedAdditionalContextsMask() 121 171 { … … 125 175 } 126 176 177 /** 178 @brief Registers a context (or sub-context) and returns the container which identifies the context. 179 @param name The name of the context 180 @param subname The name of the sub-context (or "" if it is not a sub-context) 181 182 If the context doesn't exist, it gets created. Otherwise the existing instance is returned. 183 */ 127 184 const OutputContextContainer& OutputManager::registerContext(const std::string& name, const std::string& subname) 128 185 { 186 // the full name of a context is a combination of name and subname with "::" in between 129 187 std::string full_name = name; 130 188 if (subname != "") 131 189 full_name += "::" + subname; 132 190 191 // check if the context already exists (and return it if it does) 133 192 std::map<std::string, OutputContextContainer>::iterator it_container = this->contextContainers_.find(full_name); 134 193 if (it_container != this->contextContainers_.end()) 135 194 return it_container->second; 136 195 196 // create a new context container 137 197 OutputContextContainer container; 138 198 container.name = full_name; 139 199 200 // check if the mask of the main-context already exists 140 201 std::map<std::string, OutputContextMask>::iterator it_mask = this->contextMasks_.find(name); 141 202 if (it_mask != this->contextMasks_.end()) 142 203 { 204 // the mask exists, assign it to the container 143 205 container.mask = it_mask->second; 144 206 } 145 207 else 146 208 { 209 // the mask doesn't exist, create it. It's a binary mask. The n-th main-context is defined by the n-th bit in the mask. 147 210 container.mask = static_cast<OutputContextMask>(0x1) << this->contextMasks_.size(); 148 211 this->contextMasks_[name] = container.mask; … … 152 215 } 153 216 217 // if the context is a sub-context, assign a unique ID. 154 218 if (subname == "") 155 219 container.sub_id = context::no_subcontext; … … 157 221 container.sub_id = ++this->subcontextCounter_; // start with 1 158 222 223 // add the new context to the map and return it 159 224 return (this->contextContainers_[full_name] = container); 160 225 } 161 226 227 /** 228 @brief Static function, shortcut to OutputManager::registerContext(). 229 The function is declared in OutputDefinitions.h. 230 */ 162 231 const OutputContextContainer& registerContext(const std::string& name, const std::string& subname) 163 232 { … … 165 234 } 166 235 236 /** 237 @brief Returns a human readable string for each output level. 238 */ 167 239 const std::string& OutputManager::getLevelName(OutputLevel level) const 168 240 { 169 241 switch (level) 170 242 { 243 // using static cache variables for speed 171 244 case level::none: { static std::string name = "None"; return name; } 172 245 case level::message: { static std::string name = "Message"; return name; } … … 187 260 } 188 261 262 /** 263 @brief Returns a string containing the name of the level and the context (if any) which 264 can be prepended to an output message if it is written to the console or the log file. 265 */ 189 266 std::string OutputManager::getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const 190 267 { 268 // "undefined" context is ignored because it's used implicitly if no explicit context is defined 191 269 static OutputContextMask undefined_mask = context::undefined().mask; 192 270 -
code/branches/output/src/libraries/util/output/OutputManager.h
r8833 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the OutputManager class which receives output from orxonox::OutputStream 33 and distributes it to all instances of orxonox::OutputListener. 34 */ 35 29 36 #ifndef _OutputManager_H__ 30 37 #define _OutputManager_H__ … … 39 46 namespace orxonox 40 47 { 48 /** 49 @brief OutputManager acts as the center of the output system and is implemented as a singleton. 50 51 All instances of OutputStream (and hence also the orxout() function) 52 send their buffered output to OutputManager. OutputManager then 53 distributes this output to all registered instances of OutputListener. 54 55 For each listener OutputManager checks if it wants to receive output 56 with the given level and context. OutputManager itself also maintains 57 masks that define the accepted levels and concept. They are a 58 combination of the masks of all output listeners. See the description 59 of OutputListener for a more conclusive description of these masks. 60 61 Additionally OutputManager is used to register output contexts. 62 */ 41 63 class _UtilExport OutputManager 42 64 { … … 55 77 void updateCombinedAdditionalContextsMask(); 56 78 79 /** 80 @brief Returns true if at least one of the output listeners will accept output with the given level and context. 81 82 For the sake of performance, output messages with levels or 83 contexts that are not accepted should be ignored or, even 84 better, not generated at all. 85 */ 57 86 inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const 58 87 { … … 71 100 ~OutputManager(); 72 101 73 std::vector<OutputListener*> listeners_; 102 std::vector<OutputListener*> listeners_; ///< List of all registered output listeners 74 103 75 OutputLevel combinedLevelMask_; 76 OutputLevel combinedAdditionalContextsLevelMask_; 77 OutputContextMask combinedAdditionalContextsMask_; 104 OutputLevel combinedLevelMask_; ///< The combined mask of accepted levels of all listeners 105 OutputLevel combinedAdditionalContextsLevelMask_; ///< The combined mask of accepted additional contexts levels of all listeners 106 OutputContextMask combinedAdditionalContextsMask_; ///< The combined mask of accepted additional contexts of all listeners 78 107 79 std::map<std::string, OutputContextMask> contextMasks_; 80 std::map<std::string, OutputContextContainer> contextContainers_; 81 OutputContextSubID subcontextCounter_; 108 std::map<std::string, OutputContextMask> contextMasks_; ///< Contains all main-contexts and their masks 109 std::map<std::string, OutputContextContainer> contextContainers_; ///< Contains all contexts including sub-contexts and their containers 110 OutputContextSubID subcontextCounter_; ///< Counts the number of sub-contexts (and generates their IDs) 82 111 }; 83 112 } -
code/branches/output/src/libraries/util/output/OutputStream.cc
r8833 r8848 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the non-generic functions of the OutputStream class. 32 */ 33 29 34 #include "OutputStream.h" 30 35 … … 33 38 namespace orxonox 34 39 { 40 /** 41 @brief Default constructor, initializes level and context with default values. 42 */ 35 43 OutputStream::OutputStream() 36 44 { … … 38 46 } 39 47 48 /** 49 @brief Constructor, initializes level and context with the provided values. 50 */ 40 51 OutputStream::OutputStream(OutputLevel level, const OutputContextContainer& context) 41 52 { … … 43 54 } 44 55 56 /** 57 @brief Sends the buffered message to OutputManager together with the stored level and context. 58 Additionally empties the buffer. 59 */ 45 60 void OutputStream::sendMessage() 46 61 { … … 49 64 } 50 65 66 /** 67 @brief Defines level and context of the following output. 68 Also sets the bAcceptsOutput_ flag according to the masks defined in OutputManager. 69 */ 51 70 void OutputStream::setOutputAttributes(OutputLevel level, const OutputContextContainer& context) 52 71 { -
code/branches/output/src/libraries/util/output/OutputStream.h
r8833 r8848 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the OutputStream class which is used to send output to orxonox::OutputManager. 33 */ 34 29 35 #ifndef _OutputStream_H__ 30 36 #define _OutputStream_H__ … … 38 44 namespace orxonox 39 45 { 46 /** 47 @brief This class is used to buffer output and send it to OutputManager whenever std::endl is passed to it. 48 49 OutputStream inherits from std::ostringstream and acts like std::cout. 50 This means you can use the << operator to write output to the stream. 51 This class is used by the orxout() function. 52 53 @attention 54 You must end an output message with std::endl, otherwise the message 55 won't be flushed. '\\n' only adds a new line to the message. 56 57 The following code samples are all equivalent: 58 @code 59 OutputStream stream; 60 stream.setOutputAttributes(user_info, context::example()); 61 stream << "Hello World" << endl; 62 @endcode 63 64 @code 65 OutputStream stream(user_info, context::example()); 66 stream << "Hello World" << endl; 67 @endcode 68 69 @code 70 orxout(user_info, context::example) << "Hello World" << endl; 71 @endcode 72 */ 40 73 class OutputStream : public std::ostringstream 41 74 { … … 48 81 void _UtilExport setOutputAttributes(OutputLevel level, const OutputContextContainer& context); 49 82 83 /// @brief Generic << operator which adds output to the stream. 50 84 template <class T> 51 85 inline OutputStream& operator<<(const T& val) { return this->output(val); } 86 /// @brief Sends a manipulator to the output stream. 52 87 inline OutputStream& operator<<(std::ios_base& (*manipulator)(std::ios_base&)) { return this->output(manipulator); } 88 /// @brief Sends a manipulator to the output stream. 53 89 inline OutputStream& operator<<(std::ios& (*manipulator)(std::ios&)) { return this->output(manipulator); } 90 /// @brief Sends a manipulator to the output stream and flushes the message if the manipulator is std::endl. 54 91 inline OutputStream& operator<<(std::ostream& (*manipulator)(std::ostream&)) 55 92 { … … 57 94 { 58 95 if (manipulator == static_cast<EndlType>(std::endl)) 59 this->sendMessage(); 96 this->sendMessage(); // send the message to OutputManager 60 97 else 61 return this->output(manipulator); 98 return this->output(manipulator); // apply the manipulator 62 99 } 63 100 return *this; … … 65 102 66 103 private: 104 /// @brief Generic function to add values to the output stream, using the inherited << operator from std::ostringstream. 67 105 template <class T> 68 106 inline OutputStream& output(const T& val) … … 75 113 void _UtilExport sendMessage(); 76 114 77 OutputLevel level_; 78 const OutputContextContainer* context_; 79 bool bAcceptsOutput_; 115 OutputLevel level_; ///< The output level of the current message 116 const OutputContextContainer* context_; ///< The output context of the current message 117 bool bAcceptsOutput_; ///< After defining level and context of the following message, this flag is set according to the masks defined in OutputManager. If it is false, the OutputStream will throw away every output sent using the << operator. 80 118 }; 81 119 }
Note: See TracChangeset
for help on using the changeset viewer.