Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CoMISo
Base
Commits
11d5b5f8
Commit
11d5b5f8
authored
Apr 30, 2020
by
Martin Marinov
Browse files
Merge remote-tracking branch 'Base/master' into merge-from-ReForm
parents
3623fbdf
dd1c8d9d
Changes
52
Hide whitespace changes
Inline
Side-by-side
.clang-format
0 → 100644
View file @
11d5b5f8
---
BasedOnStyle: LLVM
BreakBeforeBraces: Allman
SortIncludes: 'false'
PointerAlignment: 'Left'
AlignAfterOpenBracket: 'DontAlign'
AlignEscapedNewlines: 'DontAlign'
SpacesInContainerLiterals: 'false'
...
Code/CodeLink.hh
View file @
11d5b5f8
// (C) Copyright 201
6
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifndef BASE_CODELINK_HH_INCLUDED
#define BASE_CODELINK_HH_INCLUDED
...
...
Code/Quality.hh
View file @
11d5b5f8
// (C) Copyright 201
5
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifndef QUALITY_HH_INCLUDED
#define QUALITY_HH_INCLUDED
// This file contains various definitions related to enforcing certain code
// quality rules, e.g., applying W4
// only test this in MSVC
#if defined(_MSC_VER)
// Some warnings are disabled permanently since the cannot be controlled on
// section basis.
// Some warnings are disabled permanently since the cannot be controlled on
// section basis.
//function 'function' marked as __forceinline not inlined
#pragma warning (disable: 4714)
//function 'function' marked as __forceinline not inlined
#pragma warning (disable: 4714)
#define LOW_CODE_QUALITY_SECTION_BEGIN __pragma(warning(push, 1))
#define LOW_CODE_QUALITY_SECTION_END __pragma(warning(pop))
#define LOW_CODE_QUALITY_SECTION_BEGIN1 __pragma(warning(push, 1))
#define LOW_CODE_QUALITY_SECTION_BEGIN3 __pragma(warning(push, 3))
#define LOW_CODE_QUALITY_SECTION_END __pragma(warning(pop))
#define LOW_CODE_QUALITY_VARIABLE_ALLOW(FOO) static_cast<void>(FOO);
#else
#else
// not on MSVC
#if __cplusplus >= 201103L
#if __cplusplus >= 201103L
#ifdef __clang__
#ifdef __clang__
#define LOW_CODE_QUALITY_SECTION_BEGIN \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-register\"") \
_Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") \
_Pragma("clang diagnostic ignored \"-Wshift-negative-value\"")
//TODO: ignore more warnings as needed
#define LOW_CODE_QUALITY_SECTION_BEGIN
1
\
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-register\"") \
_Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") \
_Pragma("clang diagnostic ignored \"-Wshift-negative-value\"")
//TODO: ignore more warnings as needed
#define LOW_CODE_QUALITY_SECTION_END \
_Pragma("clang diagnostic pop")
#define LOW_CODE_QUALITY_SECTION_END \
_Pragma("clang diagnostic pop")
#elif defined(__GNUG__)
#elif defined(__GNUG__)
#define LOW_CODE_QUALITY_SECTION_BEGIN \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wall\"") //TODO: ignore more warnings as needed
#define LOW_CODE_QUALITY_SECTION_BEGIN
1
\
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wall\"") //TODO: ignore more warnings as needed
#define LOW_CODE_QUALITY_SECTION_END \
_Pragma("GCC diagnostic pop")
#define LOW_CODE_QUALITY_SECTION_END \
_Pragma("GCC diagnostic pop")
#else
#else
#define LOW_CODE_QUALITY_SECTION_BEGIN
#define LOW_CODE_QUALITY_SECTION_END
#define LOW_CODE_QUALITY_SECTION_END
#endif
#endif
#else
#else
// __cplusplus < 201103L
#define LOW_CODE_QUALITY_SECTION_BEGIN
#define LOW_CODE_QUALITY_SECTION_END
#define LOW_CODE_QUALITY_SECTION_BEGIN
1
#define LOW_CODE_QUALITY_SECTION_END
#endif
#endif // __cplusplus >= 201103L
#define LOW_CODE_QUALITY_SECTION_BEGIN3
#define LOW_CODE_QUALITY_VARIABLE_ALLOW(FOO) static_cast<void>(sizeof(FOO));
#endif // ifdef _MSC_VER
// backwards-compatible name for LOW_CODE_QUALITY_SECTION_BEGIN1
#define LOW_CODE_QUALITY_SECTION_BEGIN LOW_CODE_QUALITY_SECTION_BEGIN1
#endif // QUALITY_HH_INCLUDED
Config/BaseDefines.hh
View file @
11d5b5f8
// (C) Copyright 2019 by Autodesk, Inc.
#ifndef BASEDLLEXPORT
#if defined(WIN32) || defined(_WIN32)
...
...
@@ -44,4 +45,7 @@
#define STD_ARRAY_AVAILABLE
#endif
#ifndef _MSC_VER
#define sprintf_s snprintf
#endif
Debug/DebCallStack.cc
View file @
11d5b5f8
// (C) Copyright 201
6
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifdef DEB_ON
...
...
@@ -6,10 +6,6 @@
#include
"DebOut.hh"
#include
<cstring>
#ifndef WIN32
#include
<cstdio>
#endif
namespace
Debug
{
namespace
{
...
...
@@ -36,13 +32,13 @@ void append_function(std::string& _str, const char* const _func)
void
append_entry
(
std
::
string
&
_str
,
const
Enter
*
const
_entr
,
const
bool
_cmpct
,
const
bool
_entr_nmbr
,
const
Enter
*
const
_prev_entr
)
{
if
(
_prev_entr
!=
NULL
&&
// there is a previous entry and it is the same?
if
(
_prev_entr
!=
nullptr
&&
// there is a previous entry and it is the same?
strcmp
(
_prev_entr
->
function
(),
_entr
->
function
())
==
0
)
{
// ... so do nothing
return
;
}
if
(
_prev_entr
!=
NULL
)
if
(
_prev_entr
!=
nullptr
)
_str
.
append
(
"/"
);
if
(
_cmpct
)
...
...
@@ -52,10 +48,8 @@ void append_entry(std::string& _str, const Enter* const _entr,
if
(
_entr_nmbr
)
{
_str
.
append
(
"."
);
std
::
stringstream
ss
;
ss
<<
_entr
->
number
();
_str
.
append
(
ss
.
str
());
_str
+=
'.'
;
_str
+=
std
::
to_string
(
_entr
->
number
());
}
}
...
...
@@ -73,50 +67,21 @@ const CallStack& CallStack::query()
return
modify
();
}
// Read a particular call stack element
//bool read(int _up, const char*& _funcname, int& _count)
//{
// const Enter* fcs = call(_up);
// if (fcs != NULL)
// {
// _funcname = fcs->function();
// _count = fcs->number(); // Return most recent deb_enter_count
// return true;
// }
// return false;
//}
//
void
CallStack
::
append
(
std
::
string
&
_str
,
const
bool
_entr_nmbr
)
const
{
const
Enter
*
prev
=
NULL
;
const
Enter
*
prev
=
nullptr
;
for
(
size_t
i
=
0
,
n
=
depth
();
i
<
n
;
prev
=
calls_
[
i
++
])
append_entry
(
_str
,
calls_
[
i
],
true
,
_entr_nmbr
,
prev
);
}
void
CallStack
::
append_indent
(
std
::
string
&
_str
,
const
int
_indt
,
const
bool
_html
)
const
void
CallStack
::
append_indent
(
std
::
string
&
_str
,
const
int
_indt
)
const
{
if
(
_indt
==
0
)
return
;
if
(
_html
)
{
char
buffer
[
64
];
#ifndef WIN32
sprintf
(
buffer
,
"<FONT SIZE=%i>"
,
_indt
);
#else
sprintf_s
(
buffer
,
sizeof
(
buffer
),
"<FONT SIZE=%i>"
,
_indt
);
#endif
_str
.
append
(
buffer
);
}
int
num
=
(
int
)
calls_
.
size
();
int
i0
=
0
;
if
(
!
_html
)
++
i0
;
// Don't waste whitespace on first level indent if .txt
int
i0
=
1
;
for
(
int
i
=
i0
;
i
<
num
;
++
i
)
_str
.
append
(
" "
);
if
(
_html
)
_str
.
append
(
": </FONT>
\n
"
);
}
}
//namespace Debug
...
...
Debug/DebCallStack.hh
View file @
11d5b5f8
// (C) Copyright 201
6
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifndef BASE_DEBCALLSTACK_HH_INCLUDED
#define BASE_DEBCALLSTACK_HH_INCLUDED
...
...
@@ -32,19 +32,14 @@ public:
if
(
_up
<
(
int
)
n
)
return
calls_
[
n
-
1
-
_up
];
else
return
NULL
;
return
nullptr
;
}
/*!
Append the full call stack.
*/
//! Append the full call stack.
void
append
(
std
::
string
&
_str
,
const
bool
_entr_nmbr
=
true
)
const
;
/*!
Append and indent to the string
*/
void
append_indent
(
std
::
string
&
_str
,
const
int
_indt
,
const
bool
_html
)
const
;
//! Append and indent to the string
void
append_indent
(
std
::
string
&
_str
,
const
int
_indt
)
const
;
private:
std
::
vector
<
const
Enter
*>
calls_
;
...
...
Debug/DebConfig.cc
View file @
11d5b5f8
// (C) Copyright 201
6
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifdef DEB_ON
#include
"DebConfig.hh"
#include
"DebDefault.hh"
#include
"DebFile.hh"
#include
"Base/Utils/Environment.hh"
#include
<fstream>
#include
<sstream>
#include
<iostream>
#include
<list>
#include
<string>
#include
<map>
...
...
@@ -49,54 +49,42 @@ public:
}
private:
static
bool
search
(
const
std
::
string
&
_flnm
,
const
std
::
list
<
std
::
string
>&
_sel_strings
)
typedef
std
::
list
<
std
::
string
>
StringList
;
// list of strings to be found inside the file name.
StringList
file_selct_strngs_
;
// list of strings to be found inside the function name.
StringList
func_selct_strngs_
;
private:
static
bool
search
(
const
std
::
string
&
_str
,
const
StringList
&
_slcts
)
{
for
(
std
::
list
<
std
::
string
>::
const_itera
to
r
s
el_i
t
=
_s
el_strings
.
begin
();
sel_it
!=
_sel_strings
.
end
();
++
sel_it
)
for
(
const
au
to
&
s
lc
t
:
_s
lcts
)
{
const
std
::
string
&
sel
=
*
sel_it
;
if
(
_flnm
.
find
(
sel
)
!=
std
::
string
::
npos
)
if
(
_str
.
find
(
slct
)
!=
std
::
string
::
npos
)
return
true
;
}
return
false
;
}
private:
// list of strings to be found inside the file name.
std
::
list
<
std
::
string
>
file_selct_strngs_
;
// list of strings to be found inside the function name.
std
::
list
<
std
::
string
>
func_selct_strngs_
;
};
}
//namespace
class
Config
::
Impl
{
public:
Impl
()
:
dflt_lvl_
(
Default
::
LEVEL
)
{
read
();
}
void
print_char_to_cerr
(
const
char
_c
)
{
std
::
cerr
<<
_c
;
}
void
read
();
int
level
(
const
char
*
const
_flnm
,
const
char
*
const
_fnct
)
const
;
class
Config
::
LevelFilterMap
:
public
std
::
map
<
int
,
FilterLevelSelector
>
{};
private:
int
dflt_lvl_
;
typedef
std
::
map
<
int
,
FilterLevelSelector
>
LevelFilterMap
;
LevelFilterMap
lvl_fltrs_
;
// filters for each level
};
void
Config
::
Impl
::
read
()
bool
Config
::
load
(
const
char
*
const
_cnfg_envr
,
const
char
*
const
_cnfg_flnm
)
{
// const std::string flnm =
// System::Environment::variable("REFORM_DEB_CONFIG", "reform_deb.cfg");
const
auto
flnm
=
System
::
Environment
::
variable
(
_cnfg_envr
,
_cnfg_flnm
);
std
::
string
flnm
;
if
(
!
System
::
Environment
::
variable
(
"REFORM_DEB_CONFIG"
,
flnm
))
// For ReForm compatibility. Can this be removed?
{
flnm
=
System
::
Environment
::
variable
(
"COMISO_DEB_CONFIG"
,
"comiso_deb.cfg"
);
}
std
::
ifstream
cnfg_strm
(
flnm
.
c_str
());
if
(
!
cnfg_strm
.
is_open
())
return
false
;
delete
lvl_fltrs_
;
lvl_fltrs_
=
new
LevelFilterMap
;
std
::
ifstream
cnfg_strm
(
flnm
.
c_str
());
std
::
string
line
;
while
(
std
::
getline
(
cnfg_strm
,
line
))
{
...
...
@@ -104,7 +92,7 @@ void Config::Impl::read()
std
::
string
type
;
line_stream
>>
type
;
void
(
FilterLevelSelector
::*
add_string
)(
const
std
::
string
&
)
=
NULL
;
void
(
FilterLevelSelector
::*
add_string
)(
const
std
::
string
&
)
=
nullptr
;
if
(
type
==
"all"
)
{}
...
...
@@ -117,9 +105,9 @@ void Config::Impl::read()
int
lvl
;
line_stream
>>
lvl
;
if
(
add_string
==
NULL
)
if
(
add_string
==
nullptr
)
{
dflt_lvl_
=
lvl
;
// We have read the default level.
output_level
=
lvl
;
// We have read the default level.
continue
;
}
char
colon
;
...
...
@@ -127,21 +115,19 @@ void Config::Impl::read()
if
(
colon
!=
':'
)
continue
;
std
::
string
select_str
;
while
(
line_stream
>>
select_str
)
(
lvl_fltrs_
[
lvl
].
*
add_string
)(
select_str
);
while
(
line_stream
>>
select_str
)
(
(
*
lvl_fltrs_
)
[
lvl
].
*
add_string
)(
select_str
);
}
return
true
;
}
int
Config
::
Impl
::
level
(
const
char
*
const
_flnm
,
const
char
*
const
_fnct
)
const
int
Config
::
custom_
level
(
const
char
*
const
_flnm
,
const
char
*
const
_fnct
)
const
{
int
lvl
=
dflt_lvl_
;
for
(
LevelFilterMap
::
const_iterator
fltr_it
=
lvl_fltrs_
.
begin
();
fltr_it
!=
lvl_fltrs_
.
end
();
++
fltr_it
)
if
(
lvl_fltrs_
==
nullptr
)
return
output_level
;
int
lvl
=
output_level
;
for
(
const
auto
&
fltr
:
*
lvl_fltrs_
)
{
// continue this iteration until the maximum allowed level if found
const
LevelFilterMap
::
value_type
&
fltr
=
*
fltr_it
;
// The following two lines where commented out to allow lowering the threshold.
// if (lvl >= fltr.first) // can this filter increase the current level?
// continue;
if
(
fltr
.
second
.
select_file
(
_flnm
)
||
fltr
.
second
.
select_function
(
_fnct
))
lvl
=
fltr
.
first
;
}
...
...
@@ -160,20 +146,15 @@ const Config& Config::query()
return
modify
();
}
Config
::
Config
()
:
impl_
(
new
Impl
)
{}
Config
::~
Config
()
{
delete
impl_
;
}
int
Config
::
level
(
const
char
*
const
_flnm
,
const
char
*
const
_fnct
)
const
const
Config
&
Config
::
defaults
()
{
return
impl_
->
level
(
_flnm
,
_fnct
);
static
Config
dflt_cnfg
;
return
dflt_cnfg
;
}
void
Config
::
set_console
(
const
bool
_on
)
{
File
::
modify
().
set_console
(
_on
);
}
bool
Config
::
console
()
const
{
return
File
::
query
().
console
();
}
Config
::
Config
()
{}
void
Config
::
set_logfile
(
bool
_on
)
{
File
::
modify
().
set_logfile
(
_on
);
}
bool
Config
::
logfile
()
const
{
return
File
::
query
().
logfile
();
}
Config
::~
Config
()
{
delete
lvl_fltrs_
;
}
}
//namespace Debug
...
...
Debug/DebConfig.hh
View file @
11d5b5f8
// (C) Copyright 201
6
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifndef BASE_DEBCONFIG_HH_INCLUDED
#define BASE_DEBCONFIG_HH_INCLUDED
...
...
@@ -6,10 +6,11 @@
#include
<Base/Config/BaseDefines.hh>
#include
<string>
#include
<vector>
namespace
Debug
{
void
print_char_to_cerr
(
const
char
_c
);
//!< print a char to cerr
/*!
Access the global, per-process, configuration options of the Debug system.
\todo Make this a per-thread configuration.
...
...
@@ -17,28 +18,46 @@ Access the global, per-process, configuration options of the Debug system.
class
BASEDLLEXPORT
Config
{
public:
static
const
Config
&
query
();
//! Define the function type to print a character on the console
typedef
void
(
*
print_function
)(
const
char
);
public:
//! Modify the current configuration.
static
Config
&
modify
();
//! Query the current configuration.
static
const
Config
&
query
();
//! Query the default configuration.
static
const
Config
&
defaults
();
public:
//! Turn on/off the console. This could be extended to redirect it.
void
set_console
(
const
bool
_on
=
true
);
//! The output level for all code in the absence of a config file.
int
output_level
=
5
;
//! The deb out log filename, nullptr disables the debug output log file.
const
char
*
log_filename
=
nullptr
;
//!
Get if the console is turned on/off.
bool
console
()
const
;
//!
Function to deb out on the console, nullptr if output disabled.
print_function
console_print
=
print_char_to_cerr
;
//! Turn on/off the logfile. This could be extended to provide a FILE*.
void
set_logfile
(
const
bool
_on
);
public:
//! The output level for the given filename and function.
int
custom_level
(
const
char
*
const
_flnm
,
const
char
*
const
_fnct
)
const
;
//! Get if the logfile is turned on/off.
bool
logfile
()
const
;
/*!
Load the configuration file specified either by the environment variable
or the filename if the the environment variable is not set.
\todo Document the config format.
\return true if the configuration file was loaded properly, false otherwise.
*/
bool
load
(
const
char
*
const
_cnfg_envr
,
const
char
*
const
_cnfg_flnm
);
//! Get the level for this filename and function
int
level
(
const
char
*
const
_flnm
,
const
char
*
const
_fnct
)
const
;
private:
class
LevelFilterMap
;
private:
class
Impl
;
Impl
*
impl_
;
LevelFilterMap
*
lvl_fltrs_
=
nullptr
;
private:
//! Private constructor
...
...
Debug/DebDefault.hh
deleted
100644 → 0
View file @
3623fbdf
// (C) Copyright 2016 by Autodesk, Inc.
#ifndef BASE_DEBDEFAULT_HH_INCLUDED
#define BASE_DEBDEFAULT_HH_INCLUDED
namespace
Debug
{
namespace
Default
{
const
char
*
const
LOG_FILENAME
=
"deb_out.txt"
;
const
int
LEVEL
=
5
;
}
//Default
}
//Debug
#endif//BASE_DEBDEFAULT_HH_INCLUDED
Debug/DebError.hh
View file @
11d5b5f8
// (C) Copyright 201
5
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifndef BASE_DEBERROR_HH_INCLUDED
#define BASE_DEBERROR_HH_INCLUDED
...
...
Debug/DebFile.cc
View file @
11d5b5f8
// (C) Copyright 201
6
by Autodesk, Inc.
// (C) Copyright 201
9
by Autodesk, Inc.
#ifdef DEB_ON
#include
"DebFile.hh"
#include
"DebCallStack.hh"
#include
"DebDefault.hh"
#include
"Base/Utils/Environment.hh"
#include
"Base/Utils/OStringStream.hh"
#include
<string>
#include
<fstream>
#include
<time.h>
#include
<vector>
#include
<iostream>
#include
<map>
#include
<memory>
#include
<list>
#include
<map>
#include
<sstream>
#include
<cstring>
#if !defined(WIN32) && !defined(_WIN32)
#define sprintf_s snprintf
#endif
namespace
Debug
{
namespace
Debug
{
namespace
{
// TODO: make this use std::string; check for html extension; case insensitive
bool
is_html_filename
(
const
char
*
const
str
)
File
::~
File
()
{
if
(
str
==
NULL
)
return
false
;
const
char
*
dot
=
strrchr
(
str
,
'.'
);
if
(
dot
==
NULL
)
return
false
;
++
dot
;
return
(
!
strncmp
(
dot
,
"htm"
,
3
))
||
(
!
strncmp
(
dot
,
"HTM"
,
3
))
;
print_footer
();
flush
();
delete
bffr_
;
// if flush failed to delete it for some reason
}
}
//namespace
class
File
::
Impl
void
File
::
print
(
const
char
_c
,
const
bool
_cnsl
)
{
public:
Impl
(
const
char
*
const
_flnm
,
const
uint
_flags
)
:
flags_
(
_flags
),
num_flush_
(
0
),
line_strt_
(
false
)
{
set_filename
(
_flnm
);
}
~
Impl
()
{
close
();
clear
();
}
bool
is_kept_open
()
const
{
return
0
!=
(
flags_
&
KEEP_OPEN
);
}
bool
is_html
()
const
{
return
0
!=
(
flags_
&
HTML
);
}
bool
is_retained
()
const
{
return
0
!=
(
flags_
&
RETAIN
);
}
bool
is_appended
()
const
{
return
0
!=
(
flags_
&
APPEND
);
}
// Only applies to HTML DEB_out
bool
is_white_on_black
()
const
{
return
true
;
}
bool
file_is_open
()
const
{
return
file_stream_
.
is_open
();
}
int
priority
()
const
{
return
priority_
;
}
const
char
*
filename
()
const
{
return
flnm_
.
empty
()
?
NULL
:
flnm_
.
c_str
();
}
void
clear
()