Skip to content
GitLab
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
836d6d8e
Commit
836d6d8e
authored
Mar 07, 2020
by
Martin Marinov
Committed by
GitHub Enterprise
Mar 07, 2020
Browse files
TSP-3454 Add options to simplify journal testing (#12)
parent
dc4f7e38
Changes
4
Hide whitespace changes
Inline
Side-by-side
Journal/JournalFileSystem.cc
View file @
836d6d8e
...
...
@@ -156,10 +156,12 @@ bool make_directory(String& _path)
return
true
;
}
static
int
file_idx
=
0
;
void
reset_filenames
()
{
file_idx
=
0
;
}
String
compose_next_filename
(
const
String
&
_jrnl_path
,
const
char
*
const
_name
)
{
static
int
file_idx
=
0
;
// Create filename
const
size_t
PADDING_SIZE
=
4
;
auto
flnm
=
to_string
(
file_idx
++
);
...
...
Journal/JournalFileSystem.hh
View file @
836d6d8e
...
...
@@ -45,6 +45,9 @@ return false if failed and leave _path unchanged.
*/
bool
make_directory
(
String
&
_path
);
//! Reset the "unique" index used to compose file names
void
reset_filenames
();
//! Compose the next available filename in the supplied journal path
String
compose_next_filename
(
const
String
&
_jrnl_path
,
const
char
*
const
_name
);
...
...
Journal/JournalStream.cc
View file @
836d6d8e
...
...
@@ -38,8 +38,11 @@ namespace Journal
}
Stream
::
Stream
(
const
Language
_lngg
,
const
char
*
const
_cmpn_name
,
const
char
*
const
_base_path
)
const
char
*
const
_base_path
,
const
Options
&
_optns
)
{
if
(
_optns
.
flag_on
<
Options
::
FL_RESET_FILENAMES
>
())
reset_filenames
();
switch
(
_lngg
)
{
case
Language
::
CPP
:
...
...
@@ -51,7 +54,9 @@ Stream::Stream(const Language _lngg, const char* const _cmpn_name,
default:
throw
INIT_FAILED
;
}
impl_
->
time
();
if
(
_optns
.
flag_on
<
Options
::
FL_TIMESTAMP
>
())
impl_
->
time
();
}
Stream
::~
Stream
()
{
JOURNAL_WRAP
(
delete
impl_
);
}
...
...
@@ -200,8 +205,8 @@ void StreamPtr::reset(Stream* _ptr)
static
StreamPtr
strm_ptr
;
// static stream pointer to call the destructor
bool
set_on
(
const
Language
_lngg
,
const
bool
_on
,
const
char
*
const
_
cmpn_name
,
const
char
*
c
ons
t
_
base_path
)
bool
set_on
(
const
Language
_lngg
,
const
bool
_on
,
const
char
*
const
_cmpn_name
,
const
char
*
const
_
base_path
,
const
Opti
ons
&
_
optns
)
{
if
(
on
()
==
_on
)
return
true
;
...
...
@@ -214,7 +219,7 @@ bool set_on(const Language _lngg, const bool _on,
try
{
strm_ptr
.
reset
(
new
Stream
(
_lngg
,
_cmpn_name
,
_base_path
));
strm_ptr
.
reset
(
new
Stream
(
_lngg
,
_cmpn_name
,
_base_path
,
_optns
));
}
catch
(...)
{
// things went wrong, so just return false, strm_ptr should be nullptr
...
...
Journal/JournalStream.hh
View file @
836d6d8e
...
...
@@ -21,6 +21,7 @@
namespace
Journal
{
typedef
std
::
string
String
;
typedef
unsigned
int
uint
;
using
Base
::
ENDL
;
using
Base
::
IOutputStream
;
...
...
@@ -135,13 +136,52 @@ of this function for the selected output language.
*/
template
<
typename
T
>
Data
define_in_language
(
Stream
&
_strm
,
const
T
&
_arg
);
/*!
Options to control the journal output.
These options are useful for developing journal baselines in regression tests as
they can be used to force repeatable journal file output.
*/
struct
Options
{
public:
enum
Flags
//!< enumerate on/off flags to control the Journal
{
FL_NONE
,
//!< no flags are set
FL_TIMESTAMP
=
0x1
,
//!< set output of the timestamp
FL_RESET_FILENAMES
=
0x2
,
//!< reset the filenames
FL_DEFAULT
=
FL_TIMESTAMP
//!< default flag
};
uint
flags
=
FL_DEFAULT
;
Options
()
=
default
;
explicit
Options
(
const
uint
_flags
)
:
flags
(
_flags
)
{}
//! Turn a flag on/of
template
<
enum
Flags
_flag
>
void
set_flag_on
(
const
bool
_on
)
{
if
(
_on
)
flags
|=
_flag
;
else
flags
&=
~
_flag
;
}
//! check if a flag is set on
template
<
enum
Flags
_flag
>
bool
flag_on
()
const
{
return
(
flags
&
_flag
)
==
_flag
;
}
};
//! the journal stream class, used when streaming from define() specializations
class
Stream
{
public:
// do not call constructor/destructor directly, use \ref set_on() instead
Stream
(
const
Language
_lngg
,
const
char
*
const
_cmpn_name
,
const
char
*
const
_base_path
);
const
char
*
const
_base_path
,
const
Options
&
_optns
);
~
Stream
();
// disable copy & assignment
...
...
@@ -365,9 +405,10 @@ provided, the base path will be composed from the component name as follows:
cannot be made, the journaling is disabled and this function returns false.
*/
bool
set_on
(
const
Language
_lngg
,
//!< output journal language
const
bool
_on
,
//!< turn on or off
const
bool
_on
,
//!< turn on or off
const
char
*
const
_cmpn_name
,
//!< component name in desired capitalization
const
char
*
const
_base_path
//!< base path
const
char
*
const
_base_path
,
//!< base path
const
Options
&
_optns
=
{}
//!< stream options
);
/*!
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment