Log class has the Stream class as a base class now

- implemented some missing operators<<(...)
- removed Manipulators: l1, l2, l3, l4, lend, lsave
- PascalCase to snake_case in Log

added to Stream:
  virtual bool is_char_stream() const = 0;
  virtual bool is_wchar_stream() const = 0;
  virtual char get_char(size_t index) const = 0;
  virtual wchar_t get_wchar(size_t index) const = 0;
  virtual Stream & operator<<(const Stream & stream) = 0;
This commit is contained in:
2021-06-24 20:52:48 +02:00
parent 2b6789754f
commit 4d9f5f6c55
9 changed files with 706 additions and 280 deletions

View File

@@ -45,22 +45,16 @@
namespace morm
{
class Model;
}
namespace pt
{
class Log
class Log : public Stream
{
public:
/*
log1 - the first level
log2
@@ -76,81 +70,91 @@ public:
log3,
log4,
l1,
l2,
l3,
l4,
logend,
lend,
logsave,
lsave,
};
Log();
virtual ~Log();
~Log();
virtual void SetLogBuffer(WTextStream * buffer);
virtual WTextStream * GetLogBuffer();
bool is_char_stream() const;
bool is_wchar_stream() const;
void SetFileLog(FileLog * file_log);
FileLog * GetFileLog();
void clear();
bool empty() const;
size_t size() const;
void reserve(size_t len);
size_t capacity() const;
void SetMaxBufferLength(size_t max_buffer_length);
size_t GetMaxBufferLength();
void to_str(std::string & str, bool clear_string = true) const;
void to_str(std::wstring & str, bool clear_string = true) const;
virtual Log & IntMinWidth(size_t min_width);
std::string to_str() const;
std::wstring to_wstr() const;
virtual Log & operator<<(const void * s);
char get_char(size_t index) const;
wchar_t get_wchar(size_t index) const;
virtual Log & operator<<(const char * s);
virtual Log & operator<<(const std::string * s);
virtual Log & operator<<(const std::string & s);
Log & operator<<(const char * s);
Log & operator<<(const std::string & s);
Log & operator<<(const wchar_t * s);
Log & operator<<(const std::wstring & s);
virtual Log & operator<<(const wchar_t * s);
virtual Log & operator<<(const std::wstring * s);
virtual Log & operator<<(const std::wstring & s);
Log & operator<<(char val);
Log & operator<<(unsigned char val);
Log & operator<<(wchar_t val);
Log & operator<<(bool val);
Log & operator<<(short val);
Log & operator<<(int s);
Log & operator<<(long s);
Log & operator<<(long long s);
Log & operator<<(unsigned short val);
Log & operator<<(unsigned int val);
Log & operator<<(unsigned long val);
Log & operator<<(unsigned long long val);
Log & operator<<(float val);
Log & operator<<(double s);
Log & operator<<(long double val);
Log & operator<<(const void * s);
virtual Log & operator<<(char s);
virtual Log & operator<<(wchar_t s);
virtual Log & operator<<(int s);
virtual Log & operator<<(long s);
virtual Log & operator<<(long long s);
// add unsigned long, unsigned int
virtual Log & operator<<(size_t s);
//virtual Log & operator<<(float s); // added
virtual Log & operator<<(double s);
virtual Log & operator<<(const Space & space);
virtual Log & operator<<(const Date & date);
Log & operator<<(const Stream & stream);
Log & operator<<(const Space & space);
Log & operator<<(const Date & date);
#ifdef PT_HAS_MORM_LIBRARY
virtual Log & operator<<(morm::Model & model);
#endif
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
Log & operator<<(const TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
Log & write(const char * buf, size_t len);
Log & write(const wchar_t * buf, size_t len);
/*
* methods specific to Log class
*
*/
virtual Log & operator<<(Manipulators m);
virtual void set_log_buffer(WTextStream * buffer);
virtual WTextStream * get_log_buffer();
void set_file_log(FileLog * file_log);
FileLog * get_file_log();
void set_max_buffer_length(size_t max_buffer_length);
size_t get_max_buffer_length();
virtual Log & LogString(const std::string & value, size_t max_size);
virtual Log & LogString(const std::wstring & value, size_t max_size);
virtual Log & int_min_width(size_t min_width);
virtual Log & put_string(const std::string & value, size_t max_size);
virtual Log & put_string(const std::wstring & value, size_t max_size);
template<typename char_type, size_t stack_size, size_t heap_block_size>
Log & operator<<(const TextStreamBase<char_type, stack_size, heap_block_size> & buf);
virtual Log & LogBinary(const char * blob, size_t blob_len);
virtual Log & LogBinary(const std::string & blob);
virtual Log & put_binary_blob(const char * blob, size_t blob_len);
virtual Log & put_binary_blob(const std::string & blob);
@@ -176,6 +180,7 @@ protected:
template<class StringType>
Log & log_string_generic(const StringType & value, size_t max_size);
virtual bool can_put_log();
virtual void save_log();
virtual void save_log_and_clear();
@@ -183,12 +188,24 @@ protected:
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
Log & Log::operator<<(const TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
{
if( can_put_log() )
{
(*buffer) << arg;
}
return *this;
}
template<class StringType>
Log & Log::log_string_generic(const StringType & value, size_t max_size)
{
std::size_t min_size = value.size() < max_size ? value.size() : max_size;
if( buffer && file_log && current_level <= file_log->get_log_level() )
if( can_put_log() )
{
for(size_t i=0 ; i < min_size ; ++i)
{
@@ -204,19 +221,6 @@ Log & Log::log_string_generic(const StringType & value, size_t max_size)
template<typename char_type, size_t stack_size, size_t heap_block_size>
Log & Log::operator<<(const TextStreamBase<char_type, stack_size, heap_block_size> & buf)
{
if( buffer && file_log && current_level <= file_log->get_log_level() )
{
(*buffer) << buf;
}
return *this;
}
} // namespace