Skip to content

Commit

Permalink
Tests and Samples: Fixed SonarCloud issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonJoker committed Jan 14, 2024
1 parent 01cf668 commit 4a23b9d
Show file tree
Hide file tree
Showing 226 changed files with 3,187 additions and 3,611 deletions.
75 changes: 38 additions & 37 deletions samples/00-Common/Src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ namespace common
using int_type = typename std::basic_streambuf< CharType >::int_type;
using traits_type = typename std::basic_streambuf< CharType >::traits_type;

LogStreambuf( LogStreambuf const & ) = delete;
LogStreambuf & operator=( LogStreambuf const & ) = delete;
LogStreambuf( LogStreambuf && )noexcept = delete;
LogStreambuf & operator=( LogStreambuf && )noexcept = delete;

LogStreambuf( string_type const & appName, ostream_type & stream )
: m_stream( stream )
, m_appName{ appName }
{
m_old = m_stream.rdbuf( this );
}

~LogStreambuf()noexcept
~LogStreambuf()noexcept override
{
try
{
Expand Down Expand Up @@ -120,14 +125,12 @@ namespace common
localtime_s( &today, &ttime );
#else
today = *localtime( &ttime );
#endif
char buffer[33] = { 0 };
strftime( buffer, 32, "%Y-%m-%d %H:%M:%S", &today );
std::string timeStamp = buffer;

std::ofstream file{ logFileName, std::ios::app };
#endif
std::array< char, 33u > buffer{};
strftime( buffer.data(), 32, "%Y-%m-%d %H:%M:%S", &today );
std::string timeStamp{ buffer.data() };

if ( file )
if ( std::ofstream file{ logFileName, std::ios::app } )
{
file << timeStamp << " - " << log;
}
Expand All @@ -149,23 +152,24 @@ namespace common
using CharType = char;
using string_type = std::basic_string< CharType >;

static inline std::array< std::string, 4u > const logTypeName
{
"Debug",
"Info",
"Warning",
"Error",
};
static inline std::array< FILE *, 4u > const stdStream
{
stdout,
stdout,
stdout,
stderr,
};

static void Log( string_type const & appName
, string_type const & text )
{
static std::string const logTypeName[]
{
"Debug",
"Info",
"Warning",
"Error",
};
static FILE * const stdStream[]
{
stdout,
stdout,
stdout,
stderr,
};
logDebugString( appName + " - " + logTypeName[size_t( Type )] + ": " + text + "\n"
, stdStream[size_t( Type )] );
}
Expand All @@ -184,11 +188,11 @@ namespace common

bool App::OnInit()
{
m_cout = new LogStreambuf< InfoLogStreambufTraits >( m_name.ToStdString()
m_cout = std::make_unique< LogStreambuf< InfoLogStreambufTraits > >( m_name.ToStdString()
, std::cout );
m_cerr = new LogStreambuf< ErrorLogStreambufTraits >( m_name.ToStdString()
m_cerr = std::make_unique < LogStreambuf< ErrorLogStreambufTraits > >( m_name.ToStdString()
, std::cerr );
m_clog = new LogStreambuf< DebugLogStreambufTraits >( m_name.ToStdString()
m_clog = std::make_unique < LogStreambuf< DebugLogStreambufTraits > >( m_name.ToStdString()
, std::clog );

#if 1//!defined( NDEBUG )
Expand Down Expand Up @@ -230,7 +234,7 @@ namespace common
result = true;
}
}
catch ( std::exception & exc )
catch ( Exception & exc )
{
std::cerr << exc.what() << std::endl;
}
Expand All @@ -254,9 +258,9 @@ namespace common
# endif
#endif

delete m_cout;
delete m_cerr;
delete m_clog;
m_cout.reset();
m_cerr.reset();
m_clog.reset();
return wxApp::OnExit();
}

Expand All @@ -282,9 +286,8 @@ namespace common

if ( result )
{
wxString fileName;

if ( parser.Found( wxT( "l" ), &fileName ) )
if ( wxString fileName;
parser.Found( wxT( "l" ), &fileName ) )
{
logFileName = fileName;
}
Expand All @@ -294,12 +297,10 @@ namespace common

for ( auto & renderer : m_renderers )
{
if ( m_rendererName.empty() )
if ( m_rendererName.empty()
&& parser.Found( renderer.name ) )
{
if ( parser.Found( renderer.name ) )
{
m_rendererName = renderer.name;
}
m_rendererName = renderer.name;
}
}
}
Expand Down
45 changes: 33 additions & 12 deletions samples/00-Common/Src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,51 @@ namespace common
: public wxApp
{
protected:
App( wxString const & name );
explicit App( wxString const & name );

public:
virtual ~App() = default;
bool OnInit()override;
int OnExit()override;

inline wxString const & getInstanceName()const
wxString const & getInstanceName()const noexcept
{
return m_rendererName;
}

protected:
wxString const & getName()const noexcept
{
return m_name;
}

bool isAllocated()const noexcept
{
return m_allocated;
}

MainFrame & getMainFrame()const noexcept
{
assert( m_mainFrame );
return *m_mainFrame;
}

ashes::RendererList const & getRenderers()const noexcept
{
return m_renderers;
}

private:
bool doParseCommandLine();
virtual MainFrame * doCreateMainFrame( wxString const & rendererName ) = 0;

protected:
wxString m_name;
wxString m_rendererName;
bool m_allocated{ false };
MainFrame * m_mainFrame{ nullptr };
std::streambuf * m_cout{ nullptr };
std::streambuf * m_cerr{ nullptr };
std::streambuf * m_clog{ nullptr };
ashes::RendererList m_renderers;
private:
wxString m_name{};
wxString m_rendererName{};
bool m_allocated{};
MainFrame * m_mainFrame{};
std::unique_ptr< std::streambuf > m_cout{};
std::unique_ptr< std::streambuf > m_cerr{};
std::unique_ptr< std::streambuf > m_clog{};
ashes::RendererList m_renderers{};
};
}
Loading

0 comments on commit 4a23b9d

Please sign in to comment.