Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
99d4af37
Commit
99d4af37
authored
Dec 31, 2017
by
Jordan P. Lefebvre
Browse files
Updating .clang-format option BreakBeforeBraces to be Allman. Applying updated format.
parent
522b19d0
Changes
114
Hide whitespace changes
Inline
Side-by-side
.clang-format
View file @
99d4af37
...
...
@@ -36,7 +36,7 @@ BraceWrapping:
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: A
ttach
BreakBeforeBraces: A
llman
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
...
...
radixalgorithm/ordering.cc
View file @
99d4af37
...
...
@@ -2,8 +2,10 @@
#include
<iostream>
namespace
radix
{
void
super_sad_necessary_hack_for_dll_lib_creation
::
foo_method
()
{
namespace
radix
{
void
super_sad_necessary_hack_for_dll_lib_creation
::
foo_method
()
{
std
::
cout
<<
"This is a dummy method for compilation symbol"
<<
std
::
endl
;
}
...
...
radixalgorithm/ordering.hh
View file @
99d4af37
...
...
@@ -5,15 +5,17 @@
#include
<vector>
#include
"radixdl/visibility.hh"
namespace
radix
{
struct
RADIX_PUBLIC
super_sad_necessary_hack_for_dll_lib_creation
{
namespace
radix
{
struct
RADIX_PUBLIC
super_sad_necessary_hack_for_dll_lib_creation
{
void
foo_method
();
};
template
<
typename
list_type
,
typename
compare_type
>
RADIX_PUBLIC
std
::
vector
<
size_t
>
sort_permutation
(
const
list_type
&
data
,
compare_type
&
comparator
)
{
compare_type
&
comparator
)
{
// create list of indices the size of the incoming data
std
::
vector
<
std
::
size_t
>
order
(
data
.
size
());
// initialize list with initial index, starting at zero
...
...
@@ -30,9 +32,11 @@ RADIX_PUBLIC std::vector<size_t> sort_permutation(const list_type &data,
template
<
typename
list_type
>
RADIX_PUBLIC
void
apply_permutation
(
list_type
&
data
,
const
std
::
vector
<
size_t
>
&
order
)
{
const
std
::
vector
<
size_t
>
&
order
)
{
std
::
vector
<
bool
>
done
(
data
.
size
(),
false
);
for
(
size_t
i
=
0
;
i
<
data
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
data
.
size
();
++
i
)
{
if
(
done
[
i
])
continue
;
done
[
i
]
=
true
;
// previous ordering is that of the loop, so index i it is
...
...
@@ -40,7 +44,8 @@ RADIX_PUBLIC void apply_permutation(list_type &data,
// get the new order lookup
size_t
j
=
order
[
i
];
//
while
(
i
!=
j
)
{
while
(
i
!=
j
)
{
radix_line
(
i
<<
". swapping "
<<
prev_j
<<
" for "
<<
j
);
std
::
swap
(
data
[
prev_j
],
data
[
j
]);
done
[
j
]
=
true
;
...
...
radixalgorithm/tests/tstOrdering.cc
View file @
99d4af37
...
...
@@ -4,7 +4,8 @@
#include
"radixalgorithm/ordering.hh"
#include
"radixbug/bug.hh"
TEST
(
radixalgorithm
,
Ordering
)
{
TEST
(
radixalgorithm
,
Ordering
)
{
std
::
vector
<
double
>
list
{
2.0
,
1.0
,
3.0
,
4.0
,
5.0
,
0.0
,
10.0
};
// permutation 5, 1, 0, 2, 3, 4, 6
// correct ordering
...
...
@@ -18,7 +19,8 @@ TEST(radixalgorithm, Ordering) {
EXPECT_EQ
(
permutation
[
0
],
5
);
EXPECT_EQ
(
permutation
[
6
],
6
);
std
::
cout
<<
"Ordering:"
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
permutation
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
permutation
.
size
();
++
i
)
{
std
::
cout
<<
"index "
<<
i
<<
". ("
<<
list
[
i
]
<<
") recieves value from "
<<
permutation
[
i
]
<<
" ("
<<
list
[
permutation
[
i
]]
<<
")"
<<
std
::
endl
;
...
...
@@ -31,7 +33,8 @@ TEST(radixalgorithm, Ordering) {
radix
::
apply_permutation
(
list2
,
permutation
);
EXPECT_EQ
(
list2
[
0
],
5
);
EXPECT_EQ
(
list2
[
6
],
6
);
for
(
size_t
i
=
0
;
i
<
list
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
list
.
size
();
++
i
)
{
std
::
cout
<<
"["
<<
list
[
i
]
<<
","
<<
list2
[
i
]
<<
"]"
<<
std
::
endl
;
}
}
radixams/main.cc
View file @
99d4af37
...
...
@@ -9,7 +9,8 @@
#include
<cmath>
using
namespace
radix
;
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
CommandLine
command
(
argc
,
argv
);
command
.
declareArgument
(
"altitude"
,
...
...
@@ -18,7 +19,8 @@ int main(int argc, char **argv) {
command
.
declareArgument
(
"energy"
,
"Gamma ray energy in MeV"
);
// expecting three arguments
if
(
!
command
.
validate
(
std
::
cerr
))
{
if
(
!
command
.
validate
(
std
::
cerr
))
{
command
.
help
(
std
::
cerr
);
return
0
;
}
...
...
@@ -43,7 +45,8 @@ int main(int argc, char **argv) {
double
sigma
=
1.225
;
// not at sea level, update sigma
if
(
std
::
fabs
(
z
)
>
1e-16
)
{
if
(
std
::
fabs
(
z
)
>
1e-16
)
{
sigma
=
1.911515e-16
*
(
z
*
z
*
z
*
z
)
-
9.857582e-13
*
(
z
*
z
*
z
)
+
5.399174e-9
*
(
z
*
z
)
-
1.180686e-4
*
z
+
1.22507
;
}
...
...
@@ -68,12 +71,14 @@ int main(int argc, char **argv) {
auto
DRz
=
DRg
*
EIRatio
;
// report dose rate at sea level
if
(
std
::
fabs
(
z
)
<
1e-16
)
{
if
(
std
::
fabs
(
z
)
<
1e-16
)
{
std
::
cout
<<
std
::
scientific
<<
DRg
<<
" is the Dose Rate at Ground Sea Level in R/hr"
<<
std
::
endl
;
}
// report dose rate at altitude above sea level
else
{
else
{
std
::
cout
<<
std
::
scientific
<<
DRz
<<
" is the Dose Rate at your Altitude above Ground Sea Level in R/hr"
...
...
radixbug/bug.hh
View file @
99d4af37
...
...
@@ -90,7 +90,8 @@
// Insist is always enabled
#if RADIX_DBC & 1
#define radix_require(c) \
if (!(c)) { \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " radix_require(" << #c \
<< ") failed." << std::endl; \
...
...
@@ -101,7 +102,8 @@
#endif
#if RADIX_DBC & 2
#define radix_check(c) \
if (!(c)) { \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " radix_check(" << #c \
<< ") failed." << std::endl; \
...
...
@@ -112,7 +114,8 @@
#endif
#if RADIX_DBC & 4
#define radix_ensure(c) \
if (!(c)) { \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << " radix_ensure(" << #c \
<< ") failed." << std::endl; \
...
...
@@ -125,7 +128,8 @@
#endif
#define radix_insist(c, msg) \
if (!(c)) { \
if (!(c)) \
{ \
std::ostringstream stream; \
stream << __FILE__ << ":" << __LINE__ << "radix_insist(" << #c \
<< ") failed with this message:" << std::endl \
...
...
@@ -140,8 +144,10 @@
#include
<chrono>
#include
<ctime>
namespace
radix
{
class
Timer
{
namespace
radix
{
class
Timer
{
private:
bool
mRunning
;
std
::
chrono
::
steady_clock
::
time_point
mStart
;
...
...
@@ -153,14 +159,18 @@ class Timer {
Timer
()
:
mRunning
(
false
)
,
mDuration
(
0
)
,
mIntervals
(
0
)
{}
void
start
()
{
,
mIntervals
(
0
)
{
}
void
start
()
{
radix_check
(
!
mRunning
);
mRunning
=
true
;
mIntervals
++
;
mStart
=
std
::
chrono
::
steady_clock
::
now
();
}
void
stop
()
{
void
stop
()
{
radix_check
(
mRunning
);
mEnd
=
std
::
chrono
::
steady_clock
::
now
();
mRunning
=
false
;
...
...
@@ -168,7 +178,8 @@ class Timer {
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
mEnd
-
mStart
);
}
double
duration
()
const
{
double
duration
()
const
{
radix_check
(
!
mRunning
);
return
mDuration
.
count
();
}
...
...
radixbug/tests/tstBug.cc
View file @
99d4af37
...
...
@@ -4,7 +4,8 @@
#define RADIX_TIMING 3
#include
"radixbug/bug.hh"
TEST
(
radixbug
,
Timer
)
{
TEST
(
radixbug
,
Timer
)
{
radix_timer
(
timer1
);
radix_timer_2
(
timer2
);
radix_timer_3
(
timer3
);
...
...
@@ -13,9 +14,11 @@ TEST(radixbug, Timer) {
//
// demostrate timing metrics
radix_timer_start
(
timer1
);
for
(
size_t
i
=
0
;
i
<
100
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
100
;
++
i
)
{
radix_timer_start_2
(
timer2
);
for
(
size_t
j
=
0
;
j
<
10000
;
++
j
)
{
for
(
size_t
j
=
0
;
j
<
10000
;
++
j
)
{
radix_timer_start_3
(
timer3
);
value
=
value
+
func
(
value
);
radix_timer_stop_3
(
timer3
);
...
...
radixcommand/commandline.cc
View file @
99d4af37
#include
"radixcommand/commandline.hh"
namespace
radix
{
namespace
radix
{
CommandLine
::
CommandLine
(
int
argc
,
char
**
argv
)
:
mArgc
(
argc
)
,
mArgv
(
argv
)
{
,
mArgv
(
argv
)
{
if
(
argc
<
1
)
return
;
mExecutable
=
argv
[
0
];
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
std
::
string
temp
=
std
::
string
(
argv
[
i
]);
std
::
tuple
<
std
::
string
,
std
::
string
,
bool
>
data
=
std
::
make_tuple
(
""
,
""
,
false
);
//
// Check for '-' as first character
//
if
(
temp
.
size
()
>
0
)
{
if
(
temp
.
at
(
0
)
==
'-'
)
{
if
(
temp
.
size
()
>
0
)
{
if
(
temp
.
at
(
0
)
==
'-'
)
{
//
// Check for flag=value
//
size_t
index
=
temp
.
find
(
'='
);
if
(
index
==
std
::
string
::
npos
)
{
if
(
index
==
std
::
string
::
npos
)
{
// we didn't find equal sign
//
// This is just a flag with empty value
//
std
::
get
<
0
>
(
data
)
=
std
::
string
(
""
);
mData
.
insert
(
std
::
make_pair
(
temp
.
substr
(
1
),
data
));
}
else
{
}
else
{
//
// We found equal sign, so we must divide into flag and value
//
...
...
@@ -37,13 +44,15 @@ CommandLine::CommandLine(int argc, char **argv)
// Check to make sure empty string wasn't provided
// flag=''
if
(
temp
.
size
()
-
1
!=
index
)
{
if
(
temp
.
size
()
-
1
!=
index
)
{
std
::
get
<
0
>
(
data
)
=
temp
.
substr
(
index
+
1
,
temp
.
size
()
-
1
);
}
mData
.
insert
(
std
::
make_pair
(
flag
,
data
));
}
// else
}
// if = '-'
else
{
else
{
mArgs
.
push_back
(
temp
);
}
}
// if size > 0
...
...
@@ -51,113 +60,150 @@ CommandLine::CommandLine(int argc, char **argv)
}
void
CommandLine
::
addOption
(
const
std
::
string
&
name
,
const
std
::
string
&
description
,
bool
required
)
{
const
std
::
string
&
description
,
bool
required
)
{
// check if option was parsed in
const
auto
&
it
=
mData
.
find
(
name
);
if
(
it
==
mData
.
end
())
{
if
(
it
==
mData
.
end
())
{
// create a new tuple with no value
mData
.
insert
(
std
::
make_pair
(
name
,
std
::
make_tuple
(
std
::
string
(
""
),
description
,
required
)));
}
else
{
}
else
{
// update existing entry
std
::
get
<
1
>
(
it
->
second
)
=
description
;
std
::
get
<
2
>
(
it
->
second
)
=
required
;
}
}
void
CommandLine
::
printParsedLine
(
std
::
ostream
&
out
)
const
{
void
CommandLine
::
printParsedLine
(
std
::
ostream
&
out
)
const
{
out
<<
"Executable: '"
<<
mExecutable
<<
"'"
<<
std
::
endl
;
if
(
0
<
mData
.
size
())
{
if
(
0
<
mData
.
size
())
{
out
<<
"Options:"
<<
std
::
endl
;
}
int
unknown
=
0
;
for
(
const
auto
&
it
:
mData
)
{
for
(
const
auto
&
it
:
mData
)
{
// <0> is value
std
::
string
value
=
std
::
get
<
0
>
(
it
.
second
);
// check descriptions to indicate if this is a known option
bool
known
=
!
std
::
get
<
1
>
(
it
.
second
).
empty
();
bool
required
=
std
::
get
<
2
>
(
it
.
second
);
if
(
!
known
)
{
if
(
!
known
)
{
unknown
++
;
}
out
<<
"
\t
"
;
if
(
known
)
{
if
(
required
)
{
if
(
known
)
{
if
(
required
)
{
out
<<
"["
<<
it
.
first
<<
"] "
<<
value
;
}
else
{
}
else
{
out
<<
"<"
<<
it
.
first
<<
"> "
<<
value
;
}
out
<<
" -- "
<<
std
::
get
<
1
>
(
it
.
second
)
<<
std
::
endl
;
}
else
{
}
else
{
out
<<
"*"
<<
it
.
first
<<
" "
<<
value
<<
std
::
endl
;
}
}
if
(
0
<
mArgs
.
size
())
{
if
(
0
<
mArgs
.
size
())
{
out
<<
"Arguments:"
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
mArgs
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
mArgs
.
size
();
++
i
)
{
out
<<
"
\t
"
<<
mArgs
[
i
]
<<
std
::
endl
;
}
}
else
{
}
else
{
out
<<
"No arguments."
<<
std
::
endl
;
}
if
(
unknown
)
{
if
(
unknown
)
{
out
<<
"* - unknown/unrecognized input("
<<
unknown
<<
")"
<<
std
::
endl
;
}
}
void
CommandLine
::
help
(
std
::
ostream
&
out
)
const
{
void
CommandLine
::
help
(
std
::
ostream
&
out
)
const
{
// dump commandline example first
out
<<
mExecutable
;
for
(
const
auto
&
it
:
mData
)
{
for
(
const
auto
&
it
:
mData
)
{
// <0> is value
std
::
string
value
=
std
::
get
<
0
>
(
it
.
second
);
// check descriptions to indicate if this is a known option
bool
hasDoc
=
!
std
::
get
<
1
>
(
it
.
second
).
empty
();
bool
required
=
std
::
get
<
2
>
(
it
.
second
);
if
(
hasDoc
)
{
if
(
required
)
{
if
(
hasDoc
)
{
if
(
required
)
{
out
<<
" [-"
<<
it
.
first
<<
"=var]"
;
}
else
{
}
else
{
out
<<
" <-"
<<
it
.
first
<<
"<=var>>"
;
}
}
}
for
(
size_t
i
=
0
;
i
<
mDeclArgs
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
mDeclArgs
.
size
();
++
i
)
{
out
<<
" "
<<
mDeclArgs
[
i
].
first
;
}
out
<<
std
::
endl
;
for
(
const
auto
&
it
:
mData
)
{
for
(
const
auto
&
it
:
mData
)
{
// <0> is value
std
::
string
value
=
std
::
get
<
0
>
(
it
.
second
);
// check descriptions to indicate if this is a known option
bool
hasDoc
=
!
std
::
get
<
1
>
(
it
.
second
).
empty
();
bool
required
=
std
::
get
<
2
>
(
it
.
second
);
if
(
hasDoc
)
{
if
(
hasDoc
)
{
out
<<
"
\t
"
;
if
(
required
)
{
if
(
required
)
{
out
<<
"["
<<
it
.
first
<<
"] "
;
}
else
{
}
else
{
out
<<
"<"
<<
it
.
first
<<
"> "
;
}
out
<<
" -- "
<<
std
::
get
<
1
>
(
it
.
second
)
<<
std
::
endl
;
}
}
for
(
size_t
i
=
mArgs
.
size
();
i
<
mDeclArgs
.
size
();
++
i
)
{
for
(
size_t
i
=
mArgs
.
size
();
i
<
mDeclArgs
.
size
();
++
i
)
{
out
<<
"
\t
"
<<
mDeclArgs
[
i
].
first
;
if
(
!
mDeclArgs
[
i
].
second
.
empty
())
{
if
(
!
mDeclArgs
[
i
].
second
.
empty
())
{
out
<<
" -- "
<<
mDeclArgs
[
i
].
second
<<
std
::
endl
;
}
else
{
}
else
{
out
<<
std
::
endl
;
}
}
}
bool
CommandLine
::
exists
(
const
std
::
string
&
name
)
const
{
bool
CommandLine
::
exists
(
const
std
::
string
&
name
)
const
{
const
auto
&
it
=
mData
.
find
(
name
);
return
(
it
!=
mData
.
end
());
}
bool
CommandLine
::
existsNotEmpty
(
const
std
::
string
&
name
)
const
{
bool
CommandLine
::
existsNotEmpty
(
const
std
::
string
&
name
)
const
{
const
auto
&
it
=
mData
.
find
(
name
);
bool
exists
=
(
it
!=
mData
.
end
());
if
(
!
exists
)
return
false
;
...
...
@@ -167,45 +213,59 @@ bool CommandLine::existsNotEmpty(const std::string &name) const {
const
std
::
vector
<
std
::
string
>
&
CommandLine
::
arguments
()
const
{
return
mArgs
;
}
void
CommandLine
::
setArguments
(
const
std
::
vector
<
std
::
string
>
&
args
)
{
void
CommandLine
::
setArguments
(
const
std
::
vector
<
std
::
string
>
&
args
)
{
mArgs
=
args
;
}
std
::
string
CommandLine
::
executable
()
const
{
return
mExecutable
;
}
void
CommandLine
::
setExecutable
(
const
std
::
string
&
executable
)
{
void
CommandLine
::
setExecutable
(
const
std
::
string
&
executable
)
{
mExecutable
=
executable
;
}
void
CommandLine
::
declareArgument
(
const
std
::
string
&
id
,
const
std
::
string
&
description
)
{
const
std
::
string
&
description
)
{
mDeclArgs
.
push_back
(
std
::
make_pair
(
id
,
description
));
}
bool
CommandLine
::
validate
(
std
::
vector
<
std
::
string
>
&
errors
)
const
{
for
(
const
auto
&
it
:
mData
)
{
bool
CommandLine
::
validate
(
std
::
vector
<
std
::
string
>
&
errors
)
const
{
for
(
const
auto
&
it
:
mData
)
{
// check if value is empty/no set
bool
empty
=
std
::
get
<
0
>
(
it
.
second
).
empty
();
bool
required
=
std
::
get
<
2
>
(
it
.
second
);
if
(
required
&&
empty
)
{
if
(
required
&&
empty
)
{
std
::
stringstream
ss
;
ss
<<
"Required option: '"
<<
it
.
first
<<
"' is missing."
;
errors
.
push_back
(
ss
.
str
());
}
}
// ensure the number of arguments matchs the number of declared arguments
if
(
mArgs
.
size
()
<
mDeclArgs
.
size
())
{
if
(
mArgs
.
size
()
<
mDeclArgs
.
size
())
{
std
::
stringstream
ss
;
ss
<<
"Missing required argument"
;
if
((
mDeclArgs
.
size
()
-
mArgs
.
size
())
==
1
)
{
if
((
mDeclArgs
.
size
()
-
mArgs
.
size
())
==
1
)
{
ss
<<
" '"
<<
mDeclArgs
[
mArgs
.
size
()].
first
<<
"'"
;
}
else
{
}
else
{
ss
<<
"s:"
<<
std
::
endl
;
for
(
size_t
i
=
mArgs
.
size
();
i
<
mDeclArgs
.
size
();
++
i
)
{
for
(
size_t
i
=
mArgs
.
size
();
i
<
mDeclArgs
.
size
();
++
i
)
{
ss
<<
"
\t
'"
<<
mDeclArgs
[
i
].
first
;
if
(
!
mDeclArgs
[
i
].
second
.
empty
())
{
if
(
!
mDeclArgs
[
i
].
second
.
empty
())
{
ss
<<
"' -- "
<<
mDeclArgs
[
i
].
second
<<
std
::
endl
;
}
else
{
}
else
{
ss
<<
"'"
<<
std
::
endl
;
}
}
...
...
@@ -216,26 +276,33 @@ bool CommandLine::validate(std::vector<std::string> &errors) const {
return
true
;
}
bool
CommandLine
::
validate
(
std
::
ostream
&
out
)
const
{
bool
CommandLine
::
validate
(
std
::
ostream
&
out
)
const
{
std
::
vector
<
std
::
string
>
errors
;
bool
valid
=
validate
(
errors
);
for
(
size_t
i
=
0
;
i
<
errors
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
errors
.
size
();
++
i
)
{
out
<<
errors
[
i
]
<<
std
::
endl
;
}
return
valid
;
}
template
<
>
std
::
string
CommandLine
::
get
(
const
std
::
string
&
name
)
const
{
std
::
string
CommandLine
::
get
(
const
std
::
string
&
name
)
const
{
std
::
string
result
;
const
auto
&
it
=
mData
.
find
(
name
);
if
(
it
==
mData
.
end
())
{
if
(
it
==
mData
.
end
())
{
std
::
stringstream
ss
;
ss
<<
"No such option: "
<<
name
;
throw
std
::
logic_error
(
ss
.
str
());
}
else
{
}
else
{
std
::
string
value
=
std
::
get
<
0
>
(
it
->
second
);
if
(
value
.
empty
())
{
if
(
value
.
empty
())
{
std
::
stringstream
ss
;
ss
<<
"Illegal attempt to convert flag '"
<<
name
<<
"' to a value."
;
throw
std
::
logic_error
(
ss
.
str
());
...
...
@@ -246,15 +313,18 @@ std::string CommandLine::get(const std::string &name) const {
}
template
<
>
std
::
string
CommandLine
::
get
(
const
std
::
string
&
name
,
std
::
string
defaultValue
)
const
{
std
::
string
defaultValue
)
const