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
Martin Reinecke
ducc
Commits
c37e04f1
Commit
c37e04f1
authored
Dec 28, 2019
by
Martin Reinecke
Browse files
evolution
parent
52df59d3
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/mr_util
/datatypes.h
→
not_yet_integrated
/datatypes.h
View file @
c37e04f1
File moved
cxxsupport
/misc_utils.h
→
not_yet_integrated
/misc_utils.h
View file @
c37e04f1
File moved
cxxsupport
/vec.h
→
not_yet_integrated
/vec.h
View file @
c37e04f1
File moved
src/error_handling.cc
View file @
c37e04f1
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#include
"mr_util/error_handling.h"
using
namespace
std
;
...
...
@@ -12,8 +33,9 @@ bool abort_in_progress__ = false;
ostream
&
CodeLocation
::
print
(
ostream
&
os
)
const
{
os
<<
"file: "
<<
file
<<
", line: "
<<
line
;
if
(
func
)
os
<<
", function: "
<<
func
;
os
<<
file
<<
": "
<<
line
;
if
(
func
)
os
<<
" ("
<<
func
<<
")"
;
os
<<
":
\n
"
;
return
os
;
}
...
...
src/mr_util/error_handling.h
View file @
c37e04f1
...
...
@@ -54,7 +54,7 @@ namespace detail {
else { MR_fail("Assertion failure\n", ##__VA_ARGS__); } \
} while(0)
// to be replaced with std::source_location once available
// to be replaced with std::source_location once
generally
available
class
CodeLocation
{
private:
...
...
@@ -74,7 +74,11 @@ inline ::std::ostream &operator<<(::std::ostream &os, const CodeLocation &loc)
extern
bool
abort_in_progress__
;
void
killjob__
();
#if 1
#if (__cplusplus>=201703L) // hyper-elegant C++2017 version
template
<
typename
...
Args
>
inline
void
streamDump__
(
::
std
::
ostream
&
os
,
Args
&&
...
args
)
{
(
os
<<
...
<<
args
);
}
#else
template
<
typename
T
>
inline
void
streamDump__
(
::
std
::
ostream
&
os
,
const
T
&
value
)
{
os
<<
value
;
}
...
...
@@ -86,11 +90,6 @@ inline void streamDump__(::std::ostream &os, const T& value,
os
<<
value
;
streamDump__
(
os
,
args
...);
}
#else
// hyper-elegant C++2017 version
template
<
typename
...
Args
>
inline
void
streamDump__
(
::
std
::
ostream
&
os
,
Args
&&
...
args
)
{
(
os
<<
...
<<
args
);
}
#endif
}}}
...
...
src/mr_util/gl_integrator.h
View file @
c37e04f1
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_GL_INTEGRATOR_H
#define MRUTIL_GL_INTEGRATOR_H
...
...
src/mr_util/mav.h
View file @
c37e04f1
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_MAV_H
#define MRUTIL_MAV_H
...
...
src/mr_util/string_utils.h
View file @
c37e04f1
/*
* This file is part of
libcxxsupport
.
* This file is part of
the MR utility library
.
*
*
libcxxsupport
is free software; you can redistribute it and/or modify
*
This code
is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
libcxxsupport
is distributed in the hope that it will be useful,
*
This code
is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with
libcxxsupport
; if not, write to the Free Software
* along with
this code
; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
* (DLR).
*/
/*! \file string_utils.h
* Various functions for manipulating strings.
*
* Copyright (C) 2002-2018 Max-Planck-Society
* \author Martin Reinecke
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_STRING_UTILS_H
#define MRUTIL_STRING_UTILS_H
...
...
src/mr_util/system.h
View file @
c37e04f1
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_SYSTEM_H
#define MRUTIL_SYSTEM_H
...
...
src/mr_util/threading.h
View file @
c37e04f1
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Peter Bell, Max-Planck-Society
Author: Peter Bell, Martin Reinecke */
#ifndef MRUTIL_THREADING_H
#define MRUTIL_THREADING_H
...
...
@@ -9,11 +30,12 @@
#include
<atomic>
#include
<functional>
#include
<vector>
#ifdef MRUTIL_THREADING_PTHREADS
# include <pthread.h>
#if __has_include(<pthread.h>)
#include
<pthread.h>
#endif
// FIXME: allow disabling multithreading altogether
namespace
mr
{
namespace
threading
{
...
...
@@ -156,7 +178,7 @@ class thread_pool
thread_pool
&
get_pool
()
{
static
thread_pool
pool
;
#if
def MR_THREADING_PTHREADS
#if
__has_include(<pthread.h>)
static
once_flag
f
;
call_once
(
f
,
[]{
...
...
@@ -330,6 +352,8 @@ using detail::execStatic;
using
detail
::
execDynamic
;
using
detail
::
execGuided
;
// FIXME: missing execParallel(), my_thread(), num_threads()
}
// end of namespace threading
}
// end of namespace mr
...
...
src/mr_util/vecsupport.h
View file @
c37e04f1
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_VECSUPPORT_H
#define MRUTIL_VECSUPPORT_H
...
...
@@ -68,9 +89,66 @@ template<typename T, size_t len=vbytes/sizeof(T)> class vtp
template
<
typename
I
>
T
operator
[](
I
i
)
const
{
return
v
[
i
];
}
};
template
<
typename
T
>
class
aligned_array
{
private:
T
*
p
;
size_t
sz
;
#if (__cplusplus >= 201703L)
static
T
*
ralloc
(
size_t
num
)
{
if
(
num
==
0
)
return
nullptr
;
void
*
res
=
aligned_alloc
(
64
,
num
*
sizeof
(
T
));
if
(
!
res
)
throw
bad_alloc
();
return
reinterpret_cast
<
T
*>
(
res
);
}
static
void
dealloc
(
T
*
ptr
)
{
free
(
ptr
);
}
#else // portable emulation
static
T
*
ralloc
(
size_t
num
)
{
if
(
num
==
0
)
return
nullptr
;
void
*
ptr
=
malloc
(
num
*
sizeof
(
T
)
+
64
);
if
(
!
ptr
)
throw
bad_alloc
();
T
*
res
=
reinterpret_cast
<
T
*>
((
reinterpret_cast
<
size_t
>
(
ptr
)
&
~
(
size_t
(
63
)))
+
64
);
(
reinterpret_cast
<
void
**>
(
res
))[
-
1
]
=
ptr
;
return
res
;
}
static
void
dealloc
(
T
*
ptr
)
{
if
(
ptr
)
free
((
reinterpret_cast
<
void
**>
(
ptr
))[
-
1
]);
}
#endif
public:
aligned_array
()
:
p
(
0
),
sz
(
0
)
{}
aligned_array
(
size_t
n
)
:
p
(
ralloc
(
n
)),
sz
(
n
)
{}
aligned_array
(
aligned_array
&&
other
)
:
p
(
other
.
p
),
sz
(
other
.
sz
)
{
other
.
p
=
nullptr
;
other
.
sz
=
0
;
}
~
aligned_array
()
{
dealloc
(
p
);
}
void
resize
(
size_t
n
)
{
if
(
n
==
sz
)
return
;
dealloc
(
p
);
p
=
ralloc
(
n
);
sz
=
n
;
}
T
&
operator
[](
size_t
idx
)
{
return
p
[
idx
];
}
const
T
&
operator
[](
size_t
idx
)
const
{
return
p
[
idx
];
}
T
*
data
()
{
return
p
;
}
const
T
*
data
()
const
{
return
p
;
}
size_t
size
()
const
{
return
sz
;
}
};
}
using
detail
::
vtp
;
using
detail
::
aligned_array
;
}}
...
...
src/string_utils.cc
View file @
c37e04f1
...
...
@@ -39,7 +39,6 @@
#include
<cctype>
#include
"mr_util/string_utils.h"
#include
"mr_util/error_handling.h"
#include
"mr_util/datatypes.h"
using
namespace
std
;
...
...
@@ -47,8 +46,6 @@ namespace mr {
namespace
string_utils
{
using
namespace
mr
::
datatypes
;
string
trim
(
const
string
&
orig
)
{
string
::
size_type
p1
=
orig
.
find_first_not_of
(
"
\t
"
);
...
...
@@ -108,26 +105,18 @@ string intToString(int64_t x, size_t width)
return
trim
(
res
);
}
namespace
{
void
end_stringToData
(
const
string
&
x
,
const
char
*
tn
,
istringstream
&
strstrm
)
{
MR_assert
(
strstrm
,
"conversion error in stringToData<"
,
tn
,
">('"
,
x
,
"')"
);
string
rest
;
strstrm
>>
rest
;
// rest=trim(rest);
MR_assert
(
rest
.
length
()
==
0
,
"conversion error in stringToData<"
,
tn
,
">('"
,
x
,
"')"
);
}
}
// unnamed namespace
template
<
typename
T
>
void
stringToData
(
const
string
&
x
,
T
&
value
)
{
istringstream
strstrm
(
x
);
strstrm
>>
value
;
end_stringToData
(
x
,
type2typename
<
T
>
(),
strstrm
);
bool
ok
=
bool
(
strstrm
);
if
(
ok
)
{
string
rest
;
strstrm
>>
rest
;
ok
=
rest
.
length
()
==
0
;
}
MR_assert
(
ok
,
"could not convert '"
,
x
,
"' to desired data type."
);
}
template
<
>
void
stringToData
(
const
string
&
x
,
string
&
value
)
...
...
@@ -301,7 +290,7 @@ template<typename T> void split (istream &stream, vector<T> &list)
string
word
;
stream
>>
word
;
MR_assert
(
stream
||
stream
.
eof
(),
"error while splitting stream into
"
,
type2typename
<
T
>
(),
"
components"
);
"error while splitting stream into components"
);
if
(
stream
)
list
.
push_back
(
stringToData
<
T
>
(
word
));
}
}
...
...
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