Changeset 11071 for code/trunk/src/libraries/util/output
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/output/BaseWriter.cc
r8858 r11071 47 47 this->configurableMaxLevel_ = level::none; 48 48 this->configurableAdditionalContextsMaxLevel_ = level::verbose; 49 this->configurableAdditionalContexts_. push_back("example");49 this->configurableAdditionalContexts_.emplace_back("example"); 50 50 51 51 this->changedConfigurableLevel(); … … 116 116 117 117 // iterate over all strings in the config-vector 118 for ( size_t i = 0; i < this->configurableAdditionalContexts_.size(); ++i)118 for (const std::string& full_name : this->configurableAdditionalContexts_) 119 119 { 120 const std::string& full_name = this->configurableAdditionalContexts_[i];121 122 120 // split the name into main-name and sub-name (if given; otherwise sub-name remains empty). both names are separated by :: 123 121 std::string name = full_name; -
code/trunk/src/libraries/util/output/BaseWriter.h
r8858 r11071 103 103 104 104 protected: 105 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) ;105 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) override; 106 106 107 107 private: -
code/trunk/src/libraries/util/output/ConsoleWriter.h
r9550 r11071 53 53 public: 54 54 ConsoleWriter(std::ostream& outputStream); 55 ConsoleWriter(const ConsoleWriter&);56 55 virtual ~ConsoleWriter(); 57 56 … … 63 62 64 63 protected: 65 virtual void printLine(const std::string& line, OutputLevel level) ;64 virtual void printLine(const std::string& line, OutputLevel level) override; 66 65 67 66 private: 67 // non-copyable: 68 ConsoleWriter(const ConsoleWriter&) = delete; 69 ConsoleWriter& operator=(const ConsoleWriter&) = delete; 70 68 71 std::ostream& outputStream_; ///< The ostream to which the console writer writes its output 69 72 bool bEnabled_; ///< If false, the instance will not write output to the console. -
code/trunk/src/libraries/util/output/LogWriter.cc
r9550 r11071 35 35 36 36 #include <ctime> 37 #include <chrono> 37 38 #include <cstdlib> 38 39 … … 43 44 namespace orxonox 44 45 { 45 static const int MAX_ARCHIVED_FILES = 9;46 static constexpr int MAX_ARCHIVED_FILES = 9; 46 47 47 48 /** … … 180 181 return; 181 182 183 // get the milliseconds 184 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 185 std::chrono::system_clock::duration timeSinceEpoch = now.time_since_epoch(); 186 std::chrono::milliseconds millisSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(timeSinceEpoch); 187 unsigned int millis = (millisSinceEpoch.count() % 1000); 188 182 189 // get the current time 183 time_t rawtime; 184 struct tm* timeinfo; 185 time(&rawtime); 186 timeinfo = localtime(&rawtime); 190 time_t rawtime = std::chrono::system_clock::to_time_t(now); 191 struct tm* timeinfo = localtime(&rawtime); 192 193 // format time: hh:mm:ss:xxx 194 char buffer[13]; 195 snprintf(buffer, sizeof(buffer), "%.2i:%.2i:%.2i:%.3i", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, millis); 187 196 188 197 // print timestamp and output line to the log file 189 this->file_ << (timeinfo->tm_hour < 10 ? "0" : "") << timeinfo->tm_hour << ':' << 190 (timeinfo->tm_min < 10 ? "0" : "") << timeinfo->tm_min << ':' << 191 (timeinfo->tm_sec < 10 ? "0" : "") << timeinfo->tm_sec << ' ' << line << std::endl; 198 this->file_ << buffer << ' ' << line << std::endl; 192 199 } 193 200 } -
code/trunk/src/libraries/util/output/LogWriter.h
r9550 r11071 57 57 public: 58 58 LogWriter(); 59 LogWriter(const LogWriter&);60 59 virtual ~LogWriter(); 61 60 … … 70 69 71 70 protected: 72 virtual void printLine(const std::string& line, OutputLevel level) ;71 virtual void printLine(const std::string& line, OutputLevel level) override; 73 72 74 73 private: 74 // non-copyable: 75 LogWriter(const LogWriter&) = delete; 76 LogWriter& operator=(const LogWriter&) = delete; 77 75 78 void openFile(); 76 79 void closeFile(); -
code/trunk/src/libraries/util/output/MemoryWriter.cc
r9550 r11071 57 57 void MemoryWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 58 58 { 59 this->messages_. push_back(Message(level, context, lines));59 this->messages_.emplace_back(level, context, lines); 60 60 } 61 61 … … 65 65 void MemoryWriter::resendOutput(OutputListener* listener) const 66 66 { 67 for ( size_t i = 0; i < this->messages_.size(); ++i)67 for (const Message& message : this->messages_) 68 68 { 69 const Message& message = this->messages_[i];70 69 listener->unfilteredOutput(message.level, *message.context, message.lines); 71 70 } -
code/trunk/src/libraries/util/output/MemoryWriter.h
r9550 r11071 68 68 public: 69 69 MemoryWriter(); 70 MemoryWriter(const MemoryWriter&);71 70 virtual ~MemoryWriter(); 72 71 … … 75 74 76 75 protected: 77 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) ;76 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) override; 78 77 79 78 private: 79 // non-copyable: 80 MemoryWriter(const MemoryWriter&) = delete; 81 MemoryWriter& operator=(const MemoryWriter&) = delete; 82 80 83 std::vector<Message> messages_; ///< Stores all output messages from the creation of this instance until disable() is called. 81 84 }; -
code/trunk/src/libraries/util/output/OutputDefinitions.h
r10624 r11071 132 132 namespace context 133 133 { 134 static const OutputContextMask all = 0xFFFFFFFFFFFFFFFFull; ///< Context mask, all bits set to 1135 static const OutputContextMask none = 0x0000000000000000ull; ///< Context mask, all bits set to 0134 static constexpr OutputContextMask all = 0xFFFFFFFFFFFFFFFFull; ///< Context mask, all bits set to 1 135 static constexpr OutputContextMask none = 0x0000000000000000ull; ///< Context mask, all bits set to 0 136 136 137 static const OutputContextSubID no_subcontext = 0; ///< Used as ID for contexts which are not sub-contexts137 static constexpr OutputContextSubID no_subcontext = 0; ///< Used as ID for contexts which are not sub-contexts 138 138 139 139 namespace -
code/trunk/src/libraries/util/output/OutputListener.cc
r9550 r11071 111 111 this->levelMask_ = mask; 112 112 113 for ( size_t i = 0; i < this->listeners_.size(); ++i)114 this->listeners_[i]->updatedLevelMask(this);113 for (AdditionalContextListener* listener : this->listeners_) 114 listener->updatedLevelMask(this); 115 115 } 116 116 … … 142 142 this->additionalContextsLevelMask_ = mask; 143 143 144 for ( size_t i = 0; i < this->listeners_.size(); ++i)145 this->listeners_[i]->updatedAdditionalContextsLevelMask(this);144 for (AdditionalContextListener* listener : this->listeners_) 145 listener->updatedAdditionalContextsLevelMask(this); 146 146 } 147 147 … … 153 153 this->additionalContextsMask_ = mask; 154 154 155 for ( size_t i = 0; i < this->listeners_.size(); ++i)156 this->listeners_[i]->updatedAdditionalContextsMask(this);155 for (AdditionalContextListener* listener : this->listeners_) 156 listener->updatedAdditionalContextsMask(this); 157 157 } 158 158 -
code/trunk/src/libraries/util/output/OutputManager.cc
r9550 r11071 41 41 #include "util/Output.h" 42 42 #include "util/StringUtils.h" 43 #include "util/SharedPtr.h"44 43 45 44 namespace orxonox … … 57 56 58 57 this->isInitialized_ = false; 59 this->memoryWriterInstance_ = 0;60 this->consoleWriterInstance_ = 0;61 this->logWriterInstance_ = 0;58 this->memoryWriterInstance_ = nullptr; 59 this->consoleWriterInstance_ = nullptr; 60 this->logWriterInstance_ = nullptr; 62 61 63 62 // register 'undefined' context in order to give it always the first context-ID … … 81 80 } 82 81 83 /*static*/ SharedPtr<OutputManager>& OutputManager::Testing::getInstancePointer()84 { 85 static SharedPtr<OutputManager> instance(new OutputManager());82 /*static*/ std::shared_ptr<OutputManager>& OutputManager::Testing::getInstancePointer() 83 { 84 static std::shared_ptr<OutputManager> instance(new OutputManager()); 86 85 return instance; 87 86 } … … 132 131 vectorize(message, '\n', &lines); 133 132 134 for ( size_t i = 0; i < this->listeners_.size(); ++i)135 this->listeners_[i]->unfilteredOutput(level, context, lines);133 for (OutputListener* listener : this->listeners_) 134 listener->unfilteredOutput(level, context, lines); 136 135 } 137 136 … … 179 178 { 180 179 int mask = 0; 181 for ( size_t i = 0; i < this->listeners_.size(); ++i)182 mask |= this->listeners_[i]->getLevelMask();180 for (OutputListener* listener : this->listeners_) 181 mask |= listener->getLevelMask(); 183 182 this->combinedLevelMask_ = static_cast<OutputLevel>(mask); 184 183 } … … 190 189 { 191 190 int mask = 0; 192 for ( size_t i = 0; i < this->listeners_.size(); ++i)193 mask |= this->listeners_[i]->getAdditionalContextsLevelMask();191 for (OutputListener* listener : this->listeners_) 192 mask |= listener->getAdditionalContextsLevelMask(); 194 193 this->combinedAdditionalContextsLevelMask_ = static_cast<OutputLevel>(mask); 195 194 } … … 201 200 { 202 201 this->combinedAdditionalContextsMask_ = 0; 203 for ( size_t i = 0; i < this->listeners_.size(); ++i)204 this->combinedAdditionalContextsMask_ |= this->listeners_[i]->getAdditionalContextsMask();202 for (OutputListener* listener : this->listeners_) 203 this->combinedAdditionalContextsMask_ |= listener->getAdditionalContextsMask(); 205 204 } 206 205 -
code/trunk/src/libraries/util/output/OutputManager.h
r9550 r11071 41 41 #include <vector> 42 42 #include <map> 43 #include <memory> 43 44 44 45 #include "OutputDefinitions.h" … … 66 67 public: 67 68 OutputManager(); 68 OutputManager(const OutputManager&);69 69 virtual ~OutputManager(); 70 70 … … 81 81 virtual void unregisterListener(OutputListener* listener); 82 82 83 virtual void updatedLevelMask(const OutputListener* listener) 83 virtual void updatedLevelMask(const OutputListener* listener) override 84 84 { this->updateCombinedLevelMask(); } 85 virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener) 85 virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener) override 86 86 { this->updateCombinedAdditionalContextsLevelMask(); } 87 virtual void updatedAdditionalContextsMask(const OutputListener* listener) 87 virtual void updatedAdditionalContextsMask(const OutputListener* listener) override 88 88 { this->updateCombinedAdditionalContextsMask(); } 89 89 … … 114 114 115 115 private: 116 // non-copyable: 117 OutputManager(const OutputManager&) = delete; 118 OutputManager& operator=(const OutputManager&) = delete; 119 116 120 void updateMasks(); 117 121 void updateCombinedLevelMask(); … … 137 141 struct _UtilExport Testing 138 142 { 139 static SharedPtr<OutputManager>& getInstancePointer();143 static std::shared_ptr<OutputManager>& getInstancePointer(); 140 144 }; 141 145 }; -
code/trunk/src/libraries/util/output/OutputStream.cc
r8858 r11071 41 41 @brief Default constructor, initializes level and context with default values. 42 42 */ 43 OutputStream::OutputStream() 43 OutputStream::OutputStream() : OutputStream(level::debug_output, context::undefined()) 44 44 { 45 this->setOutputAttributes(level::debug_output, context::undefined());46 45 } 47 46 -
code/trunk/src/libraries/util/output/SubcontextOutputListener.cc
r8858 r11071 79 79 80 80 // compose the mask of subcontexts and build the set of sub-context-IDs 81 for ( std::set<const OutputContextContainer*>::const_iterator it = subcontexts.begin(); it != subcontexts.end(); ++it)81 for (const OutputContextContainer* subcontext : subcontexts) 82 82 { 83 this->subcontextsCheckMask_ |= (*it)->mask;84 this->subcontexts_.insert( (*it)->sub_id);83 this->subcontextsCheckMask_ |= subcontext->mask; 84 this->subcontexts_.insert(subcontext->sub_id); 85 85 } 86 86 -
code/trunk/src/libraries/util/output/SubcontextOutputListener.h
r9550 r11071 73 73 virtual ~SubcontextOutputListener(); 74 74 75 virtual void setAdditionalContextsMask(OutputContextMask mask) ;75 virtual void setAdditionalContextsMask(OutputContextMask mask) override; 76 76 void setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts); 77 77 78 virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const ;78 virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const override; 79 79 80 80 inline const std::set<OutputContextSubID>& getSubcontexts() const
Note: See TracChangeset
for help on using the changeset viewer.