Changeset 8853 for code/branches/output/src
- Timestamp:
- Aug 21, 2011, 11:18:20 PM (13 years ago)
- Location:
- code/branches/output/src/libraries/util
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/output/src/libraries/util/CMakeLists.txt
r8850 r8853 39 39 SignalHandler.cc 40 40 StringUtils.cc 41 output/OutputStream.cc42 output/OutputManager.cc43 output/OutputListener.cc44 output/BaseWriter.cc45 output/ConsoleWriter.cc46 output/LogWriter.cc47 output/MemoryWriter.cc48 output/SubcontextOutputListener.cc49 41 ) 42 43 ADD_SUBDIRECTORY(output) 50 44 51 45 ORXONOX_ADD_LIBRARY(util -
code/branches/output/src/libraries/util/Output.h
r8848 r8853 45 45 46 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. 47 contexts, to receive only a part of the output. Instances of 48 orxonox::SubcontextOutputListener are even able to filter sub-contexts. 49 A derivative of orxonox::BaseWriter is able to define these levels and 50 contexts through config values. 50 51 51 52 @attention -
code/branches/output/src/libraries/util/output/BaseWriter.cc
r8850 r8853 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the BaseWriter class. 32 */ 33 29 34 #include "BaseWriter.h" 30 35 … … 33 38 namespace orxonox 34 39 { 40 /** 41 @brief Constructor: Initializes the config-values. 42 */ 35 43 BaseWriter::BaseWriter(const std::string& name, bool bRegister) : SubcontextOutputListener(bRegister) 36 44 { … … 46 54 } 47 55 56 /** 57 @brief Destructor. 58 */ 48 59 BaseWriter::~BaseWriter() 49 60 { 50 61 } 51 62 63 /** 64 @brief This function is inherited from OutputListener, each message is split into lines and sent to printLine(). 65 */ 52 66 void BaseWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 53 67 { … … 59 73 } 60 74 75 /** 76 @brief Overwritten implementation of the function inherited from OutputListener, sets also the corresponding config-value. 77 */ 61 78 void BaseWriter::setLevelMax(OutputLevel max) 62 79 { … … 65 82 } 66 83 84 /** 85 @brief Overwritten implementation of the function inherited from OutputListener, sets also the corresponding config-value. 86 */ 67 87 void BaseWriter::setAdditionalContextsLevelMax(OutputLevel max) 68 88 { … … 71 91 } 72 92 93 /** 94 @brief Called if the config value has changed, updates the corresponding mask in OutputListener. 95 */ 73 96 void BaseWriter::changedConfigurableLevel() 74 97 { … … 76 99 } 77 100 101 /** 102 @brief Called if the config value has changed, updates the corresponding mask in OutputListener. 103 */ 78 104 void BaseWriter::changedConfigurableAdditionalContextsLevel() 79 105 { … … 81 107 } 82 108 109 /** 110 @brief Called if the config-vector of accepted contexts has changed, updates the masks in SubcontextOutputListener. 111 */ 83 112 void BaseWriter::changedConfigurableAdditionalContexts() 84 113 { … … 86 115 std::set<const OutputContextContainer*> sub_contexts; 87 116 117 // iterate over all strings in the config-vector 88 118 for (size_t i = 0; i < this->configurableAdditionalContexts_.size(); ++i) 89 119 { 90 120 const std::string& full_name = this->configurableAdditionalContexts_[i]; 91 121 122 // split the name into main-name and sub-name (if given; otherwise sub-name remains empty). both names are separated by :: 92 123 std::string name = full_name; 93 124 std::string subname; … … 100 131 } 101 132 133 // get the context defined by this name 102 134 const OutputContextContainer& context = OutputManager::getInstance().registerContext(name, subname); 103 135 136 // if the context is a sub-context, insert it to the set of sub-contexts. Otherwise add it's mask to the mask of main-contexts. 104 137 if (context.sub_id == context::no_subcontext) 105 138 main_contexts |= context.mask; … … 108 141 } 109 142 143 // pass main-contexts and sub-contexts to SubcontextOutputListener 110 144 this->setAdditionalContextsMask(main_contexts); 111 145 this->setAdditionalSubcontexts(sub_contexts); -
code/branches/output/src/libraries/util/output/BaseWriter.h
r8850 r8853 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Output 32 @brief Declaration of the BaseWriter class, the base of all output writers. 33 */ 34 29 35 #ifndef _BaseWriter_H__ 30 36 #define _BaseWriter_H__ … … 35 41 namespace orxonox 36 42 { 43 /** 44 @brief BaseWriter is an output listener and makes the accepted output levels and contexts configurable. 45 46 All output writers like ConsoleWriter and LogWriter are inherited from 47 this class. BaseWriter itself inherits from SubcontextOutputListener. 48 It adds helper functions to configure the accepted levels and contexts. 49 50 The levels are not fully configurable, only the "max" form is allowed 51 (which means that it's only possible to define a maximum level, not 52 the full mask). 53 54 Contexts are defined by a vector of strings, each context is defined 55 by it's name. Sub-contexts have the form \a "main-name::sub-name", i.e. 56 their name is concatenated with :: in between. 57 58 Each instance of BaseWriter needs a name to generate distinguishable 59 config values. 60 61 Received output messages are split into lines and sent line by line to 62 the virtual printLine() function. Each line has a prepended prefix 63 which describes the level and context of the output. 64 */ 37 65 class _UtilExport BaseWriter : public SubcontextOutputListener 38 66 { … … 44 72 void setAdditionalContextsLevelMax(OutputLevel max); 45 73 74 /// @brief Returns the name of this instance. 46 75 const std::string& getName() const 47 76 { return this->name_; } 48 77 78 /// Config value, used to define the maximum output level (independent of contexts) 49 79 int configurableMaxLevel_; 80 /// @brief Returns the name of the config value which defines the maximum output level (independent of contexts). 50 81 inline std::string getConfigurableMaxLevelName() const 51 82 { return this->name_ + "Level"; } 52 83 84 /// Config value, used to define the maximum output level of additional context 53 85 int configurableAdditionalContextsMaxLevel_; 86 /// @brief Returns the name of the config value which defines the maximum output level of additional context. 54 87 inline std::string getConfigurableAdditionalContextsMaxLevelName() const 55 88 { return this->name_ + "AdditionalContextsLevel"; } 56 89 90 /// Config vector, used to define the additional contexts (and sub-contexts) 57 91 std::vector<std::string> configurableAdditionalContexts_; 92 /// @brief Returns the name of the config vector which defines the additional contexts (and sub-contexts) 58 93 inline std::string getConfigurableAdditionalContextsName() const 59 94 { return this->name_ + "AdditionalContexts"; } … … 63 98 void changedConfigurableAdditionalContexts(); 64 99 100 /// Returns the (static) name of the section wherein the config-values are defined. 65 101 static inline std::string getConfigurableSectionName() 66 102 { return "Output"; } … … 70 106 71 107 private: 72 virtual void printLine(const std::string& line, OutputLevel level) = 0; 108 virtual void printLine(const std::string& line, OutputLevel level) = 0; ///< Pure virtual function, gets called for each line of output together with a prefix which describes level and context of the output. 73 109 74 void setLevelRange(OutputLevel min, OutputLevel max); 75 void setLevelMask(OutputLevel mask); 110 void setLevelRange(OutputLevel min, OutputLevel max); ///< Inherited function, overwritten as private because it is not supported by the config-value 111 void setLevelMask(OutputLevel mask); ///< Inherited function, overwritten as private because it is not supported by the config-value 76 112 77 void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max); 78 void setAdditionalContextsLevelMask(OutputLevel mask); 113 void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max); ///< Inherited function, overwritten as private because it is not supported by the config-value 114 void setAdditionalContextsLevelMask(OutputLevel mask); ///< Inherited function, overwritten as private because it is not supported by the config-value 79 115 80 std::string name_; 116 std::string name_; ///< The name of this instance, used to generate unique config-values 81 117 }; 82 118 } -
code/branches/output/src/libraries/util/output/OutputDefinitions.h
r8848 r8853 58 58 share the context mask of their main-context. This allows contexts with 59 59 more descriptive names (e.g. input::keyboard) and they can be filtered 60 individually by derivatives of orxonox:: BaseWriter.60 individually by derivatives of orxonox::SubcontextOutputListener. 61 61 */ 62 62 #define REGISTER_OUTPUT_SUBCONTEXT(name, subname) \ … … 160 160 REGISTER_OUTPUT_SUBCONTEXT(misc, script); 161 161 } 162 163 162 } 164 163 } -
code/branches/output/src/libraries/util/output/SubcontextOutputListener.cc
r8850 r8853 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the SubcontextOutputListener interface. 32 */ 33 29 34 #include "SubcontextOutputListener.h" 30 35 31 36 namespace orxonox 32 37 { 38 /** 39 @brief Constructor, initializes the context masks. 40 */ 33 41 SubcontextOutputListener::SubcontextOutputListener(bool bRegister) : OutputListener(bRegister) 34 42 { … … 37 45 } 38 46 47 /** 48 @brief Destructor. 49 */ 39 50 SubcontextOutputListener::~SubcontextOutputListener() 40 51 { 41 52 } 42 53 54 /** 55 @brief Overwritten implementation of the function defined by OutputListener. 56 57 Contexts defined with this function are accepted independent of the 58 sub-context. The "final" mask of additional contexts is defined by the 59 combination of this mask and the masks of all accepted sub-contexts. 60 */ 43 61 void SubcontextOutputListener::setAdditionalContextsMask(OutputContextMask mask) 44 62 { … … 48 66 } 49 67 68 /** 69 @brief Defines the set of accepted sub-contexts. 70 71 The masks of sub-contexts in this set are added to the mask of 72 additional contexts, but output is only accepted if the exact 73 sub-context exists in this set. 74 */ 50 75 void SubcontextOutputListener::setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts) 51 76 { … … 53 78 this->subcontexts_.clear(); 54 79 80 // compose the mask of subcontexts and build the set of sub-context-IDs 55 81 for (std::set<const OutputContextContainer*>::const_iterator it = subcontexts.begin(); it != subcontexts.end(); ++it) 56 82 { … … 63 89 64 90 /** 65 @brief Returns true if this listener accepts output of the given level and context, based on the levels , contexts masks, and sub-contexts.91 @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks, as well as the set of accepted sub-contexts. 66 92 */ 67 93 bool SubcontextOutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const -
code/branches/output/src/libraries/util/output/SubcontextOutputListener.h
r8850 r8853 44 44 namespace orxonox 45 45 { 46 /** 47 @brief This class extends the basic OutputListener interface and adds the ability to filter sub-contexts. 48 49 Defining additional contexts with setAdditionalContextsMask() enables 50 all sub-contexts of these additional contexts. To accept only some 51 particular sub-contexts, setAdditionalSubcontexts() has to be used. 52 Note that this requires a set, since a mask is not possible with 53 sub-contexts. 54 55 The "final" context mask which will be seen by OutputManager is the 56 combination of all regular contexts plus the masks of all sub-contexts. 57 58 @remark 59 It would have been possible to implement filtering of sub-contexts 60 directly in OutputListener and even to make OutputManager aware of 61 sub-contexts. This would reduce the amount of unnecessarily generated 62 output, but also increase the complexity of the checks whether some 63 output is needed. 64 On the other hand, filtering of sub-contexts makes the whole concept 65 more complicated, as it adds another mask and a set. So to keep it 66 clean and simple I figured it's best to put sub-context filtering into 67 a seaparate class. 68 */ 46 69 class _UtilExport SubcontextOutputListener : public OutputListener 47 70 { … … 56 79 57 80 private: 58 OutputContextMask subcontextsCheckMask_; 59 OutputContextMask subcontextsNoCheckMask_; 60 std::set<OutputContextSubID> subcontexts_; 81 OutputContextMask subcontextsCheckMask_; ///< All contexts defined by this mask need to be checked whether they are accepted by the set of sub-contexts 82 OutputContextMask subcontextsNoCheckMask_; ///< All contexts defined by this mask don't need to be checked since we accept all sub-contexts 83 std::set<OutputContextSubID> subcontexts_; ///< The set of accepted sub-contexts 61 84 }; 62 85 }
Note: See TracChangeset
for help on using the changeset viewer.