Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
e2447af3
Commit
e2447af3
authored
Jul 11, 2021
by
LEFEBVREJP email
Browse files
Merge branch 'do-while' into 'master'
Macro do-while See merge request
!111
parents
4c7a6747
8c9b62e3
Pipeline
#154048
passed with stages
in 17 minutes and 45 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
radixbug/bug.hh
View file @
e2447af3
#ifndef RADIX_RADIXBUG_BUG_HH_
#define RADIX_RADIXBUG_BUG_HH_
#ifndef DEBUG_OUTPUT
#define DEBUG_OUTPUT 0
#define DEBUG_CALL(c)
#else
#define DEBUG_CALL(c) c
#endif
#ifndef RADIX_RADIXCORE_BUG_HH_
#define RADIX_RADIXCORE_BUG_HH_
// default to c++ compiler
/*
...
...
@@ -34,7 +27,7 @@
*/
#include <cstdio>
#include <iostream>
#if DEBUG_OUTPUT
& 1
#if
RADIX_
DEBUG_OUTPUT
#ifndef radix_stream
#define radix_stream std::cerr
#endif
...
...
@@ -79,7 +72,7 @@
#define radix_flush_tagged_warning(arg)
#define radix_tagged_block(block)
#define radix_block(block)
#endif
/* DEBUG_OUTPUT */
#endif
/*
RADIX_
DEBUG_OUTPUT */
#include <sstream>
#include <stdexcept>
...
...
@@ -96,37 +89,46 @@
// Insist is always enabled
#if RADIX_DBC & 1
#define radix_require(c) \
do \
{ \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " radix_require(" << #c \
<< ") failed." << std::endl; \
throw std::runtime_error(stream.str()); \
}
} \
} while (false)
#else
#define radix_require(c)
#endif
#if RADIX_DBC & 2
#define radix_check(c) \
do \
{ \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " radix_check(" << #c \
<< ") failed." << std::endl; \
throw std::runtime_error(stream.str()); \
}
} \
} while (false)
#else
#define radix_check(c)
#endif
#if RADIX_DBC & 4
#define radix_ensure(c) \
do \
{ \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " radix_ensure(" << #c \
<< ") failed." << std::endl; \
throw std::runtime_error(stream.str()); \
}
} \
} while (false)
#define radix_remember(c) c
#else
#define radix_ensure(c)
...
...
@@ -134,6 +136,8 @@
#endif
#define radix_insist(c, msg) \
do \
{ \
if (!(c)) \
{ \
std::ostringstream stream; \
...
...
@@ -141,15 +145,26 @@
<< ") failed with this message:" << std::endl \
<< msg << std::endl; \
throw std::runtime_error(stream.str()); \
}
} \
} while (false)
#define radix_not_implemented(msg) \
do \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " : " << msg \
<< " is not implemented. " << std::endl; \
throw std::runtime_error(stream.str()); \
}
} while (false)
#define radix_not_reachable() \
do \
{ \
std::ostringstream stream; \
stream << "Execution encountered unreachable code point at " << __FILE__ \
<< ":" << __LINE__ << std::endl; \
throw std::runtime_error(stream.str()); \
} while (false)
/// set default timing to off
#ifndef RADIX_TIMING
...
...
@@ -160,6 +175,11 @@
#include <ctime>
namespace
radix
{
/**
* @brief Timer implementation for recording duration between start and stop
* points.
*
*/
class
Timer
{
private:
...
...
@@ -176,6 +196,10 @@ class Timer
,
mIntervals
(
0
)
{
}
/**
* @brief Mark the start time for this timer
*
*/
void
start
()
{
radix_check
(
!
mRunning
);
...
...
@@ -183,6 +207,10 @@ class Timer
mIntervals
++
;
mStart
=
std
::
chrono
::
steady_clock
::
now
();
}
/**
* @brief Mark the stop time and record duration of time.
*
*/
void
stop
()
{
radix_check
(
mRunning
);
...
...
@@ -192,13 +220,30 @@ class Timer
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
mEnd
-
mStart
);
}
/**
* @brief Returns duration this timer ran in nanoseconds
*
* @return std::chrono::nanoseconds::rep
*/
std
::
chrono
::
nanoseconds
::
rep
duration
()
const
{
radix_check
(
!
mRunning
);
return
mDuration
.
count
();
}
/**
* @brief Returns the number times this timer was started and subsequently
* stopped.
*
* @return size_t
*/
size_t
intervals
()
const
{
return
mIntervals
;
}
/**
* @brief Returns the duration this timer ran in wall clock seconds.
* Does not account for intervals
* @return double durantion in seconds
*/
double
wall_clock
()
{
radix_require
(
!
mRunning
);
...
...
@@ -207,6 +252,12 @@ class Timer
return
seconds
(
mEnd
-
mStart
).
count
();
}
/**
* @brief Returns the duration this timer ran accounting for start/stop
* intervals
*
* @return double duration in seconds
*/
double
sum_wall_clock
()
{
// 1e9 nanoseconds in a second
...
...
@@ -214,6 +265,12 @@ class Timer
return
seconds
(
mDuration
).
count
();
}
/**
* @brief Returns whether this timer is currently counting.
*
* @return true The timer is running.
* @return false The timer is not running.
*/
bool
running
()
const
{
return
mRunning
;
};
};
...
...
@@ -255,4 +312,4 @@ class Timer
#define radix_timer_block_3(content)
#endif
#endif
/* RADIX_RADIX
BUG
_BUG_HH_*/
#endif
/* RADIX_RADIX
CORE
_BUG_HH_*/
radixbug/tests/tstBug.cc
View file @
e2447af3
...
...
@@ -2,6 +2,8 @@
// force RADIX_TIMING on
#define RADIX_TIMING 3
// force RADIX_DBC on
#define RADIX_DBC 7
#include "radixbug/bug.hh"
TEST
(
radixbug
,
Timer
)
...
...
@@ -47,3 +49,66 @@ TEST(radixbug, Timer)
std
::
cout
<<
"Wall clock (s): "
<<
timer1
.
wall_clock
()
<<
std
::
endl
;
std
::
cout
<<
"Sum wall clock (s): "
<<
timer1
.
sum_wall_clock
()
<<
std
::
endl
;
}
TEST
(
radixcore
,
DBC
)
{
try
{
radix_check
(
false
);
EXPECT_TRUE
(
false
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
cout
<<
"Successful radix_check()"
<<
std
::
endl
;
radix_check
(
true
);
}
try
{
radix_require
(
false
);
EXPECT_TRUE
(
false
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
cout
<<
"Successful radix_require()"
<<
std
::
endl
;
radix_require
(
true
);
}
try
{
radix_ensure
(
false
);
EXPECT_TRUE
(
false
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
cout
<<
"Successful radix_ensure()"
<<
std
::
endl
;
radix_ensure
(
true
);
}
try
{
radix_insist
(
false
,
"Will cause error"
);
EXPECT_TRUE
(
false
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
cout
<<
"Successful radix_insist()"
<<
std
::
endl
;
radix_insist
(
true
,
"Will not cause error"
);
}
try
{
radix_not_implemented
(
"not implemented"
);
EXPECT_TRUE
(
false
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
cout
<<
"Successful radix_not_implemented()"
<<
std
::
endl
;
}
try
{
radix_not_reachable
();
EXPECT_TRUE
(
false
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
cout
<<
"Successful radix_not_reachable()"
<<
std
::
endl
;
}
}
radixcore/value.cc
View file @
e2447af3
...
...
@@ -276,9 +276,9 @@ int Value::to_int() const
radix_not_implemented
(
"conversion of array to integer"
);
case
TYPE_OBJECT
:
radix_not_implemented
(
"conversion of object to integer"
)
radix_not_implemented
(
"conversion of object to integer"
)
;
}
radix_not_implemented
(
"unknown type conversion to integer"
)
radix_not_implemented
(
"unknown type conversion to integer"
)
;
}
double
Value
::
to_double
()
const
{
...
...
@@ -305,9 +305,9 @@ double Value::to_double() const
radix_not_implemented
(
"conversion of array to double"
);
case
TYPE_OBJECT
:
radix_not_implemented
(
"conversion of object to double"
)
radix_not_implemented
(
"conversion of object to double"
)
;
}
radix_not_implemented
(
"unknown type conversion to double"
)
radix_not_implemented
(
"unknown type conversion to double"
)
;
}
bool
Value
::
to_bool
()
const
{
...
...
@@ -332,9 +332,9 @@ bool Value::to_bool() const
radix_not_implemented
(
"conversion of array to double"
);
case
TYPE_OBJECT
:
radix_not_implemented
(
"conversion of object to double"
)
radix_not_implemented
(
"conversion of object to double"
)
;
}
radix_not_implemented
(
"unknown type conversion to bool"
)
radix_not_implemented
(
"unknown type conversion to bool"
)
;
}
const
char
*
Value
::
to_cstring
()
const
{
...
...
@@ -353,9 +353,9 @@ const char* Value::to_cstring() const
radix_not_implemented
(
"conversion of array to cstring"
);
case
TYPE_OBJECT
:
radix_not_implemented
(
"conversion of object to cstring"
)
radix_not_implemented
(
"conversion of object to cstring"
)
;
}
radix_not_implemented
(
"unknown type conversion to cstring"
)
radix_not_implemented
(
"unknown type conversion to cstring"
)
;
}
std
::
string
Value
::
to_string
()
const
{
...
...
@@ -381,50 +381,48 @@ std::string Value::to_string() const
to_object
()
->
pack_json
(
str
);
return
str
.
str
();
}
radix_not_implemented
(
"unknown type conversion to string"
)
radix_not_implemented
(
"unknown type conversion to string"
)
;
}
DataArray
*
Value
::
to_array
()
const
{
radix_insist
(
convertable
(
TYPE_ARRAY
),
"Value object must be convertable to an array"
)
return
m_data
.
m_array
;
radix_insist
(
convertable
(
TYPE_ARRAY
),
"Value object must be convertable to an array"
);
return
m_data
.
m_array
;
}
DataObject
*
Value
::
to_object
()
const
{
radix_insist
(
convertable
(
TYPE_OBJECT
),
"Value object must be convertable to an object"
)
return
m_data
.
m_object
;
radix_insist
(
convertable
(
TYPE_OBJECT
),
"Value object must be convertable to an object"
);
return
m_data
.
m_object
;
}
const
DataArray
&
Value
::
as_array
()
const
{
radix_insist
(
convertable
(
TYPE_ARRAY
),
"Value object must be convertable to an array"
)
return
*
(
m_data
.
m_array
);
radix_insist
(
convertable
(
TYPE_ARRAY
),
"Value object must be convertable to an array"
);
return
*
(
m_data
.
m_array
);
}
DataArray
&
Value
::
as_array
()
{
radix_insist
(
convertable
(
TYPE_ARRAY
),
"Value object must be convertable to an array"
)
return
*
(
m_data
.
m_array
);
radix_insist
(
convertable
(
TYPE_ARRAY
),
"Value object must be convertable to an array"
);
return
*
(
m_data
.
m_array
);
}
const
DataObject
&
Value
::
as_object
()
const
{
radix_insist
(
convertable
(
TYPE_OBJECT
),
"Value object must be convertable to an object"
)
return
*
(
m_data
.
m_object
);
radix_insist
(
convertable
(
TYPE_OBJECT
),
"Value object must be convertable to an object"
);
return
*
(
m_data
.
m_object
);
}
DataObject
&
Value
::
as_object
()
{
radix_insist
(
convertable
(
TYPE_OBJECT
),
"Value object must be convertable to an object"
)
return
*
(
m_data
.
m_object
);
radix_insist
(
convertable
(
TYPE_OBJECT
),
"Value object must be convertable to an object"
);
return
*
(
m_data
.
m_object
);
}
bool
Value
::
convertable
(
Value
::
Type
to
)
const
{
...
...
@@ -443,7 +441,7 @@ bool Value::convertable(Value::Type to) const
case
TYPE_OBJECT
:
return
is_object
();
}
radix_not_implemented
(
"unknown type conversion"
)
radix_not_implemented
(
"unknown type conversion"
)
;
}
Value
&
Value
::
operator
[](
const
std
::
string
&
name
)
...
...
@@ -531,7 +529,7 @@ bool Value::format_json(std::ostream& out, int indent_level, int level,
out
<<
"null"
;
break
;
default:
radix_not_implemented
(
"unknown Object value type json emission"
)
radix_not_implemented
(
"unknown Object value type json emission"
)
;
}
}
return
out
.
good
();
...
...
@@ -567,7 +565,7 @@ bool Value::pack_json(std::ostream& out) const
out
<<
"null"
;
break
;
default:
radix_not_implemented
(
"unknown Object value type json emission"
)
radix_not_implemented
(
"unknown Object value type json emission"
)
;
}
}
return
out
.
good
();
...
...
@@ -678,8 +676,8 @@ void DataArray::merge(const DataArray& rhs)
}
DataObject
::
DataObject
()
{}
DataObject
::
DataObject
(
const
DataObject
&
orig
)
:
m_
data
(
orig
.
m_data
)
,
m_
insert_order
(
orig
.
m_insert_order
)
:
m_
insert_order
(
orig
.
m_insert_order
)
,
m_
data
(
orig
.
m_data
)
{
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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