Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ag-ohlberger
dune-community
dune-xt
Commits
69c28425
Commit
69c28425
authored
12 years ago
by
René Fritze
Browse files
Options
Downloads
Patches
Plain Diff
move type stuff from color, add test
parent
6f603bd5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dune/stuff/common/color.hh
+0
-23
0 additions, 23 deletions
dune/stuff/common/color.hh
dune/stuff/common/type_utils.hh
+77
-0
77 additions, 0 deletions
dune/stuff/common/type_utils.hh
dune/stuff/test/common_typenames.cc
+9
-0
9 additions, 0 deletions
dune/stuff/test/common_typenames.cc
with
86 additions
and
23 deletions
dune/stuff/common/color.hh
+
0
−
23
View file @
69c28425
...
...
@@ -78,29 +78,6 @@ std::string backcolor(int i)
return
"
\033
[38;5;"
+
Dune
::
Stuff
::
Common
::
String
::
convertTo
(
i
)
+
"m"
;
}
// demangles typeid
template
<
class
T
>
std
::
string
demangledTypeId
(
T
&
obj
)
{
int
status
;
#ifdef __GNUC__
return
abi
::
__cxa_demangle
(
typeid
(
obj
).
name
(),
0
,
0
,
&
status
);
#else // ifdef __GNUC__
return
typeid
(
obj
).
name
();
#endif // ifdef __GNUC__
}
// demangledTypeId
// create output for demangled typeid
template
<
class
T
>
void
realTypeId
(
T
&
obj
,
std
::
string
name
=
""
,
int
maxlevel
=
10000
)
{
std
::
cout
<<
name
<<
(
name
==
""
?
""
:
"'s type is "
)
<<
highlightTemplate
(
demangledTypeId
(
obj
),
maxlevel
)
<<
std
::
endl
;
}
// maybe you want to choose your own color
int
templateColorChooser
(
int
i
)
{
...
...
This diff is collapsed.
Click to expand it.
dune/stuff/common/type_utils.hh
0 → 100644
+
77
−
0
View file @
69c28425
#ifndef DUNE_STUFF_TYPENAMES_HH
#define DUNE_STUFF_TYPENAMES_HH
#include
"color.hh"
/** use this to define Typename specializations in the GLOBAL namespace ONLY **/
#define STUFF_TYPENAME(NAME) \
namespace Dune { \
namespace Stuff { \
namespace Common { \
template <> \
struct Typename<NAME> \
{ \
static const char* value() \
{ \
return #NAME; \
} \
}; \
} \
} \
}
namespace
Dune
{
namespace
Stuff
{
namespace
Common
{
std
::
string
demangleTypename
(
const
std
::
string
&
mangled_name
)
{
#ifdef __GNUC__
return
abi
::
__cxa_demangle
(
mangled_name
.
c_str
(),
0
,
0
,
int
());
#else // ifdef __GNUC__
return
mangled_name
;
#endif // ifdef __GNUC__
}
//! demangles typeid
template
<
class
T
>
std
::
string
demangledTypeId
(
T
&
obj
)
{
return
demangleTypename
(
typeid
(
obj
).
name
());
}
// demangledTypeId
//! create output for demangled typeid
template
<
class
T
>
void
realTypeId
(
T
&
obj
,
std
::
string
name
=
""
,
int
maxlevel
=
10000
)
{
std
::
cout
<<
name
<<
(
name
==
""
?
""
:
"'s type is "
)
<<
highlightTemplate
(
demangledTypeId
(
obj
),
maxlevel
)
<<
std
::
endl
;
}
//! an extensible mechanism to assign "cleartext" names to types
template
<
typename
T
>
struct
Typename
{
static
std
::
string
value
()
{
#if defined(__GNUC__) && defined(__GXX_RTTI)
return
demangleTypename
(
typeid
(
T
).
name
());
#else
return
"unknown"
;
#endif
}
};
}
// namespace Common
}
// namespace Stuff
}
// namespace Dune
STUFF_TYPENAME
(
int
)
STUFF_TYPENAME
(
double
)
STUFF_TYPENAME
(
float
)
STUFF_TYPENAME
(
long
)
STUFF_TYPENAME
(
unsigned
int
)
STUFF_TYPENAME
(
unsigned
long
)
STUFF_TYPENAME
(
char
)
#endif // DUNE_STUFF_TYPENAMES_HH
This diff is collapsed.
Click to expand it.
dune/stuff/test/common_typenames.cc
+
9
−
0
View file @
69c28425
...
...
@@ -4,13 +4,22 @@
#include
<config.h>
#endif // ifdef HAVE_CMAKE_CONFIG
#include
<iostream>
#include
<dune/common/mpihelper.hh>
#include
<dune/stuff/common/type_utils.hh>
STUFF_TYPENAME
(
Dune
::
MPIHelper
)
int
main
(
int
argc
,
char
**
argv
)
{
using
namespace
Dune
::
Stuff
::
Common
;
try
{
// mpi
Dune
::
MPIHelper
::
instance
(
argc
,
argv
);
std
::
cout
<<
"builtin typename:
\n
unsigned long -> "
<<
Typename
<
unsigned
long
>::
value
()
<<
"
\n
unknown: Dune::Exception -> "
<<
Typename
<
Dune
::
Exception
>::
value
()
<<
"
\n
extended: Dune::MPIHelper -> "
<<
Typename
<
Dune
::
MPIHelper
>::
value
()
<<
std
::
endl
;
}
catch
(
Dune
::
Exception
&
e
)
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment