Commit 465784ce3f635a34b02a342a31de514bd59e9d22
1 parent
3f44115e
add bool, char*, unsigned operator<<
Showing
2 changed files
with
81 additions
and
12 deletions
include/GLog.hpp
| ... | ... | @@ -61,11 +61,14 @@ public: |
| 61 | 61 | // Operators |
| 62 | 62 | GLog& operator= (const GLog& log); |
| 63 | 63 | void operator()(const char *msgFormat, ...); |
| 64 | - GLog& operator<<(const std::string& value); | |
| 64 | + GLog& operator<<(const std::string& str); | |
| 65 | + GLog& operator<<(const char* str); | |
| 66 | + GLog& operator<<(const char& value); | |
| 67 | + GLog& operator<<(const unsigned char& value); | |
| 65 | 68 | GLog& operator<<(const bool& value); |
| 66 | 69 | GLog& operator<<(const int& value); |
| 70 | + GLog& operator<<(const unsigned int& value); | |
| 67 | 71 | GLog& operator<<(const double& value); |
| 68 | - GLog& operator<<(const char& value); | |
| 69 | 72 | GLog& operator<<(std::ostream& (*fn)(std::ostream&)); |
| 70 | 73 | |
| 71 | 74 | // Methods | ... | ... |
src/app/GLog.cpp
| ... | ... | @@ -180,14 +180,80 @@ void GLog::operator()(const char *msgFormat, ...) |
| 180 | 180 | |
| 181 | 181 | |
| 182 | 182 | /***********************************************************************//** |
| 183 | - * @brief Insert string into output stream | |
| 183 | + * @brief Insert C++ string into output stream | |
| 184 | 184 | * |
| 185 | - * @param[in] value String to be inserted. | |
| 185 | + * @param[in] str C++ string to be inserted. | |
| 186 | 186 | ***************************************************************************/ |
| 187 | -GLog& GLog::operator<<(const std::string& value) | |
| 187 | +GLog& GLog::operator<<(const std::string& str) | |
| 188 | 188 | { |
| 189 | 189 | // Add string to buffer |
| 190 | - m_buffer.append(value); | |
| 190 | + m_buffer.append(str); | |
| 191 | + | |
| 192 | + // Flush buffer | |
| 193 | + flush(); | |
| 194 | + | |
| 195 | + // Return logger | |
| 196 | + return *this; | |
| 197 | +} | |
| 198 | + | |
| 199 | + | |
| 200 | +/***********************************************************************//** | |
| 201 | + * @brief Insert C string into output stream | |
| 202 | + * | |
| 203 | + * @param[in] str C string to be inserted. | |
| 204 | + ***************************************************************************/ | |
| 205 | +GLog& GLog::operator<<(const char* str) | |
| 206 | +{ | |
| 207 | + // Add string to buffer | |
| 208 | + m_buffer.append(str); | |
| 209 | + | |
| 210 | + // Flush buffer | |
| 211 | + flush(); | |
| 212 | + | |
| 213 | + // Return logger | |
| 214 | + return *this; | |
| 215 | +} | |
| 216 | + | |
| 217 | + | |
| 218 | +/***********************************************************************//** | |
| 219 | + * @brief Insert character value into output stream | |
| 220 | + * | |
| 221 | + * @param[in] value Character value to be inserted. | |
| 222 | + ***************************************************************************/ | |
| 223 | +GLog& GLog::operator<<(const char& value) | |
| 224 | +{ | |
| 225 | + // Allocate output stream | |
| 226 | + std::ostringstream oss; | |
| 227 | + | |
| 228 | + // Put value into stream | |
| 229 | + oss << value; | |
| 230 | + | |
| 231 | + // Append stream to buffer | |
| 232 | + m_buffer.append(oss.str()); | |
| 233 | + | |
| 234 | + // Flush buffer | |
| 235 | + flush(); | |
| 236 | + | |
| 237 | + // Return logger | |
| 238 | + return *this; | |
| 239 | +} | |
| 240 | + | |
| 241 | + | |
| 242 | +/***********************************************************************//** | |
| 243 | + * @brief Insert unsigned character value into output stream | |
| 244 | + * | |
| 245 | + * @param[in] value Unsigned character value to be inserted. | |
| 246 | + ***************************************************************************/ | |
| 247 | +GLog& GLog::operator<<(const unsigned char& value) | |
| 248 | +{ | |
| 249 | + // Allocate output stream | |
| 250 | + std::ostringstream oss; | |
| 251 | + | |
| 252 | + // Put value into stream | |
| 253 | + oss << value; | |
| 254 | + | |
| 255 | + // Append stream to buffer | |
| 256 | + m_buffer.append(oss.str()); | |
| 191 | 257 | |
| 192 | 258 | // Flush buffer |
| 193 | 259 | flush(); |
| ... | ... | @@ -243,11 +309,11 @@ GLog& GLog::operator<<(const int& value) |
| 243 | 309 | |
| 244 | 310 | |
| 245 | 311 | /***********************************************************************//** |
| 246 | - * @brief Insert double precision value into output stream | |
| 312 | + * @brief Insert unsigned integer into output stream | |
| 247 | 313 | * |
| 248 | - * @param[in] value Double precision value to be inserted. | |
| 314 | + * @param[in] value Unsigned integer to be inserted. | |
| 249 | 315 | ***************************************************************************/ |
| 250 | -GLog& GLog::operator<<(const double& value) | |
| 316 | +GLog& GLog::operator<<(const unsigned int& value) | |
| 251 | 317 | { |
| 252 | 318 | // Allocate output stream |
| 253 | 319 | std::ostringstream oss; |
| ... | ... | @@ -267,11 +333,11 @@ GLog& GLog::operator<<(const double& value) |
| 267 | 333 | |
| 268 | 334 | |
| 269 | 335 | /***********************************************************************//** |
| 270 | - * @brief Insert character value into output stream | |
| 336 | + * @brief Insert double precision value into output stream | |
| 271 | 337 | * |
| 272 | - * @param[in] value Character value to be inserted. | |
| 338 | + * @param[in] value Double precision value to be inserted. | |
| 273 | 339 | ***************************************************************************/ |
| 274 | -GLog& GLog::operator<<(const char& value) | |
| 340 | +GLog& GLog::operator<<(const double& value) | |
| 275 | 341 | { |
| 276 | 342 | // Allocate output stream |
| 277 | 343 | std::ostringstream oss; | ... | ... |